本篇博客针对HortonWorks Data Platform平台配置,使用此配置完成后,可以直接在浏览器登陆ambari进行集群配置,即此配置是前置条件配置!
脚本可在HDP一键部署下载!
环境:
操作系统:CentOS6.6 、HDP2.2 (hdp:2.2.0.0,hdp-util:1.1.0.20)、ambari:1.7;
这里使用的机器全部是安装完操作系统后(最小化安装,同时所有机器安装的操作系统版本需保持一致),配置完网络后的机器。
1. 网络配置:
/etc/sysconfig/network :
NETWORKING=yes
HOSTNAME=node80.example.com
GATEWAY=192.168.0.2
其中HOSTNAME配置为全称,同时还应配置GATEWAY
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:71:33:61"
IPV6INIT="no"
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
UUID="827078f8-57da-4105-a803-2c8011d72092"
IPADDR=192.168.0.80
NETMASK=255.255.255.0
GATEWAY=192.168.0.2
DNS1=192.168.0.80
DOMAIN=example.com
静态ip、配置dns为主节点、配置DOMAIN、关闭ipv6。
2. 安装需要文件(放在/opt目录下)相关hdp下载:http://s3.amazonaws.com/public-repo-1.hortonworks.com/index.html :
其中需要的文件是:ambari-1.7.0-centos6.tar.gz (需固定)、 HDP-UTILS-1.1.0.20-centos6.tar.gz(需固定)
CentOS-6.6-x86_64-bin-DVD1.iso(可替换,根据操作系统的不同而不同)
HDP-2.2.0.0-centos6-rpm.tar.gz (需固定)、 jdk-7u80-linux-x64.tar.gz(可替换),一共有5个文件,把这5个文件放在/opt目录下面,这个是必须的!!!(在代码里把这个参数写死了的)
3. hdp一键部署脚本分析:
脚本可以在HDP一键部署下载!
(一般需要增加文件的执行权限,下载解压后,进入文件夹,运行:chmod +x *.sh)
3.1 打开one_key.sh:
#!/bin/bash
# HDP一键安装
# 拷贝iso安装文件、jdk、HDP、HDP-UTILS、Ambari安装文件到/opt目录
# 配置好主节点和各slaves节点ip,注意配置dns为主节点
# 修改本目录hosts文件,第一行为主节点
# 修改本文件中的password为root的密码,必须使用root用户
user=root
password=admin
./create_local_yum.sh && echo "create_local_yum.sh 执行成功"
./update_master.sh && echo "update_master.sh 执行成功"
./generate_ssh.sh $user $password && echo "generate_ssh.sh 执行成功"
./install_jdk_on_all_hosts.sh && echo "install_jdk_on_all_hosts.sh 执行成功"
./update_slaves.sh && echo "update_slave.sh 执行成功"
echo "一键安装配置完成,开始配置ambari..."
source /etc/profile
yum -y install ambari-server && ambari-server setup -j $JAVA_HOME -s && ambari-server start && echo "Ambari安装完成,请在浏览器中输入http://$HOSTNAME:8080 进行配置!"
# 重启所有机器
./reboot_all.sh
这里分为6步:
1、制作本地yum源,安装必要软件;
2、更新主节点;
3、在主节点配置ssh无密码登录,同时配置到其他slave节点的无密码登录;
4、在所有节点安装并配置jdk;
5、 更新slaves节点所需软件及服务;
6、安装、配置ambari-server,并重启所有节点;
3.2 create_local_yum.sh
#!/bin/bash
# 使用提供的iso安装文件来挂载本地yum源
iso_path=/opt/`ls /opt/ | grep ".iso"`
echo "Iso file path is :" $iso_path
#创建挂载目录
yum_path=/mnt/rhel
echo 'Creating mount directory :' $yum_path
mkdir $yum_path
#######################################
mount -o loop $iso_path $yum_path && echo 'Finished mount yum repository'
##########################################
echo 'Updating /etc/yum.repos.d/ files...'
rm -rf /etc/yum.repos.d/*
touch /etc/yum.repos.d/rhel.repo
echo "
[rhel-local]
name=rhel-local
baseurl=file://$yum_path
gpgcheck=0
enabled=1
" >> /etc/yum.repos.d/rhel.repo
yum clean all && echo 'yum repository has been updated! '
此步骤即把安装文件iso挂载在/mnt/rhel目录,然后更新本地yum.repos.d中的文件,为下面的安装软件提供支持!
3.3 update_master.sh
#!/bin/bash
# 应该首先安装expect,这一步前 应该确认yum可用
#往本机/etc/hosts添加hosts文件内容#############
cat hosts >> /etc/hosts;
echo "添加hosts到/etc/hosts文件完成";
host_ip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
suffix_ip=${host_ip%.*}
suffix_ip=${suffix_ip%.*}
# 安装必要的软件并制作http源###################
yum -y install vim httpd createrepo perl bind-utils openssh-clients ntp vim wget unzip bind && chkconfig httpd on && mkdir /var/www/html/centos && mkdir /var/www/html/centos/Packages &&echo "拷贝文件中..." && cp /mnt/rhel/Packages /var/www/html/centos/Packages -r && echo "拷贝文件完成,生成源中..." && createrepo /var/www/html/centos/Packages && rm -rf /etc/yum.repos.d/* && echo "http源拷贝完成,更新yum..."
touch /etc/yum.repos.d/rhel.repo
echo "
[rhel-http]
name=rhel-http
baseurl=http://$HOSTNAME/centos/Packages
gpgcheck=0
enabled=1
" >> /etc/yum.repos.d/rhel.repo
service httpd start && chkconfig httpd on && yum clean all
echo "http 源已经配置完成"
#配置dns#######################
echo "开始配置dns..."
#cp named.conf /etc/named.conf && cp db.* /var/named/ && service named start && chkconfig named on && echo "dns 配置完成"
sh generate_named.conf.sh && sh generate_db.192.sh && sh generate_db.hortonworks.com.sh && service named start && chkconfig named on && echo "dns 配置完成"
# 配置 ntp#########################
echo "开始配置ntp..."
chkconfig ntpd on
#cp ntp.conf /etc/ntp.conf
# 写入ntp.conf文件
echo "
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
# 这里注意 mask是否是255.255.255.0 ,同时注意前面的ip
restrict $suffix_ip.0.0 mask 255.255.255.0 nomodify notrap
restrict 0.rhel.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 1.rhel.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 2.rhel.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
" > /etc/ntp.conf
service ntpd start && echo "ntp 配置完成!"
## 配置 hdp yum####################
echo "开始配置hdp..."
tar -zxvf /opt/ambari-1.7.0-centos6.tar.gz -C /var/www/html;
tar -zxvf /opt/HDP-2.2.0.0-centos6-rpm.tar.gz -C /var/www/html;
tar -zxvf /opt/HDP-UTILS-1.1.0.20-centos6.tar.gz -C /var/www/html;
# 写入文件
touch /etc/yum.repos.d/ambari.repo
touch /etc/yum.repos.d/hdp.repo
echo "
[ambari-1.x]
name=Ambari 1.x
baseurl=http://$HOSTNAME/ambari/centos6/1.x/updates/1.7.0
gpgcheck=0
enabled=1
priority=1
" >> /etc/yum.repos.d/ambari.repo
echo "
[HDP-2.2.0.0]
name=Hortonworks Data Platform Version - HDP-2.2.0.0
baseurl=http://$HOSTNAME/HDP/centos6/2.x/GA/2.2.0.0
gpgcheck=0
enabled=1
priority=1
[HDP-UTILS-1.1.0.20]
name=Hortonworks Data Platform Utils Version - HDP-UTILS-1.1.0.20
baseurl=http://$HOSTNAME/HDP-UTILS-1.1.0.20/repos/centos6
gpgcheck=0
enabled=1
priority=1
" >> /etc/yum.repos.d/hdp.repo
yum clean all && echo "HDP 配置完成"
# 配置selinux#############
echo "开始配置selinux..."
sed -i 's/enforcing/disabled/' /etc/selinux/config && echo "selinux 配置完成"
# 配置 iptalbes###########
echo "开始配置iptables..."
service iptables stop && chkconfig iptables off && service ip6tables stop && chkconfig ip6tables off && echo "iptables配置完成"
# 关闭 THP################
echo "关闭THP..."
echo "if test -f /sys/kernel/mm/redhat_transparent_hugepage/defrag;then echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag fi" >> /etc/rc.local && echo "闭THP完成"
echo "更新主节点完成"
a. 更新/etc/hosts文件;
b. 安装必要的软件;
c. 更新/etc/yum.repos.d中的文件,添加操作系统的安装包的http资源;
d. 配置dns(这里引入了三个文件生成脚本:generate_named.conf.sh 、 generate_db.192.sh 、generate_db.hortonworks.com.sh);
e. 配置ntp;
f. 解压HDP相关安装文件,并生成yum.repos.d下面的文件,制作http资源;
g. 配置 selinux、iptables、关闭THP;
3.4 generate_ssh.sh
#!/bin/bash
# 本机产生无密码登录,同时设置其他机器无密码登录
# 必须使用root用户
if [ $# -lt 2 ]; then
echo " HELP
generate_ssh.sh --generate ssh key for login without typing password;
this script should run on the namenode machine and user should edit the ip-list file
USAGE: ./generate_ssh.sh user pasaword
EXAMPLE: ./generate_ssh root admin
HELP
"
exit 0
fi
yum -y install expect && echo "expect 安装完成"
user=$1
ip=$HOSTNAME
pass=$2
rm -rf /root/.ssh/*
echo "##################################"
echo " generate the rsa public key on $HOSTNAME ..."
echo "##################################"
expect -c "
set timeout -1
spawn ssh-keygen -t rsa
expect \"*id_rsa*\"
send \"\r\"
expect \"*passphrase*\"
send \"\r\"
expect \"*again*\"
send \"\r\"
expect eof
"
cat hosts | while read line
do
#提取ip
ip_i=${line% *}
full_hostname_i=${ip_i##* }
ip_i=${ip_i% *}
hostname_i=${line##* }
expect -c "
set timeout -1
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $hostname_i
expect \"yes/no\"
send \"yes\r\"
expect \"password:\"
send \"$pass\r\"
expect \"#\"
expect eof
"
done
echo "ssh配置完成"
3.5 install_jdk_on_all_hosts.sh
#!/bin/bash
# 拷贝jdk安装脚本并
#拷贝jdk到所有host,并安装配置jdk
cat hosts | while read line
do
#提取ip
# ip_i=${line% *}
# full_hostname_i=${ip_i##* }
# ip_i=${ip_i% *}
hostname_i=${line##* }
echo "hostname:$hostname_i"
scp /opt/jdk-* $hostname_i:/opt/
scp ./install_jdk.sh $hostname_i:/opt/
expect -c "
set timeout -1
spawn ssh $hostname_i
expect \"#\"
send \"/opt/install_jdk.sh\r\"
expect \"#\"
send \"exit\r\"
expect eof
"
echo "$hostname_i 节点安装jdk完成"
done
这里变量hosts文件中的slaves机器,使用scp命令拷贝jdk、install_jdk.sh到各个slaves机器,接着使用expect命令远程登录到各个slaves机器,运行刚才拷贝的install_jdk.sh文件。install_jdk.sh文件主要是配置、安装jdk。
3.6 update_slave.sh
#!/bin/bash
# 1. 把yum源拷贝到slaves,并更新
# 2. 在slaves安装软件
# 3. 执行slaves.sh ,进行配置
#往slaves 机器拷贝yum、hosts文件#############
lines=`cat hosts |wc -l`
let lines=lines-1
tail -n $lines hosts | while read line
do
hostname_i=${line##* }
echo "hostname:$hostname_i"
scp /etc/yum.repos.d/* $hostname_i:/etc/yum.repos.d/
scp hosts $hostname_i:/opt/
scp slaves.sh $hostname_i:/opt/
echo "yum、hosts、slaves.sh 拷贝完成"
expect -c "
set timeout -1
spawn ssh $hostname_i
expect \"#\"
send \"/opt/slaves.sh &\r\"
send \"exit\r\"
expect eof
"
echo "$hostname_i配置完成"
done
3.7 slaves.sh
#!/bin/bash
#往slave /etc/hosts添加hosts文件内容#############
cat /opt/hosts >> /etc/hosts;
echo "添加/opt/hosts到/etc/hosts文件完成";
master_ip=`head -n 1 /opt/hosts`
master_ip=${master_ip% *}
master_ip=${master_ip% *}
echo "master_ip:$master_ip"
# 更新yum源
rm -rf /etc/yum.repos.d/CentOS* && yum clean all && yum -y install perl bind-utils openssh-clients ntp vim wget unzip && echo "yum源更新完成 ,相关软件安装完成"
# 配置 ntp#########################
echo "开始配置ntp..."
chkconfig ntpd on
#cp ntp.conf /etc/ntp.conf
# 写入ntp.conf文件
echo "
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
restrict default ignore
restrict $master_ip mask 255.255.255.255 nomodify notrap noquery
server $master_ip
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
" > /etc/ntp.conf
service ntpd start && echo "ntp 配置完成!"
echo "开始配置selinux..."
sed -i 's/enforcing/disabled/' /etc/selinux/config && echo "selinux 配置完成"
# 配置 iptalbes###########
echo "开始配置iptables..."
service iptables stop && chkconfig iptables off && service ip6tables stop && chkconfig ip6tables off && echo "iptables配置完成"
# 关闭 THP################
echo "关闭THP..."
echo "
if test -f /sys/kernel/mm/redhat_transparent_hugepage/defrag;then echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag fi" >> /etc/rc.local && echo "关闭THP完成"
echo "更新$HOSTNAME完成"
3.8 reboot_all.sh
#!/bin/bash
#重启slaves机器#############
lines=`cat hosts |wc -l`
let lines=lines-1
tail -n $lines hosts | while read line
do
hostname_i=${line##* }
echo "hostname:$hostname_i"
expect -c "
set timeout -1
spawn ssh $hostname_i
expect \"#\"
send \"reboot\r\"
expect \"#\"
expect eof
"
echo "$hostname_i重启中"
done
## 重启本机
reboot
reboot_all.sh 首先使用expect工具远程登录到各个slaves节点,然后执行重启命令,最后再本机执行重启即可。
运行:
0)配置过程中全程使用root用户;
1)确保网络配置ok;
2)拷贝5个安装文件到/opt目录下面;
3)下载HDP一键安装脚本,并解压,添加运行权限;
4)修改HDP一键安装脚本中的hosts文件,改为自己集群所需机器名;
5)修改one_key.sh中的用户名和密码;
6)进入解压目录,运行:./one_key.sh >> one_key.log &
7)tail -f one_key.log 实时查看log输出;
8)等待重启完成后,可以手动检查dns、ntp、iptables等等配置是否正确;
9)如果配置正确,即可在浏览器访问8080端口开始集群的配置!
分享,成长,快乐
脚踏实地,专注
转载请注明blog地址:http://blog.csdn.net/fansy1990