以往安装配置使用Apache Hadoop时,完全需要手动在服务器上,通过命令和脚本进行安装配置,比较复杂而繁琐。使用CDH,我们可以通过Cloudera提供的CM(Cloudera Manager)来进行安装,CM是一个面向Hadoop相关软件的强大SCM工具,它提供了通过Web界面向导的方式进行软件的安装配置,此外还提供了比较基础、友好的监控、预警功能,通过Web UI展示各种已安装软件的资源使用情况、系统运行状态等等。
如果使用CM来管理CDH平台,因为CM使用了监控管理、运行状态数据采集、预警等等很多服务,所以在集群服务器资源使用方面也会比通常的Apache Hadoop版本多很多,如果所需要的Hadoop集群规模超大,比如成百上千个节点,使用CM来安装管理CDH集群能够节省大量时间,而且节省了对整个集群基本的监控的配置管理;如果集群规模比较小,如5~10个节点左右,建议对这类集群最好单个节点的资源(内存、CPU、磁盘、网络)比较充足一些为好。
软件准备
我们通过离线的方式,基于Parcels进行CDH的安装配置,所以首先需要找到并下载相应的软件包。下面是我们当前安装配置的系统软件、应用软件的版本情况,如下所示:
- CentOS 7.2
- jdk-7u80-linux-x64.tar.gz
- http://archive.cloudera.com/cdh5/parcels/5.12.2/
环境准备
- CDH集群节点规划集群
CDH集群节点规划,如下表所示:
IP地址 | 主机名 | 节点角色 |
192.168.152.128 | ali-bj01-tst-cluster-001.xiweiai.cn | NameNode、SecondaryNameNode、ResourceMaster、cloudera-scm-server、cloudera-scm-agent、mysql |
192.168.152.129 | ali-bj01-tst-cluster-002.xiweiai.cn | DataNode、NodeManager、cloudera-scm-agent |
- 关闭防火墙
在集群中的所有节点上,关闭防火墙,执行如下命令:
1
2
|
systemctl stop firewalld systemctl disable firewalld |
基础环境配置
- JDK安装配置
下载JDK安装文件jdk-7u80-linux-x64.tar.gz,解压缩到目录/usr/local/java/中,然后在/etc/profile中增加如下配置:
1
2
3
|
export JAVA_HOME= /usr/local/java/jdk1 .7.0_80 export PATH=$PATH:$JAVA_HOME /bin export CLASSPATH=.:$JAVA_HOME /lib/ *.jar:$JAVA_HOME /jre/lib/ *.jar |
然后使配置生效,执行如下命令:
1
|
source /etc/profile |
- ssh免密码配置
为了方便安装软件文件在集群中各个节点中进行拷贝,首先在集群中每个节点上单独创建了一个hadoop账户,如下所示:
1
2
|
useradd hadoop Passwd hadoop |
然后,配置在NameNode上通过ssh免密码登录到集群其它节点,在所有节点上执行如下命令生成秘钥和公钥:
1
|
ssh -keygen -t rsa |
接着在NameNode上,将公钥文件拷贝到集群中所有的DataNode节点上,执行如下命令:
1
2
3
4
|
scp ~/. ssh /id_rsa .pub 172.16.117.63:~/. ssh /id_rsa .pub.master scp ~/. ssh /id_rsa .pub 172.16.117.64:~/. ssh /id_rsa .pub.master scp ~/. ssh /id_rsa .pub 172.16.117.65:~/. ssh /id_rsa .pub.master cp ~/. ssh /id_rsa .pub ~/. ssh /id_rsa .pub.master |
继续在CDH集群中的NameNode及每个DataNode节点上,将公钥添加到authorized_keys文件中,执行如下命令:
1
2
|
cat ~/. ssh /id_rsa .pub.master >> ~/. ssh /authorized_keys chmod g-w ~/. ssh /authorized_keys |
最后,我们验证一下在NameNode本地可以免密码访问自己:
1
|
同时在NameNode上,也可以直接免密码登录到所有其他的DataNode节点上:
1
2
3
|
这样,就可以在配置CDH安装文件过程中,非常方便地拷贝分发安装包和配置文件了。
- 安装MySQL
我们的MySQL数据库服务器,直接安装在NameNode节点,为CDH专用。
下载MySQL软件包,并解压缩,如下所示:
1
2
|
wget http: //dev .mysql.com /get/Downloads/MySQL-5 .7 /mysql-5 .7.16-1.el7.x86_64.rpm-bundle. tar tar xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle. tar |
然后,安装MySQL数据库,执行如下命令:
1
2
3
4
|
rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm |
进行MySQL数据库的初始化,执行如下命令:
1
|
mysqld --initialize --user=mysql |
可以在/var/log/mysqld.log文件中,获取到MySQL的初始临时密码,比如我的临时密码为k6i6u!Kl0)ex。
启动MySQL数据库服务器,执行如下命令:
1
|
systemctl start mysqld.service |
然后登录到MySQL数据库服务器:
1
|
mysql -uroot -p |
输入上述临时密码,便可以成功登录,修改默认root用户的密码,自行如下命令:
1
|
ALTER USER ‘root‘ @ ‘localhost‘ IDENTIFIED BY ‘c9mC%1L5e‘ ; |
该密码会在后面安装CDH的过程中使用到。
安装配置CM、CDH
这里,做为开发环境使用,我们没有安装配置NameNode、ResourceManager的高可用(HA),如果需要可以参考官网文档进行配置。下面,为了更清晰描述,我们划分为多个步骤并按顺序进行描述,如下所示:
- 在NameNode上准备所需软件包
将所有需要的软件包,拷贝到NameNode节点上:
1
2
3
4
|
scp CDH-5.7.0-1.cdh5.7.0.p0.45-el7.parcel* [email protected]:~/ scp mysql-connector-java-5.1.43-bin.jar [email protected]:~/ scp manifest.json [email protected]:~/ |
注意,因为通过CM安装CDH,需要使用到MySQL数据库存储相关数据,所以用到了MySQL的JDBC驱动包。
- 创建安装目录
在集群中所有节点上,准备对应的文件目录,如下所示:
1
2
3
4
|
mkdir -p /mnt/bd/installations/cdh chown -R hadoop:hadoop /mnt/bd/installations/ ln -s /mnt/bd/installations/cdh /opt/cdh chown -R hadoop:hadoop /opt/cdh |
- 准备CM、CDH软件包
在NameNode节点上,将CDH-5.7.0-1.cdh5.7.0.p0.45-el7.parcel.sha1文件重命名:
1
2
|
cd ~/ mv CDH-5.7.0-1.cdh5.7.0.p0.45-el7.parcel.sha1 CDH-5.7.0-1.cdh5.7.0.p0.45-el7.parcel.sha |
解压缩cloudera-manager-centos7-cm5.7.0_x86_64.tar到/opt/cdh/目录下,如下所示:
1
2
3
4
5
|
tar -xvf cloudera-manager-centos7-cm5.7.0_x86_64. tar -C /opt/cdh/ ll /opt/cdh/ total 8 drwxr-xr-x 4 hadoop hadoop 4096 Apr 2 2016 cloudera drwxr-xr-x 9 hadoop hadoop 4096 Apr 2 2016 cm-5.7.0 |
将parcel相关文件,拷贝到/opt/cdh/cloudera/parcel-repo/目录中:
1
2
|
cp CDH-5.7.0-1.cdh5.7.0.p0.45-el7.parcel CDH-5.7.0-1.cdh5.7.0.p0.45-el7.parcel.sha1 manifest.json /opt/cdh/cloudera/parcel-repo/ cp mysql-connector-java-5.1.43-bin.jar /opt/cdh/cm-5 .7.0 /share/cmf/lib/ |
修改/opt/cdh/cm-5.7.0/etc/cloudera-scm-agent/config.ini配置文件,修改后的内容如下所示:
1
2
|
server_host=ali-bj01-tst-cluster-001.xiweiai.cn cloudera_mysql_connector_jar= /opt/cdh/cm-5 .7.0 /share/cmf/lib/mysql-connector-java-5 .1.43-bin.jar |
另外,还需要创建如下目录:
1
|
mkdir /opt/cdh/cm-5 .7.0 /run/cloudera-scm-agent |
否则,在启动SCM agent时会报如下错误:
1
|
CM agent Unable to create the pidfile. |
- 准备MySQL数据库账号
创建scm用户,可以访问cm数据库,如下所示:
1
2
|
GRANT ALL ON cm.* TO ‘scm‘ @ ‘localhost‘ IDENTIFIED BY ‘xw%cDh9by‘ ; FLUSH PRIVILEGES; |
- 安装文件拷贝分发
将在NameNode上准备好的所有软件包,拷贝到集群中所有的DataNode上节点上:
1
2
3
|
|
- 创建cloudera-scm用户
在NameNode、所有DataNode节点上,使用root用户创建cloudera-scm用户,执行如下命令:
1
|
useradd --system --home= /opt/cdh/cm-5 .7.0 /run/cloudera-scm-server --shell= /bin/false --comment "Cloudera SCM User" cloudera-scm |
如果不创建该用户,在启动cloudera-scm-server时会报如下错误:
1
2
|
install: invalid user ‘cloudera-scm’ Starting cloudera-scm-server: [FAILED] |
- 初始化MySQL数据库
在NameNode上,为CM初始化创建MySQL数据库cm中的相关表,使用root用户执行如下命令:
1
|
/opt/cdh/cm-5 .7.0 /share/cmf/schema/scm_prepare_database .sh mysql cm -hlocalhost -P3306 -uroot -pc9mC%1L5e --scm-host localhost scm xw%cDh9by |
可以看到,初始化过程的信息,如下所示:
1
2
3
4
5
6
7
8
|
JAVA_HOME=/usr/local/java/jdk1.7.0_80 Verifying that we can write to /mnt/bd/installations/cdh/cm-5.7.0/etc/cloudera-scm-server Thu Aug 31 10:25:52 CST 2017 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Creating SCM configuration file in /mnt/bd/installations/cdh/cm-5.7.0/etc/cloudera-scm-server Executing: /usr/local/java/jdk1.7.0_80/bin/java -cp /usr/share/java/mysql-connector-java.jar:/usr/share/java/oracle-connector-java.jar:/mnt/bd/installations/cdh/cm-5.7.0/share/cmf/schema/../lib/* com.cloudera.enterprise.dbutil.DbCommandExecutor /mnt/bd/installations/cdh/cm-5.7.0/etc/cloudera-scm-server/db.properties com.cloudera.cmf.db. Thu Aug 31 10:25:53 CST 2017 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. [ main] DbCommandExecutor INFO Successfully connected to database. All done, your SCM database is configured correctly! |
启动验证
在NameNode上启动CM server,在NameNode和DataNode上启动CM agent,都需要使用root用户。
- 启动cloudera-scm-server
启动cloudera-scm-server,在NameNode节点上执行如下命令:
1
|
/opt/cdh/cm-5 .7.0 /etc/init .d /cloudera-scm-server start |
如果启动成功,显示如下信息:
1
|
Starting cloudera-scm-server: [ OK ] |
如果有失败,可以查看日志:
1
|
/opt/cdh/cm-5.7.0/log/cloudera-scm-server/cloudera-scm-server.log |
- 启动cloudera-scm-agent
启动cloudera-scm-agent,在所有节点(NameNode和DataNode)上执行如下命令:
1
|
/opt/cdh/cm-5 .7.0 /etc/init .d /cloudera-scm-agent start |
如果启动成功,显示如下信息:
1
|
Starting cloudera-scm-agent: [ OK ] |
如果有失败,可以查看日志:
1
|
/opt/cdh/cm-5.7.0/log/cloudera-scm-agent/cloudera-scm-agent.log |
- 查看CM Web管理控制台
通过浏览器,打开链接http://172.16.117.62:7180/,就可以看到Web界面,根据配置向导进行配置即可。下图是我配置好的CM管理界面,如下图所示:
配置好Hadoop相关软件后,就可以使用相关的服务了,例如下面是我们测试用的Spark Application程序的提交脚本,如下所示:
1
2
|
export SPARK_DIST_CLASSPATH=$(hadoop classpath) spark-submit --class org.shirdrn.robot.advisor.etl.InitialBatchDataSplittingByDate --master yarn --deploy-mode cluster --executor-memory 2g --num-executors 12 /var/lib/hadoop-hdfs/robot-advisor-etl_2 .10-0.0.1-SNAPSHOT.jar 2 /tmp/fund_batch_price_file /tmp/output |
提交成功后,可以通过CM Web控制台上的YARN中对应的Web UI(ResourceManager Web UI)来查看上述提交的Spark Application的运行状态,链接示例:http://ali-bj01-tst-cluster-001.xiweiai.cn:8088/cluster/app/application_1505441596298_0360。
参考链接
- http://archive.cloudera.com/cm5/cm/5/
- http://archive.cloudera.com/cdh5/parcels/5.7.0/
- https://www.cloudera.com/documentation/enterprise/5-5-x/topics/installation_installation.html
- https://www.cloudera.com/documentation/enterprise/5-5-x/topics/cm_ig_parcels.html
- https://www.cloudera.com/documentation/enterprise/5-5-x/topics/cm_ig_managing_software.html