hadoop修改hadoop.tmp.dir

来源:互联网 发布:网络信息安全资质 编辑:程序博客网 时间:2024/05/16 14:08

hadoop.tmp.dir的目录默认指向的是:/tmp/hadoop-${USERNAME}

这样会有个问题,系统重启时会自动删除/tmp目录下的文件,导致你之前对hadoop做的很多

操作都被删除了,需要重新再来,比如你想hdfs导入的文件会都被删除。

这是你需要修改 ${hadoop_home}/etc/hadoop/core-site.xml文件,添加一个名字为"hadoop.tmp.dir"

的property,内容如下:


<property>
        <name>hadoop.tmp.dir</name>
        <value>/opt/hadoopDir/tmp/data</value>
</property>


添加完hadoop.tmp.dir后的core-site.xml文件内容大致如下:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>

<property>
        <name>fs.defaultFS</name>
        <value>hdfs://localhost:9000</value>
</property>

<property>
        <name>hadoop.tmp.dir</name>
        <value>/opt/hadoopDir/tmp/data</value>
</property>

<property>
        <name>io.native.lib.available</name>
        <value>false</value>
        <description>Controls whether to use native libraries for bz2 and zlib
                compression codecs or not. The property does not control any other native
                libraries.
        </description>
</property>

</configuration>

之后就是关闭hadoop,执行hdfs namenode -format,然后重新启动的过程了,不过这时有个

问题,就是你的hadoop可能运行了很久,执行stop-dfs.sh的时候提示不能关闭namenode、

datanode等,这时可能是你的java进程的状态文件被删除了。这时们就只能使用ps fax命令查

看hadoop进程,然后手动kill掉未被关闭的进程。


这个问题主要是因为java的进程状态文件是保存在“/tmp/hsperfdata_$USER”下的,而Linux的

/tmp目录可能会被某些流失文件夹工具删除,比如:

1、tmpwatch

2、tmpreaper

我查看了自己的机器是有一个tmpwatch的工具,这时我们需要执行该工具在清除/tmp目录时不

要清除我们的/tmp/hsperfdata_$USER目录,进入root权限,然后vi /etc/cron.daily/tmpwatch:

[root@localhost tmp]# vi /etc/cron.daily/tmpwatch

#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
        -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
        -X '/tmp/hsperfdata_*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
    if [ -d "$d" ]; then
        /usr/sbin/tmpwatch "$flags" -X '/tmp/hsperfdata_*' -f 30d "$d"
    fi
done

增加上面的红色部分代码,然后保存退出,这以后tmpwatch就不会删除java的临时目录了。

0 0