獲取active nn並替換hue.ini

namenodelists="nnip1,nnip2"
nn1=$(echo $namenodelists | cut -d "," -f 1)
nn2=$(echo $namenodelists | cut -d "," -f 2)
nn1state=$(curl "http://$nn1:50070/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"|grep -c active)
nn2state=$(curl "http://$nn2:50070/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"|grep -c active)

source /etc/profile
source /root/.profile
curr_nn=$(grep -Po -m1 "http://(.*):50070" /usr/share/hue/desktop/conf/hue.ini |cut -d ':' -f 2|cut -d "/" -f 3)
echo $curr_nn
if [ $nn1state -eq 1 ]; then
activenn=$nn1
   if [ "X$curr_nn" != "X$activenn" ]; then 
       echo "nn change, now active is $activenn"
       sed -i "s|fs_defaultfs=.*|webhdfs_url=http://$activenn:50070/webhdfs/v1|" /usr/share/hue/desktop/conf/hue.ini 
       sed -i "s|webhdfs_url=.*|webhdfs_url=http://$activenn:50070/webhdfs/v1|" /usr/share/hue/desktop/conf/hue.ini
       ps -ef|grep hue |grep -v grep |awk '{print $2}' |xargs kill -9 2>/dev/null
       /usr/bin/nohup /usr/share/hue/build/env/bin/hue runserver 0.0.0.0:8888 > /usr/share/hue/hue.log 2>&1 &
   fi
fi
if [ $nn2state -eq 1 ]; then
activenn=$nn2
   if [ "X$curr_nn" != "X$activenn" ]; then 
       echo "nn change, now active is $activenn"
       sed -i "s|fs_defaultfs=.*|webhdfs_url=http://$activenn:50070/webhdfs/v1|" /usr/share/hue/desktop/conf/hue.ini 
       sed -i "s|webhdfs_url=.*|webhdfs_url=http://$activenn:50070/webhdfs/v1|" /usr/share/hue/desktop/conf/hue.ini
       ps -ef|grep hue |grep -v grep |awk '{print $2}' |xargs kill -9 2>/dev/null
       /usr/bin/nohup /usr/share/hue/build/env/bin/hue runserver 0.0.0.0:8888 > /usr/share/hue/hue.log 2>&1 &
   fi
fi
#start it if not start 
live=`ps -ef|grep runserver|grep -v -c grep`
if [ $live -eq 0 ];  then
/usr/bin/nohup /usr/share/hue/build/env/bin/python2.7 /usr/share/hue/build/env/bin/hue runserver 0.0.0.0:8888 2>&1 &
fi

當前使用hdp3.1,安裝namenode ha,配置hue使用的時候須要安裝httpfs,但這個版本的httpfs是空的包,安裝後不少目錄都沒有,不能用,node

因此採用了上面的方法,配置一個crontab * * * * * /xxx.sh 一分鐘檢查一次,若是active nn和配置文件中的active nn不一致,則就更新配置,python

而後重啓hue.web

遇到的一個問題是配置在crontab 中不會把hue拉起來,測了好久發現`` $()有問題,改爲``的方式是能夠的。curl

上網查找相關的內容,也沒有獲得很好的解析,有一種說法是``中的內容自己就是通過轉義的(和此也 無關的)oop

相關文章
相關標籤/搜索