HDP一键配置

本文发布时间: 2019-Mar-22
本篇博客针对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=yesHOSTNAME=node80.example.comGATEWAY=192.168.0.2其中HOSTNAME配置为全称,同时还应配置GATEWAY/etc/sysconfig/network-scripts/ifcfg-eth0DEVICE="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.80NETMASK=255.255.255.0GATEWAY=192.168.0.2DNS1=192.168.0.80DOMAIN=example.com静态ip、配置dns为主节点、配置DOMAIN、关闭ipv6。2. 安装需要文件(放在/opt目录下):其中需要的文件是: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=rootpassword=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/profileyum -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/rhelecho 'Creating mount directory :' $yum_pathmkdir $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.repoecho "[rhel-local]name=rhel-localbaseurl=file://$yum_pathgpgcheck=0enabled=1" >> /etc/yum.repos.d/rhel.repoyum 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.repoecho "[rhel-http]name=rhel-httpbaseurl=http://$HOSTNAME/centos/Packagesgpgcheck=0enabled=1" >> /etc/yum.repos.d/rhel.reposervice httpd start && chkconfig httpd on && yum clean allecho "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/driftrestrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1 restrict -6 ::1# 这里注意 mask是否是255.255.255.0 ,同时注意前面的iprestrict $suffix_ip.0.0 mask 255.255.255.0 nomodify notraprestrict 0.rhel.pool.ntp.org mask 255.255.255.255 nomodify notrap noqueryrestrict 1.rhel.pool.ntp.org mask 255.255.255.255 nomodify notrap noqueryrestrict 2.rhel.pool.ntp.org mask 255.255.255.255 nomodify notrap noqueryserver127.127.1.0# local clockfudge127.127.1.0 stratum 10includefile /etc/ntp/crypto/pwkeys /etc/ntp/keys" > /etc/ntp.confservice 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.repotouch /etc/yum.repos.d/hdp.repoecho "[ambari-1.x]name=Ambari 1.xbaseurl=http://$HOSTNAME/ambari/centos6/1.x/updates/1.7.0gpgcheck=0enabled=1priority=1" >> /etc/yum.repos.d/ambari.repoecho "[HDP-2.2.0.0]name=Hortonworks Data Platform Version - HDP-2.2.0.0baseurl=http://$HOSTNAME/HDP/centos6/2.x/GA/2.2.0.0gpgcheck=0enabled=1priority=1[HDP-UTILS-1.1.0.20]name=Hortonworks Data Platform Utils Version - HDP-UTILS-1.1.0.20baseurl=http://$HOSTNAME/HDP-UTILS-1.1.0.20/repos/centos6gpgcheck=0enabled=1priority=1" >> /etc/yum.repos.d/hdp.repoyum 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 adminHELP " exit 0 fi yum -y install expect && echo "expect 安装完成"user=$1ip=$HOSTNAMEpass=$2rm -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 "" expect "*passphrase*" send "" expect "*again*" send "" expect eof " cat hosts | while read linedo#提取ipip_i=${line% *}full_hostname_i=${ip_i##* }ip_i=${ip_i% *}hostname_i=${line##* }expect -c "set timeout -1spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $hostname_iexpect "yes/no"send "yes"expect "password:"send "$pass"expect "#"expect eof"doneecho "ssh配置完成"generate_ssh.sh 首先安装expect工具,然后使用此工具以及提供的用户名和密码生成ssh无密码登录,并授权到slaves机器;(这里注意必须使用root用户)3.5 install_jdk_on_all_hosts.sh#!/bin/bash# 拷贝jdk安装脚本并 #拷贝jdk到所有host,并安装配置jdkcat hosts | while read linedo#提取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 -1spawn ssh $hostname_iexpect "#"send "/opt/install_jdk.sh"expect "#"send "exit"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-1tail -n $lines hosts | while read linedohostname_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 -1spawn ssh $hostname_iexpect "#"send "/opt/slaves.sh &"send "exit"expect eof"echo "$hostname_i配置完成"doneupdate_slaves.sh脚本原理和install_jdk_on_all_hosts.sh一致,同时是先拷贝必要的文件到各个slaves节点,然后使用expect工具远程登录到slaves节点运行slaves.sh脚本,进行配置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/driftrestrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1 restrict -6 ::1restrict default ignorerestrict $master_ip mask 255.255.255.255 nomodify notrap noqueryserver $master_ipincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keys" > /etc/ntp.confservice 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完成"slaves.sh的配置很多是和master节点一致。3.8 reboot_all.sh#!/bin/bash#重启slaves机器#############lines=`cat hosts |wc -l`let lines=lines-1tail -n $lines hosts | while read linedohostname_i=${line##* }echo "hostname:$hostname_i"expect -c "set timeout -1spawn ssh $hostname_iexpect "#"send "reboot"expect "#"expect eof"echo "$hostname_i重启中"done## 重启本机rebootreboot_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


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:09pm
栏目列表