Get active nn and replace hue.ini

Keywords: PHP curl Hadoop crontab

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, hdp3.1 is used to install namenode ha. Httpfs needs to be installed when hue is configured. However, this version of httpfs is an empty package, and many directories are unavailable after installation.

Therefore, the above method is used to configure a crontab * * * * / xxx.sh to check once a minute. If the active nn is inconsistent with the active nn in the configuration file, the configuration will be updated.

Then restart hue.

One of the problems encountered is that the configuration will not pull up the hue in crontab. After a long time of testing, we found that there is a problem with '$() and it is OK to change it to' '.

Online search for relevant content has not been well parsed. There is a saying that the content in 'is itself escaped (irrelevant).

Posted by Padgoi on Sat, 19 Oct 2019 11:11:32 -0700