爆肝一周后,HUE也可以一键编译安装了?

在大数据开源产品中,HUE是一个非常好用的客户端工具。它可以连接HDFS、Yarn、Hive、HBase、Ooize、Presto等组件,并直接在HUE的WEB界面中,直接对各种组件提交命令。

但HUE的编译过程又比较繁琐,很容易失败。我爆肝了一周,解决了很多编译上的问题。成功编译HUE之后,并把整体流程编写成了脚本,可以一键进行安装和配置。

这里,将介绍一下编译过程中的常见问题,并将脚本分享给大家。

HUE编译问题

首先来看一下HUE编译中的一些问题。

  1. 首先是编译需要的npm、maven环境,因为网速原因,会导致频繁的连接超时。

    这里需要提前将npm、maven的镜像源改为国内。网上配置教程很多,大家自行配置即可。这个也已经完成了脚本的自动安装和配置,之前的大数据环境一键安装脚本有了很多的变动,之后会把整个大数据组件的安装脚本优化后重新开源到github。

  2. 其次在编译过程中,需要很多依赖,以下是官方提供的所有依赖,自行安装即可。如果已经装了Mysql,跳过mysql依赖。

    sudo yum install -y openssl-devel
    # 本地未安装Mysql
    sudo yum install -y ant asciidoc cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-plain gcc gcc-c++ krb5-devel libffi-devel libxml2-devel libxslt-devel make mysql mysql-devel openldap-devel python-devel sqlite-devel gmp-devel
    # 本地已经安装Mysql
    sudo yum install -y ant asciidoc cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-plain gcc gcc-c++ krb5-devel libffi-devel libxml2-devel libxslt-devel make openldap-devel python-devel sqlite-devel gmp-devel
    
  3. 在安装中,可能会提示缺少mysql的各种文件,这个大概率是因为本地使用rpm包等方式,自行安装了Mysql,但并没有安装mysql-devel。而且因为Mysql安装的是本地包,所以yum无法直接安装mysql-devel。这个情况,去搜狐镜像源上,找到对应的Mysql版本,手动下载并安装mysql-devel即可。

    EnvironmentError: mysql_config not found
    make[2]: *** [/opt/app/hue-release-4.7.1/desktop/core/build/MySQL-python-1.2.5/egg.stamp] 错误 1
    make[2]: 离开目录“/opt/app/hue-release-4.7.1/desktop/core”
    make[1]: *** [.recursive-env-install/core] 错误 2
    make[1]: 离开目录“/opt/app/hue-release-4.7.1/desktop”
    make: *** [desktop] 错误 2
    
  4. 最后,是最棘手的一个错误,并非环境的缺失,而是setuptools的原生问题,导致无法通过编译,报错如下。

      File "/opt/app/hue-release-4.7.1/build/env/bin/easy_install", line 11, in <module>
      	sys.exit(main())
      ....
      File "/opt/app/hue-release-4.7.1/build/env/lib/python2.7/site-packages/setuptools/sandbox.py", line 44, in _execfile
        code = compile(script, filename, 'exec')
      File "/tmp/easy_install-qSJ28J/traitlets-5.0.5/setup.py", line 41
        print(error, file=sys.stderr)
                         ^
    

    这种情况,需要手动安装下setuptools,在在hue安装目录下执行以下命令,再次编译即可

    build/env/bin/python -m pip install setuptools==28.6.1 backports.shutil-get-terminal-size pathlib2 decorator pexpect pickleshare prompt-toolkit==1.0.4 traitlets==4.2 simplegeneric==0.8.1
    
  5. 当然,在编译过程中,如果使用虚拟机,则保证内存至少2G,否则babel会抛出异常,内存小于500K,导致编译失败。

HUE一键编译安装

当然,编译中这些问题,与解决方案,最终都编写到脚本中。首先安装全部依赖,并根据报错情况提示Mysql文件缺失的解决方案,报错后并自动检测并解决setuptools问题,再重新编译。

并且根据环境,自动添加hadoop、hive、hbase的配置,在HUE启动后,可以直接进行连接。并且将HUE内置的数据库更换为推荐的Mysql,并自动创建数据库和表文件。

这里依然是将安装包放置到/opt/frames下,并在frames.txt文件中添加hue的安装配置:hue-release-4.7.1.tar.gz true node02,表示将hue安装在node02节点上。

脚本下附:

#! /bin/bash

function configureHue()
{
 hue_home=$1
 hueConf=$2

 mysqlNode=`egrep "^mysql-rpm-pack" /home/hadoop/automaticDeploy/frames.txt | cut -d " " -f3`
 mysqlHivePasswd=`egrep "^mysql-hive-password" /home/hadoop/automaticDeploy/configs.txt | cut -d " " -f2 | sed s/\r//`
 
 # 创建数据库hue,用于存放hue数据
 ssh $mysqlNode "source /etc/profile && export MYSQL_PWD=$mysqlHivePasswd && mysql --connect-expired-password -uroot -e \"drop database if exists hue;\""
 ssh $mysqlNode "source /etc/profile && export MYSQL_PWD=$mysqlHivePasswd && mysql --connect-expired-password -uroot -e \"create database if not exists hue;\""

 # 配置秘钥 
 sed -i "s/secret_key=/secret_key=ad1FA1ka09/g" $hueConf
 # 配置mysql
 num=`sed -n -e "/\[\[database\]\]/=" $hueConf`
 sed -i "${num}a host=${mysqlNode}" $hueConf
 sed -i "`expr $num + 1`a port=3306" $hueConf
 sed -i "`expr $num + 2`a engine=mysql" $hueConf
 sed -i "`expr $num + 3`a user=root" $hueConf
 sed -i "`expr $num + 4`a password=${mysqlHivePasswd}" $hueConf
 sed -i "`expr $num + 5`a name=hue" $hueConf
 
 # 初始化hue数据库数据
 $hue_home/build/env/bin/hue syncdb 
 $hue_home/build/env/bin/hue migrate
}

function addHive()
{
 hueConf=$1

 hiveInfo=`egrep "hive" /home/hadoop/automaticDeploy/frames.txt`
 hive=`echo $hiveInfo | cut -d " " -f1`
 hiveNode=`echo $hiveInfo | cut -d " " -f3`

 # 配置Hive
 num=`sed -n -e "/\[beeswax\]/=" $hueConf`
 sed -i "${num}a hive_server_host=${hiveNode}" $hueConf
 sed -i "`expr $num + 1`a hive_server_port=10000" $hueConf
 sed -i "`expr $num + 2`a thrift_version=7" $hueConf
 
 num2=`sed -n -e "/\[\[interpreters\]\]/=" $hueConf`
 sed -i "${num2}a [[[hive]]]" $hueConf
 sed -i "`expr $num2 + 1`a name=Hive" $hueConf
 sed -i "`expr $num2 + 2`a interface=hiveserver2" $hueConf

}

function addHDFS()
{
hadoopInfo=`egrep "^hadoop" /home/hadoop/automaticDeploy/frames.txt`
masterNode=`echo $hadoopInfo | cut -d " " -f3` 

hueConf=$1

sed -i "s/fs_defaultfs=hdfs:\/\/localhost:8020/fs_defaultfs=hdfs:\/\/$masterNode:9000/g" $hueConf
sed -i "s/webhdfs_url=http:\/\/localhost:50070\/webhdfs\/v1/webhdfs_url=hdfs:\/\/http:\/\/$masterNode:50070\/webhdfs\/v1/g" $hueConf
}

function addYarn()
{
hadoopInfo=`egrep "^hadoop" /home/hadoop/automaticDeploy/frames.txt`
masterNode=`echo $hadoopInfo | cut -d " " -f3` 

hueConf=$1

sed -i "s/## resourcemanager_host=localhost/resourcemanager_host=$masterNode/g" $hueConf
sed -i "s/## resourcemanager_api_url=http:\/\/localhost:8088/resourcemanager_api_url=http:\/\/$masterNode:8088/1" $hueConf
sed -i "s/## proxy_api_url=http:\/\/localhost:8088/proxy_api_url=http:\/\/$masterNode:8088/g" $hueConf
sed -i "s/## resourcemanager_port=8032/resourcemanager_port=8032/g" $hueConf
sed -i "s/## history_server_api_url=http:\/\/localhost:19888/history_server_api_url=http:\/\/$masterNode:19888/g" $hueConf
}

function addHBase()
{
hueConf=$1

hbaseInfo=`egrep "^hbase" /home/hadoop/automaticDeploy/frames.txt`
isInstall=`echo $hbaseInfo | cut -d " " -f2`
hbaseNodes=`echo $hbaseInfo | cut -d " " -f3` 

if [[ $isInstall = "true" ]];then
  sed -i "s/## hbase_clusters=(Cluster|localhost:9090)/hbase_clusters=(Cluster|$hbaseNodes:9090)/g" $hueConf
else
  echo "HBase未安装,未配置与HBase的连接"
fi
}

function installHue()
{
 #在frames.txt中查看是否需要安装hue
 hueInfo=`egrep "hue" /home/hadoop/automaticDeploy/frames.txt`
 
 hue=`echo $hueInfo | cut -d " " -f1`
 isInstall=`echo $hueInfo | cut -d " " -f2`
 hueNode=`echo $hueInfo | cut -d " " -f3`
 node=`hostname`

 # 查看Mysql安装信息  
 mysqlInfo=`egrep "^mysql-rpm-pack" /home/hadoop/automaticDeploy/frames.txt`
 mysqlNode=`echo $mysqlInfo | cut -d " " -f3` 
 
 #是否在当前节点进行安装
 if [[ $isInstall = "true" && $hueNode = $node ]];then
     
     #查看/opt/frames目录下是否有hue安装包
     hueIsExists=`find /opt/frames -name $hue`
    
     if [[ ${#hueIsExists} -ne 0 ]];then
           
          if [[ ! -d /opt/app ]];then
              mkdir /opt/app && chmod -R 775 /opt/app
          fi
   
          #删除旧的
          hue_home_old=`find /opt/app -maxdepth 1 -name "*hue*"`
          for i in $hue_home_old;do
                rm -rf $i
          done

          #解压到指定文件夹/opt/app中
          echo "开始解压hue安装包"
          tar -zxvf $hueIsExists -C /opt/app >& /dev/null
          echo "hive安装包解压完毕"

          hue_home=`find /opt/app -maxdepth 1 -name "*hue*"`

          # 安装依赖
          yum install -y openssl-devel

          # 安装编译所需依赖,需提前安装maven、npm
          if [[ $mysqlNode = $node ]];then
              sudo yum install -y ant asciidoc cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-plain gcc gcc-c++ krb5-devel libffi-devel libxml2-devel libxslt-devel make openldap-devel python-devel sqlite-devel gmp-devel
          else
              sudo yum install -y ant asciidoc cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-plain gcc gcc-c++ krb5-devel libffi-devel libxml2-devel libxslt-devel make mysql mysql-devel openldap-devel python-devel sqlite-devel gmp-devel
          fi

          cd $hue_home

          # 进行编译
          echo "开始编译,请稍等"
          make apps > /tmp/hue_intall.log 2>&1;

          grep "mysql_config not found" /tmp/hue_intall.log > /dev/null
          if [ $? -eq 0 ]; then
              echo "缺少mysql-devel,请通过yum安装,或rpm方式安装"
              echo "eg: wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-community-devel-5.7.23-1.el7.x86_64.rpm"
              echo "eg: rpm -ivh $mysqlIsExists/mysql-community-*"
              exit 1
          fi

          grep "build/env/bin/easy_install\", line 11, in <module>" /tmp/hue_intall.log > /dev/null
          if [ $? -eq 0 ]; then
              # 解决setuptools的问题
              build/env/bin/python -m pip install setuptools==28.6.1 backports.shutil-get-terminal-size pathlib2 decorator pexpect pickleshare prompt-toolkit==1.0.4 traitlets==4.2 simplegeneric==0.8.1
              echo "开始重新编译,请稍等"
              make apps > /tmp/hue_intall.log 2>&1;
          fi

          # 配置HUE
          configureHue $hue_home $hue_home/desktop/conf/pseudo-distributed.ini
          # 添加Hive
          addHive $hue_home/desktop/conf/pseudo-distributed.ini
          # 添加HDFS
          addHDFS $hue_home/desktop/conf/pseudo-distributed.ini
          # 添加Yarn
          addYarn $hue_home/desktop/conf/pseudo-distributed.ini
          # 添加HBase
          addHBase $hue_home/desktop/conf/pseudo-distributed.ini

          #配置HUE_HOME
          profile=/etc/profile
          sed -i "/^export HUE_HOME/d" $profile
          echo "export HUE_HOME=$hue_home" >> $profile

          #配置PATH
          sed -i "/^export PATH=\$PATH:\$HIVE_HOME\/build\/env\/bin/d" $profile
          echo "export PATH=\$PATH:\$HIVE_HOME/build/env/bin" >> $profile

          #更新/etc/profile文件
          source /etc/profile && source /etc/profile

     else
         echo "/opt/frames目录下没有Hue安装包"
     fi
 else
     echo "Hue不允许被安装在当前节点"
 fi
}

installHue

爆肝一周,两眼一黑,差点奔溃。但最终得此脚本,可安逸矣。大家可以自行改造,之后会将全部脚本开源出来,易用性上会有更大的提升,支持的组件也会更多。

如果有帮助的,记得点赞、关注。在公众号《数舟》中,可以免费获取专栏《数据仓库》配套的视频课程、大数据集群自动安装脚本,并获取进群交流的途径。

我所有的大数据技术内容也会优先发布到公众号中。如果对某些大数据技术有兴趣,但没有充足的时间,在群里提出,我为大家安排分享。

公众号自取:
在这里插入图片描述


版权声明:本文为qq_33876553原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。