zoukankan      html  css  js  c++  java
  • 获取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是空的包,安装后很多目录都没有,不能用,

    所以采用了上面的方法,配置一个crontab * * * * * /xxx.sh 一分钟检查一次,如果active nn和配置文件中的active nn不一致,则就更新配置,

    然后重启hue.

    遇到的一个问题是配置在crontab 中不会把hue拉起来,测了很久发现`` $()有问题,改成``的方式是可以的。

    上网查找相关的内容,也没有得到很好的解析,有一种说法是``中的内容本身就是经过转义的(和此也 无关的)

  • 相关阅读:
    基于Enterprise Library 6 的AOP实现
    命行下的查询与替换字符串
    软件架构中质量特性
    【redis】突然流量增大,不定时挂死排障记录
    Heritrix 3.1.0 源码解析(二)
    Apache Jackrabbit源码研究(四)
    Heritrix 3.1.0 源码解析(三)
    Apache Jackrabbit源码研究(五)
    Heritrix 3.1.0 源码解析(一)
    JVM 自定义的类加载器的实现和使用
  • 原文地址:https://www.cnblogs.com/huaxiaoyao/p/11220667.html
Copyright © 2011-2022 走看看