Get active nn and replace 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

Currently used hdp3.1, installation namenode ha, configuration hue used when you need to install httpfs, but this version of httpfs empty package, after installing many directories are not, can not,

Therefore, using the above method, a configuration crontab * * * * * /xxx.sh checks for one minute, and if active nn active nn inconsistent configuration file, the configuration is updated,

Then restart hue.

One problem encountered is configured in the crontab will not pull up the hue, measured for a long time it found that `` $ () there is a problem, to `` the way is possible.

Internet to find relevant content, and not well resolved, there is a saying that `` the content in itself is escaped (and this is also irrelevant)

 

Guess you like

Origin www.cnblogs.com/huaxiaoyao/p/11220667.html