化繁为简,快速完成 Spark 大数据平台机群配置

Ambari 是 Apache Software Foundation 中的一个基于 web 的顶级开源项目,其自身也是一个分布式架构的软件,主要由两部分组成: Ambari Server 和 Ambari Agent 。 它是集创建、管理、监视 Hadoop 生态圈中众多软件为一体的一个工具。 它为大数据平台的搭建 ,可视化分析及运维提供了巨大的便利。 目前, Ambari 的最新发布版本为 2.4.2。

IBM 的杰作之 IOP

IOP 是指 IBM Open Platform for Apache Hadoop,IOP 中集成并优化了大量的 Apache Hadoop 项目,包括 HDFS, YARN, MapReduce, Ambari, Hbase, Hive, Oozie, Parquet, Parquet Format, Pig, Snappy, Solr, Spark, Sqoop, Zookeeper, Open JDK, Knox, Slider 等,目前 IOP 已经发布了最新的 4.2 版本,相比之前的 4.1 版本增加了更多的项目。表 1 为 IOP4.2 与 IOP4.1 的比对 。

表 1 IOP 4.2 Version VS IOP 4.1 Version

困惑,安装前数据平台繁杂的配置准备

相信很多同仁都有过搭建大数据平台时由于机群机器之间的设置或配置不一致等诸多问题最后造成安装过程中出错,不得不排错后回滚到前几步重新开始,而且出现的错误还不容易排除,造成大量的时间都浪费在排错上。特别是机群有几十个甚至上百台机器时更不容易。比如要在所有机器上同步时钟,要给机群所有机器配置 SSH 无密码登录,关闭防火墙等等。

化繁为简,利用脚本快速完成安装前配置

文中结合作者工作中的实际,给出了一个简单的脚本,方便用户来统一进行安装过程前的配置工作,有兴趣的伙伴们也可以修改并完善这个脚本。同时也期望这个脚本能给大家的工作带来实实在在的便利。当然实际生产中更多为离线安装部署,但道理是一样的。

文中假设用户已经安装并配置了 yum 源并选择在线安装,操作系统为 Centos6.5。具体安装本地 yum 源的方法请参考 IBM developerWorks 技术文章 "利用安装光盘创建本地 yum 源补装 RPM 软件包"

准备机器

文中假设我们要部署一个含 3 台机器的机群,这三台机器的 FQDN 名分别为 c6501.ambari.apache.org,c6502.ambari.apache.org 和 c6503.ambari.apache.org,需要特别强调的是主机名要符合完全限定域名。

同步时钟

假设我们以 c6501 这台机器作为 Ambari server 机器,安装部署前首先要同步时钟设置,文中假设机群机器均安装了 ntp 软件包。 如果没有安装可通过运行: yum -y install ntp ntpdate 来安装 ntp 服务。

一切准备就绪,在终端执行命令:

# vi /etc/ntp.conf

在 ntp.conf 文件中加入:

1
2
3
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0 #local clock
fudge 127.127.1.0 stratum 10

注释掉下图区域后保存退出。

1
2
3
4
5
6
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

编辑脚本

由于客户机群内机器的 IP 地址、机器名等存在不同,为了简单起见,文中给出的脚本在开头预先定义了机群内所有机器的相关信息,这些内容会被写入到机群内所有机器中。当然,读者也可以把机群的相关信息定义到一个单独的配置文件中,通过读取配置文件来获取机群的配置信息。

脚本的预定义内容说明:

prefix:是指机群里所有机器名的前缀,比如本文中所有机器都是以"c650"开头的

master:是指 Ambari server 所在机器,文中安装在 c6501 这台机器上

machineName: 是指机群所有机器的名称、地址等信息,文中三台机器的信息如下,这些信息将会被加入到机群所有机器的 hosts 文件中。

1
2
3
4
5
machineName="
192.168.65.101 c6501.ambari.apache.org c6501
192.168.65.102 c6502.ambari.apache.org c6502
192.168.65.103 c6503.ambari.apache.org c6503
"

以下为脚本的具体内容,为便于用户理解,对脚本做了部分注释,读者可以先将其拷贝下来,新建一个 shell 脚本文件,比如 installsetup.sh(vi installsetup.sh),将拷贝下来的内容粘贴到 shell 文件中保存退出,执行 chmod 775 installsetup.sh 赋予文件可执行权限。用户也可以根据自己的喜好及方便来改写脚本中的内容。

在脚本中,为了保持机群所有机器配置的一致性,用了 scp 拷贝命令覆盖机群所有机器原来的配置并把原配置做了备份,如脚本中的 scp /etc/hosts root@c6501:/etc/hosts。当然,为了安全起见,请用户自行备份原来机器的配置文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
# The Shell script for setup environment before install spark cluster
#
# The install steps as below
#
# 1. vi /etc/sysconfig/network, add the below info into all cluster machines
#           NETWORKING=yes
#           HOSTNAME=< machineName >
#
# 2. vi /etc/ntp.conf, manual setup the information for ntpd
#
# 3. modify the machineName, master and prefix, we suppose that all the machines with the same prefix
#
# 4. run the script in master with command  ./installsetup.sh
#
 
# 预定义说明部分,包含前缀,主机名以及机群机器列表
prefix="c650"
master="c6501"
machineName="
192.168.65.101 c6501.ambari.apache.org c6501
192.168.65.102 c6502.ambari.apache.org c6502
192.168.65.103 c6503.ambari.apache.org c6503
"
 
# 文件的限制数量,将被添加到 limits.conf 文件中
numfiles="
root hard nofile 65536
root soft nofile 65536
root hard nproc 65536
root soft nproc 65536
"
echo "Begin setup environment"
 
# 添加机器 IP,名称等到 hosts 文件
cat >> /etc/hosts << EOF
     ${machineName}
EOF
 
# add the file limits
cat >> /etc/security/limits.conf << EOF
     ${numfiles}
EOF
 
# 添加时间同步信息
cat > /tmp/sync.conf << EOF
     # Add time sync:
     */20 * * * * ( /usr/sbin/ntpdate -u $master ) && ( hwclock --systohc )
EOF
 
# 在主机和节点之间配置 SSH 无密码登录
mkdir -p /root/.ssh; chmod 700 /root/.ssh
ssh-keygen -t dsa -N '' -f /root/.ssh/id_dsa
cp /root/.ssh/id_dsa.pub /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
nodes = " ` cat /etc/hosts | grep $prefix | awk ' { print $3 } ' ` "
echo $nodes
for target in $nodes ; do
     echo "Begin setup machine: " $target "= = = = = = = = = = = = >"
     ssh -o StrictHostKeyChecking=no $target " setenforce 0 "
     ssh -o StrictHostKeyChecking=no $target " mkdir -p /root/.ssh ; chmod 700 /root/.ssh "
     scp /root/.ssh/* $target:/root/.ssh/
 
     # 备份原始的 hosts 信息,最好提前手动备份,以防丢失
     echo "Backup original hosts = = = = = = = = = = = = >"
     scp $target:/etc/hosts $target:/etc/hosts_bak_auto
 
     # 拷贝 hosts 文件到机群内所有机器
     echo "Copy master hosts to cluster = = = = = = = = = = = = >"
     scp /etc/hosts $target:/etc/hosts
 
     # 禁用 SELINUX
     echo "Disable SELINUX = = = = = = = = = = = = >"
     ssh $target "sed s/=enforcing/=disabled/g /etc/selinux/config -i ; grep \"SELINUX=disabled\" /etc/selinux/config"
     ssh $target " setenforce 0 "
     echo "SELINUX=disabled"
 
     # 关闭 IPv6
     echo "Close IPv6 = = = = = = = = = = = = >"
     ssh $target " echo \" install ipv6 /bin/true \" > /etc/modprobe.d/ipv6off.conf ; cat /etc/modprobe.d/ipv6off.conf "
     lsmod | grep -i ipv6
     ifconfig | grep -i inet6
     echo $mod  "Above should be empty for IPv6 = = = = = = = = = = = = >"
     echo $config "Above should be empty for IPv6 = = = = = = = = = = = = >"
 
     # 关闭防火墙 firewall
     echo "Close firewall = = = = = = = = = = = = >"
     ssh $target "service iptables save"
     ssh $target "service iptables stop"
     ssh $target "chkconfig iptables off"
     ssh $target "sed -i \" /service iptables stop/d \" /etc/rc.local ; echo \ " service iptables stop\ ">> /etc/rc.local "
 
     # 关闭 hugepage
     ssh $target "transparent_hugepage=never"
     ssh $target "echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled"
     ssh $target "echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag"
     
     # 调整并备份 limits.conf,并将修改信息应用到机群内所有机器
     echo "Modify the limits to 65536 = = = = = = = = = = = = >"
     sed -i " /pam_limits/d " /etc/pam.d/login; echo " session required pam_limits.so " >> /etc/pam.d/login
     echo "Backup original limits.conf = = = = = = = = = = = = >"
     scp $target:/etc/security/limits.conf $target:/etc/security/limits.conf_bak_auto
     echo "Copy master limits.conf to cluster = = = = = = = = = = = = >"
     scp /etc/security/limits.conf $target:/etc/security/limits.conf
     ssh $target " sed -i \" /pam_limits/d \" /etc/pam.d/login "
     ssh $target " echo \" session required pam_limits.so\" >> /etc/pam.d/login "
 
     #如果存在 dnsmasq,则关闭
     echo "Close dnsmasq = = = = = = = = = = = = >"
     ssh $target " service dnsmasq stop "
     ssh $target " chkconfig dnsmasq off "
 
     # 检查端口是否被占用,此处只列举了部分端口,用户可以自行修改
     echo "Check port = = = = = = = = = = = = >"
     ssh $target " lsof -i:53,1528,2181,2182,7052,7869,7870,7871,7872,7873,7874,7875,7876,7877,7878,7879,7880,7881,7882,7883,8004,8006,8007,8080,8200,8280,8888,9000,9001,9093,9099,9999,10000,10101,10102,14000,18080,50010,50020,50030,50070,50075,50090,60000,60010,60020,60030 "
     echo "The above port need to be closed if existed"
 
     # 同步 ntpd
     scp /tmp/sync.conf $target:/tmp/sync.conf
     ssh $target " crontab /tmp/sync.conf ; service crond reload;"
     ssh $target " /usr/sbin/ntpdate -u " $master
     ssh $target " crontab -l "
     ssh $target " service ntpd restart"
done
 
# 拷贝 known_hosts 文件到机群所有机器
for target in $nodes ; do
     scp $target:/root/.ssh/known_hosts $target:/root/.ssh/known_hosts_bak
     scp /root/.ssh/known_hosts $target:/root/.ssh/
     ssh $target " hostname $target "
done

完成配置

用户完成脚本的编辑后,在 Ambari Server 机器上执行./installsetup.sh 运行脚本,过程中按照要求输入机群内机器的密码(第一次执行会要求输入密码,再次执行会提示是否覆盖/root/.ssh/id_dsa),等脚本执行完成,那么所有机器的前期配置也就完成了。

按部就班,完成大数据平台安装

离线安装

离线安装需要用户提前下载所需的安装包,配置本地 yum 源,开启 http 服务(或者直接用本地 file 模式)并修改相关的配置源指向本地解压后的路径。甚至用户也可以编写自己的 IOP.repo 文件等。其余的安装过程同在线安装大同小异,请参考文中在线安装完成部署。

IOP.repo 内容如下:

1
2
3
4
5
6
[BIGINSIGHTS-4.2.0.0-20160616_1657]
name=BIGINSIGHTS-4.2.0.0-20160616_1657
baseurl=http://ibm-open-platform.ibm.com/daily/IOP/RHEL6/x86_64/4.2.0.0/20160616_1657
enabled=1
gpgcheck=1
gpgkey=http://ibm-open-platform.ibm.com/daily/IOP/RHEL6/x86_64/4.2.0.0/20160616_1657/BI-GPG-KEY.public

以下为 IBM IOP 提供的下载路径,用户可以根据需要下载相对应的版本, 图 1 所示为已经发布的 IOP 版本,目前最新版为 4.2。

Ambari:https://ibm-open-platform.ibm.com/repos/Ambari/rhel/6/x86_64/

IOP:https://ibm-open-platform.ibm.com/repos/IOP/rhel/6/x86_64/4.2.x/GA/

IOP_UTILS: https://ibm-open-platform.ibm.com/repos/IOP-UTILS/rhel/6/x86_64/

图 1 IBM IOP 版本

在线安装

在线安装需要机群内机器能够访问安装源所在的网站,由于网速,网络的稳定性等外在因素的影响,相比离线安装可能耗时会多一些。安装过程中如果出现由于网络等原因造成的相关服务安装失败,用户只需重试安装即可。

不管是离线安装还是在线安装,首先都需要安装 Ambari,其安装配置可以通过以下几步来完成:

第一步 安装 Ambari server

从 IBM 网站下载或者自己编辑 ambari.repo 文件到/etc/yum.repos.d 目录下,ambari.repo 文件内容如下:

1
2
3
4
5
6
[BI_AMBARI-2.2.0-20160616_1657]
name=ambari-2.2.0-20160616_1657
baseurl=http://ibm-open-platform.ibm.com/daily/Ambari/RHEL6/x86_64/2.2.0/20160616_1657
enabled=1
gpgcheck=1
gpgkey=http://ibm-open-platform.ibm.com/daily/Ambari/RHEL6/x86_64/2.2.0/20160616_1657/BI-GPG-KEY.public

安装 Ambari server 只需执行如下命令,安装过程中首先会从 IBM 网站下载 Ambari 的相关安装包。

[root@c6501 yum.repos.d]# yum clean all
[root@c6501 yum.repos.d]# yum install ambari-server

第二步 完成 Ambari server 安装配置,如果用户不想分离数据库可采用缺省值安装。

[root@c6501 yum.repos.d]# ambari-server setup

第三步 启动 Ambari server 服务。

[root@c6501 yum.repos.d]# ambari-server start

开始部署

启动 Ambari server 后,通过 web 页面登录安装部署界面,用户名和密码分别为 admin 和 admin,如图 2 所示。

图 2 Ambari 登录界面

创建机群如图 3 所示

图 3 Ambari 创建机群界面

如果是离线安装的话,用户需要在这里配置自己的 Base URL,在线安装保持缺省值, 如图 4 所示。配置完成后点击下一步。

图 4 选择安装源界面

执行 cat /root/.ssh/id_dsa 获取 SSH Private Key,并把其粘贴到 web 上 SSH Private Key 粘贴区,如图 5 所示。其余的安装过程跟采用 HDP 等部署没有不同,用户可以根据安装向导来完成。值得注意的是,在 Confirm Hosts 过程中要尽量避免出现任何错误或警告。

图 5 安装设置界面

功夫不负有心人,经过一翻耐心的等待,大数据平台终于准备好了,快来开启大数据的旅程吧。

图 6 Ambari 机群服务界面

安装过程中常见问题及解决办法

问题 1:Ambari 节点报错 heartbeat lost

解决办法: ambari-agent restart

问题 2:登录 http://c6501.ambari.apache.org:8080/ 报错 Unable to connect

解决办法:外部机器登录主机,需要在外部机器的 hosts 文件中加入对应的 IP 映射。

问题 3:ntpd 报错

解决办法:到对应 node 下检查是否安装了 ntpd 包, 重启此服务 service ntpd restart

问题 4:Confirm Hosts 过程警告

解决办法:首先需要确定该机器以前是否安装部署过相关服务,如果部署过,则需要把以前部署时残留的目录、文件等信息全部删除。执行 python /usr/lib/python2.6/site-packages/ambari_agent/HostCleanup.py --silent --skip=users 后再移除对应机器存在的用户组。例如:

userdel -rf hive

userdel -rf zookeeper

userdel -rf spark

userdel -rf ambari-qa

userdel -rf hdfs

userdel -rf sqoop

userdel -rf yarn

userdel -rf hcat

userdel -rf mapred

userdel -rf hbase

userdel -rf oozie

userdel -rf flume

userdel -rf kafka

userdel -rf knox

userdel -rf ams

userdel -rf hadoop

userdel -rf tez

userdel -rf rrdcached

总结

由于大数据平台部署前对机群内机器都有一定的要求,如需要配置 SSH 无密码登录,修改文件最大限制,关闭防火墙,修改 hosts 文件等等,利用文中的脚本,通过简单的配置就可以在一台机器上完成整个机群所有节点部署前的配置工作,简单易用,能够节约大量的配置时间,减少配置时出错的机会。另外,此脚本同样也适用于采用 HDP 来部署大数据平台的机群预设置。当然,由于用户机群的差异性可能也存在部分服务缺失等问题,但这并不妨碍脚本的优势,希望大家能积极探讨,共同进步。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值