hadoop修改hadoop.tmp.dir

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的臨時目錄了。

發佈了43 篇原創文章 · 獲贊 22 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章