离线自动化部署CDH

database

离线CDH集群自动化部署工具

离线CDH集群安装与部署的自动化脚本工具,简单支持「离线一键装机」。

脚本将对系统配置做出一定修改,使用前请务必确认当前服务器无其他人员、任务使用,以免造成不必要的麻烦,建议提前使用测试服务器或虚拟机测试体验。

一、Features

已实现的自动化功能(仅支持Redhat/CentOS系列):

Usage: init_ssh|install_softs|init_sys|init_dev|init_mysql|test_sys|init_cm|install_all

  1. init_ssh : Configure password-free login from the control machine to other machines
  2. install_softs : Make a custom yum source. Includes: Install http service, extract Centos7 rpm package, ansible rpm package, cdh related software.
  3. init_sys : Initialize the system configuration. Includes selinux, firewall, tuned, hugepage, swappiness, tmout, kernel, maxfiles
  4. init_dev : Configure jdk with version jdk-8u231-linux-x64
  5. init_mysql : Configure the scm configuration database, initialize the hive, scm, amon, ........... databases and authorize it
  6. test_sys : Test cluster network connectivity
  7. init_cm : Control node installation cloudera-scm-* and init the cloudera-scm-server with mysql
  8. install_all : Execute all scripts except init_ssh sequentially. sequen : install_softs->init_system->init_devenv->init_mysql->init_cm->test_system

二、Getting Start

在主机中选择一台执行操作过程,以下称为「控制主机」,并确保主机外网可用。

2.1 安装包准备

当前仅支持离线安装,需要提前下载所需软件安装包,如下:

  • JDK

    • 下载地址:Cloudera Archive CM
    • 说明:版本无限制,仅支持 Oracle JDK RPM包,名称格式为 oracle-j2sdk*.rpm
    • 示例安装包:jdk-8u231-linux-x64.rpm

  • Mariadb

    • 下载地址:Mariadb
    • 说明:5.7以上版本,仅支持RPM Bundle包,名称格式为 mariadb-server.x86_64.rpm
    • 示例安装包:mariadb-server.x86_64.rpm

  • MySQL驱动包(5.1.46)

    • 下载地址:MySQL Connector
    • 说明:与MySQL版本对应,名称格式为 mysql-connector-java-*.tar.gz
    • 示例安装包:mysql-connector-java-5.1.46.tar.gz

  • Cloudera Manager

    • 下载地址:Cloudera Archive CM
    • 说明:版本无限制
    • 示例安装包:

      • cloudera-manager-agent.x86_64 : The Cloudera Manager Agent
      • cloudera-manager-server.x86_64 : The Cloudera Manager Server
      • cloudera-manager-server-db-2.x86_64 : Embedded database for the Cloudera Manager Server
      • cloudera-manager-daemons.x86_64 : Provides daemons for monitoring Hadoop and related tools.

  • CDH

    • 下载地址:Cloudera Archive CDH
    • 说明:版本无限制
    • 示例安装包:

      • manifest.json
      • CDH-6.3.2-1.cdh6.3.2.p0.1605554-el7.parcel
      • allkeys.asc
      • CDH-6.3.2-1.cdh6.3.2.p0.1605554-el7.parcel.sha1
      • CDH-6.3.2-1.cdh6.3.2.p0.1605554-el7.parcel.sha256

  • Centos rpm

    • Centos 官网 ISO
    • 说明:版本系列和机器版本保持一致
    • 示例安装包:

      • centos7

  • ansible 安装包

    • rpm仓库
    • 说明:Centos7原生没有对应rpm包,自行下载
    • 示例安装包:

      • ansible-2.9.21-1.el7.noarch.rpm

百度云打包下载所有脚本:

链接:https://pan.baidu.com/s/1Qz_BFu0-4aOZ84nvC1FnOw 

提取码:lsom

上传所有安装包至控制主机的/tmp/autocdh/路径下。

2.2 修改hosts文件

vi hosts

将集群所有节点的ip与hostname写入hosts文件中,格式同/etc/hosts,ip与hosts之间空格隔开。

示例:

192.168.1.156 autocdh1

192.168.1.157 autocdh2

192.168.1.158 autocdh3

2.3 修改配置文件

vi deploy_robot.config

  • control_host: 控制主机节点hostname
  • host_user: 集群主机用户名,需要有root权限
  • host_passwd: 集群主机用户密码,所有主机需要一致
  • contrast_host: 网络测试使用的节点hostname
  • mysql_host: MySQL安装的节点hostname
  • http_server_host: Http服务节点
  • mysql_root_passwd: MySQL 初始化之后将使用此密码作为 root 用户密码
  • cm_host: cm server节点hostname
  • cm_db_passwd: cm数据库初始化密码

示例:

  • control_host=autocdh3
  • host_user=root
  • host_passwd=123123
  • contrast_host=autocdh3
  • http_server_host=autocdh2
  • mysql_host=autocdh1
  • mysql_root_passwd=123123
  • cm_host=autocdh3
  • cm_db_passwd=scm

2.4 执行脚本

# 配置ssh

sh deploy_robot.sh init_ssh

# 执行安装

sh deploy_robot.sh install_all

That"s All!

# 查看server启动日志

tail -f /var/log/cloudera-scm-server/cloudera-scm-server.log

# 等待几分钟后看到 Started Jetty server.

访问cm主机的7180端口即可,账号密码为默认的admin/admin,登录即可。

三、使用说明

3.1 脚本参数

sh deploy_robot.sh 

Usage: <type> init_ssh|install_softs|init_sys|init_dev|init_mysql|test_sys|init_cm|install_all

1. init_ssh : Configure password-free login from the control machine to other machines

2. install_softs : Make a custom yum source. Includes: Install http service, extract Centos7 rpm package, ansible rpm package, cdh related software.

3. init_sys : Initialize the system configuration. Includes selinux, firewall, tuned, hugepage, swappiness, tmout, kernel, maxfiles

4. init_dev : Configure jdk with version jdk-8u231-linux-x64

5. init_mysql : Configure the scm configuration database, initialize the hive, scm, amon, ........... databases and authorize it

6. test_sys : Test cluster network connectivity

7. init_cm : Control node installation cloudera-scm-* and init the cloudera-scm-server with mysql

8. install_all : Execute all scripts except init_ssh sequentially. sequen : install_softs->init_system->init_devenv->init_mysql->init_cm->test_system

执行脚本需要指定「执行类型」参数。

除了Features中各个功能的执行参数之外,install_all 将会依次执行2-7步骤。

3.2 yum软件安装列表

yum_requirements.txt 文件中描述了需要在集群各个节点上安装的软件名。

脚本执行过程中依赖相关软件,默认的软件列表不建议修改。

四、其他

4.1 注意事项

  1. 使用init_ssh设置免密登录时,如果已生成过ssh密钥,那么ssh的key与认证信息将被重置。如果之前配置过ssh信息请注意更新ssh key。或者选择不要执行init_ssh,手动进行ssh配置。
  2. 建议在即将投入生产或者干净的主机上运行,以免破坏已有生产系统环境。
  3. CM安装过程中不会启用SSL。

五、附录

5.1 主控脚本

#!/bin/bash

#

if [ $# -lt 1 ]

then

echo "Usage: <type> init_ssh|install_softs|init_sys|init_dev|init_mysql|test_sys|init_cm|install_all"

echo "init_ssh : Configure password-free login from the control machine to other machines "

echo "install_softs : Make a custom yum source. Includes: Install http service, extract Centos7 rpm package, ansible rpm package, cdh related software. "

echo "init_sys : Initialize the system configuration. Includes selinux, firewall, tuned, hugepage, swappiness, tmout, kernel, maxfiles"

echo "init_dev : Configure jdk with version jdk-8u231-linux-x64"

echo "init_mysql : Configure the scm configuration database, initialize the hive, scm, amon, ........... databases and authorize it "

echo "test_sys : Test cluster network connectivity"

echo "init_cm : Control node installation cloudera-scm-* and init the cloudera-scm-server with mysql"

echo "install_all : Execute all scripts except init_ssh sequentially. sequen : install_softs->init_system->init_devenv->init_mysql->init_cm->test_system"

exit 1

fi

# declare config

declare -A CONFIG_NANME=(

["CTRL_HOST"]="control_host"

["USER"]="host_user"

["PASSWD"]="host_passwd"

["CONTRAST"]="contrast_host"

["DB_HOST"]="mysql_host"

["DB_ROOT_PASSWD"]="mysql_root_passwd"

["CM_HOST"]="cm_host"

["CM_DB_PASSWD"]="cm_db_passwd"

["HTTP_SERVER_HOST"]="http_server_host"

)

declare -A config_map=()

declare -A hostip_map=()

export TOP_PID=$$

trap "exit 1" TERM

function quit {

kill -s TERM $TOP_PID

}

function say {

printf "33[1;4;%sm %s: %s 33[0m

" "$1" "$2" "$3"

}

function err {

say "31" "!!!![error]!!!! deploy failed" "$1" >&2

exit 1

}

function info {

say "32" "####[info]#### process info" "$1" >&1

}

function check_cmd {

command -v "$1" > /dev/null 2>&1

}

function need_cmd {

if ! check_cmd "$1"; then

err "need "$1" (command not found)"

fi

}

function need_ok {

if [[ $? -ne 0 ]]; then err "$1"; fi

}

function have_fun {

fun=`cat $SELF/have_fun`

printf "33[1;32m %s 33[0m

" "$fun"

}

function need_config {

if [ -z $1 ]

then

err "need key to get config"

else

c=${config_map[$1]}

if [ -z $c ]

then

err "config not found $1"

fi

fi

}

function get_config {

need_config $1

eval $2=${config_map[$1]}

info "get config $1:${config_map[$1]}."

}

function have {

if [ ! -f $1 ]

then

err "$1 file doesn"t exists"

fi

}

function init_config {

info "config loading..."

config_file=$1

info "get config_file $config_file."

have $config_file

config_arr=`cat $config_file | grep "="`

for c in ${config_arr}

do

arr=(${c//=/ })

key=${arr[0]}

value=${arr[1]}

config_map[$key]=$value

done

info "config load finished."

echo

}

function get_home {

if [ $1 == "root" ]

then

user_home="/root"

else

user_home="/home/$user"

fi

info "operate user home: $user_home"

echo

}

function init_hosts {

info "hosts loading..."

info "get host_file $SELF/hosts"

host_file=$SELF/hosts

have $host_file

host_arr=`cat $host_file | sed s"/ /,/"`

for a in ${host_arr[*]}

do

if [ -n $a ]

then

arr=(${a//,/ })

ip=${arr[0]}

host=${arr[1]}

need_ok "host dosen"t formated: $a"

hostip_map[$host]=$ip

fi

done

#key

hosts=${!hostip_map[@]}

info "hosts: $hosts"

#value

ips=${hostip_map[@]}

info "ips: $ips"

info "hosts load finished."

echo

}

function set_hosts {

# 主机名设置

info "start setting /etc/hosts and config ssh keys."

rpm -ivh $install_path/expect-5.45-14.el7_1.x86_64.rpm $install_path/tcl-8.5.13-8.el7.x86_64.rpm

need_cmd expect

have $expect_file

if [ -f /tmp/autocdh/hosts.bak ]

then

info "restore hosts from /tmp/hosts.bak"

cat /tmp/autocdh/hosts.bak > /etc/hosts

else

info "backup hosts file to /tmp/hosts.bak"

cat /etc/hosts > /tmp/autocdh/hosts.bak

fi

cat $host_file >> /etc/hosts

info "hosts added to /etc/hosts"

curr_hosts=`cat /etc/hosts`

info "current hosts: ${curr_hosts[*]}"

info "start config ssh key(all hosts)."

for host in ${hosts[*]}

do

expect $expect_file ssh $host $user $passwd "rm -rf $user_home/.ssh"

expect $expect_file ssh $host $user $passwd "hostnamectl set-hostname $host"

expect $expect_file scp $host $user $passwd /etc/hosts

expect $expect_file ssh $host $user $passwd "ssh-keygen -t rsa"

key=`expect $expect_file ssh $host $user $passwd "cat $user_home/.ssh/id_rsa.pub"`

echo $key | awk -F "ssh-rsa" "{printf "ssh-rsa%s

",$2}" >> $user_home/.ssh/authorized_keys

done

info "all hosts ssh key done."

info "scp authorized_keys to all hosts."

for host in ${hosts[*]}

do

expect $expect_file scp $host $user $passwd $user_home/.ssh/authorized_keys

done

info "scp authorized_keys done."

ssh $db_host date

need_ok "ssh failed."

echo

}

function install_ansible {

info "ansible control host clean and makecache"

yum clean all && yum makecache

info "start install ansible."

yum install -y ansible

need_cmd ansible

echo "[all]" > /etc/ansible/hosts

for host in ${hosts[*]}

do

echo $host >> /etc/ansible/hosts

done

info "ansible finish config."

echo

}

function ansible_command {

ansible all -a "$1"

need_ok "ansible command failed: $1"

}

function ansible_shell {

ansible all -m shell -a "$1"

need_ok "ansible shell failed: $1"

}

function ansible_copy {

ansible all -m copy -a "$1"

need_ok "ansible copy failed: $1"

}

function install_httpd {

info "httpd server host: $http_server_host"

ssh autocdh2 "httpd -version"

if [[ $? -eq 0 ]]; then

info "httpd service already installed"

else

apr_file=`ls $install_path/apr-1.4.8-3.el7_4.1.x86_64.rpm`

apr_util_file=`ls $install_path/apr-util-1.5.2-6.el7.x86_64.rpm`

httpd_file=`ls $install_path/httpd-2.4.6-88.el7.centos.x86_64.rpm`

httpd_tools_file=`ls $install_path/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm`

mailcap_file=`ls $install_path/mailcap-2.1.41-2.el7.noarch.rpm`

have $apr_file

have $apr_util_file

have $httpd_file

have $httpd_tools_file

have $mailcap_file

info "mkdir and scp to http host."

ssh $http_server_host <<EOF

mkdir /tmp/autocdh/

EOF

scp $apr_file $http_server_host:$install_path/

scp $apr_util_file $http_server_host:$install_path/

scp $httpd_file $http_server_host:$install_path/

scp $httpd_tools_file $http_server_host:$install_path/

scp $mailcap_file $http_server_host:$install_path/

info "scp httpd rpm done."

info "install httpd, wait a moment..."

ssh $http_server_host <<EOF

cd /tmp/autocdh/

rpm -ivh apr-1.4.8-3.el7_4.1.x86_64.rpm apr-util-1.5.2-6.el7.x86_64.rpm httpd-2.4.6-88.el7.centos.x86_64.rpm httpd-tools-2.4.6-88.el7.centos.x86_64.rpm mailcap-2.1.41-2.el7.noarch.rpm

if [ -f /etc/httpd/conf/httpd.conf ]

then

echo "add the httpd conf to support .parcel"

sed -i "s?AddType application/x-gzip .gz .tgz?AddType application/x-gzip .gz .tgz .parcel?" /etc/httpd/conf/httpd.conf

systemctl start httpd.service

systemctl enable httpd.service

systemctl stop firewalld

else

echo "http conf file not found"

exit

fi

EOF

info "httpd service install done"

fi

}

function unpack_repo_gz {

info "httpd server host: $http_server_host"

cdh_gz_file=`ls $install_path/cdh.tar.gz`

rhel7_gz_file=`ls $install_path/centos7.tar.gz`

ansible_gz_file=`ls $install_path/ansible.tar.gz`

have $cdh_gz_file

have $rhel7_gz_file

have $ansible_gz_file

info "mkdir and scp to http host."

scp $cdh_gz_file $http_server_host:$install_path

scp $rhel7_gz_file $http_server_host:$install_path

scp $ansible_gz_file $http_server_host:$install_path

info "scp cdh.tar.gz and centos7.tar.gz and ansible.tar.gz done."

ssh $http_server_host <<EOF

echo "unpack the cdh.tar.gz and centos7.tar.gz and ansible.tar.gz into /var/www/html/"

tar -zxvf /tmp/autocdh/cdh.tar.gz -C /var/www/html/

tar -zxvf /tmp/autocdh/centos7.tar.gz -C /var/www/html/

tar -zxvf /tmp/autocdh/ansible.tar.gz -C /var/www/html/

echo "unpack the gz file success"

EOF

}

function delete_void_repo {

info "delete void repo"

ansible_shell "cd /etc/yum.repos.d/ && ls | grep -v TZ | xargs rm -rf"

info "bakup all repo success"

}

function intranet_yum_repo {

info "start set intranet yum repo"

if [[ -f /etc/yum.repos.d/TZcdh.repo ]]; then

info "cdh repo already exists"

else

echo -e "[TZcdh]

name=TZcdh

baseurl=http://$http_server_host/cdh/

gpgcheck=0

enabled=1" >> /etc/yum.repos.d/TZcdh.repo

fi

if [[ -f /etc/yum.repos.d/TZcentos7.repo ]]; then

info "TZcentos7 repo already exists"

else

echo -e "[base]

name=TZCentOS-7

baseurl=http://$http_server_host/CentOS-7/

gpgcheck=1

enabled=1

gpgkey=http://$http_server_host/CentOS-7/RPM-GPG-KEY-CentOS-7" >> /etc/yum.repos.d/TZcentos7.repo

fi

if [[ -f /etc/yum.repos.d/TZansible.repo ]]; then

info "TZansible repo already exists"

else

echo -e "[TZansible]

name=TZansible

baseurl=http://$http_server_host/ansible/

gpgcheck=0

enabled=1" >> /etc/yum.repos.d/TZansible.repo

fi

echo

}

function sync_repo {

info "sync repo for all cluster "

ansible all -m copy -a "src=/etc/yum.repos.d/TZcdh.repo dest=/etc/yum.repos.d/TZcdh.repo"

ansible all -m copy -a "src=/etc/yum.repos.d/TZansible.repo dest=/etc/yum.repos.d/TZansible.repo"

ansible all -m copy -a "src=/etc/yum.repos.d/TZcentos7.repo dest=/etc/yum.repos.d/TZcentos7.repo"

info "yum repo sync done."

}

function set_yum {

info "start set yum."

info "clean and makecache,it may take a little time, please wait a moment..."

ansible_shell "yum clean all && yum makecache"

info "install softs."

yum_requrements=`cat $SELF/yum_requirements.txt`

echo "yum install -y $yum_requrements"

ansible_command "yum install -y $yum_requrements"

info "install softs done."

echo

}

function set_selinux {

selinux_stat=`getenforce | tr "A-Z" "a-z"`

info "setting selinux, current: $selinux_stat."

if [ $selinux_stat == "enforcing" ]

then

info "change to disable..."

sed -i "s/SELINUX=enforcing/SELINUX=disable/" /etc/selinux/config

sed -i "s/SELINUX=Enforcing/SELINUX=disable/" /etc/selinux/config

curr=`cat /etc/selinux/config | grep -v "#" | grep SELINUX=`

info "current: $curr."

fi

info "sync to hosts."

ansible all -m copy -a "src=/etc/selinux/config dest=/etc/selinux/config"

info "done."

echo

}

function set_firewall {

info "disable firewalld..."

ansible all -a "systemctl status firewalld"

ansible all -a "systemctl stop firewalld"

ansible all -a "systemctl disable firewalld"

info "firewalld disabled."

echo

}

function set_ntp {

# ntp配置

info "start ntp server..."

info "change timezone info to Shanghai."

ansible all -m shell -a "rm -rf /etc/localtime && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime"

info "install ntpd."

ansible all -a "yum install ntp -y"

info "sync time to 0.cn.pool.ntp.org"

ansible all -a "ntpdate -u 0.cn.pool.ntp.org"

info "add ntp1.aliyun.com to ntp.conf"

is_exists=`cat /etc/ntp.conf | grep aliyun | wc -l`

if [ $is_exists -eq 0 ]

then

echo "server ntp1.aliyun.com" >> /etc/ntp.conf

fi

ansible all -a "systemctl start ntpd"

ansible all -a "systemctl enable ntpd"

info "ntp done."

echo

}

function set_java {

info "start set java..."

info "remove the old java | jdk"

ansible all -a "rpm -qa | grep java | xargs rpm -e --nodeps"

ansible all -a "rpm -qa | grep jdk | xargs rpm -e --nodeps"

ansible all -a "rpm -ivh http://$http_server_host/cdh/jdk-8u231-linux-x64.rpm"

if ! check_cmd java; then

info "java install failed"

else

info "java already installed."

fi

info "java install done."

echo

}

function set_tuned {

info "disable tuned..."

ansible all -a "systemctl start tuned"

ansible all -a "systemctl status tuned"

ansible all -a "tuned-adm off"

ansible all -a "tuned-adm list"

ansible all -a "systemctl stop tuned"

ansible all -a "systemctl disable tuned"

info "tuned config done."

echo

}

function set_hugepage {

info "disable hugepage..."

curr0=`cat /sys/kernel/mm/transparent_hugepage/enabled`

curr1=`cat /sys/kernel/mm/transparent_hugepage/defrag`

info "current: $curr0 , $curr1"

is_enable=`cat /sys/kernel/mm/transparent_hugepage/enabled | grep \[always\] | wc -l`

is_defrag=`cat /sys/kernel/mm/transparent_hugepage/defrag | grep \[always\] | wc -l`

if [ $is_enable -eq 1 ]

then

ansible all -m shell -a "echo never > /sys/kernel/mm/transparent_hugepage/enabled"

ansible all -m shell -a "echo never > /sys/kernel/mm/transparent_hugepage/defrag"

echo "echo never > /sys/kernel/mm/transparent_hugepage/defrag" >> /etc/rc.local

echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local

chmod +x /etc/rc.d/rc.local

ansible all -m copy -a "src=/etc/rc.d/rc.local dest=/etc/rc.d/rc.local"

original=`cat /etc/default/grub | grep GRUB_CMDLINE_LINUX | awk -F "="" "{print $2}"`

result="GRUB_CMDLINE_LINUX="transparent_hugepage=never "$original

cat /etc/default/grub | grep -v GRUB_CMDLINE_LINUX > /etc/default/grub

echo $result >> /etc/default/grub

curr2=`cat /etc/default/grub | grep GRUB_CMDLINE_LINUX`

info "current: $curr2"

ansible all -m copy -a "src=/etc/default/grub dest=/etc/default/grub"

ansible all -a "grub2-mkconfig -o /boot/grub2/grub.cfg"

fi

info "setting hugepage done."

echo

}

function set_swappiness {

info "set swappiness..."

swap_stat=`cat /proc/sys/vm/swappiness`

info "current: $swap_stat"

if [ ! $swap_stat -eq 1 ]

then

ansible all -a "sysctl -w vm.swappiness=1"

echo "vm.swappiness=1" >> /etc/sysctl.conf

curr=`cat /etc/sysctl.conf | grep swappiness`

info "current: $curr"

ansible all -m copy -a "src=/etc/sysctl.conf dest=/etc/sysctl.conf"

fi

info "setting swappiness done."

echo

}

function set_tmout {

info "set tmout to 900"

is_exists=`cat /etc/profile | grep TMOUT=900 | wc -l`

if [ $is_exists -eq 0 ]

then

echo "TMOUT=900" >> /etc/profile

ansible all -m copy -a "src=/etc/profile dest=/etc/profile"

else

info "tmout already installed"

fi

info "setting tmout done."

echo

}

function set_kernel {

info "setting kernel..."

is_exists=`cat /etc/sysctl.conf | grep pid_max | wc -l`

if [ $is_exists -eq 0 ]

then

echo -e "

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_keepalive_time = 1200

net.ipv4.ip_local_port_range = 10000 65000

net.ipv4.tcp_max_syn_backlog = 8192

net.ipv4.tcp_max_tw_buckets = 5000

fs.file-max = 655350

net.ipv4.route.gc_timeout = 100

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_synack_retries = 1

net.core.netdev_max_backlog = 16384

net.ipv4.tcp_max_orphans = 16384

net.ipv4.tcp_fin_timeout = 2

et.core.somaxconn=32768

kernel.threads-max=196605

kernel.pid_max=196605

vm.max_map_count=393210" >> /etc/sysctl.conf

else

info "kernel already installed."

fi

ansible all -m copy -a "src=/etc/sysctl.conf dest=/etc/sysctl.conf"

info "setting kernel done."

echo

}

function set_maxfiles {

curr=`ulimit -a`

info "current max files: $curr

change to 196605..."

is_exists=`cat /etc/security/limits.conf | grep 196605 | wc -l`

if [ $is_exists -eq 0 ]

then

sed -i "$ a* soft nofile 196605" /etc/security/limits.conf

sed -i "$ a* hard nofile 196605" /etc/security/limits.conf

echo "* soft nproc 196605" >> /etc/security/limits.conf

echo "* hard nproc 196605" >> /etc/security/limits.conf

else

info "ulimit already installed."

fi

ansible all -m copy -a "src=/etc/security/limits.conf dest=/etc/security/limits.conf"

info "setting maxfiles done."

echo

}

function get_sysinfo {

sys_version=`cat /etc/redhat-release`

info "operator system version: $sys_version"

umask_info=`umask`

info "umask: $umask_info"

java_version=`java -version`

info "java version: $java_version"

info "java_home: $jdk_path"

total_mem=`free -h | grep Mem | awk "{print $2}"`

info "total memory: $total_mem"

cpu_num=`cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l`

info "number of cpu: $cpu_num"

cpu_cores=`cat /proc/cpuinfo| grep "cpu cores"| uniq`

info "core number per cpu: $cpu_cores"

total_cpu=`cat /proc/cpuinfo| grep "processor"| wc -l`

info "logic cpu cores: $total_cpu"

cpu_info=`cat /proc/cpuinfo`

info "cpu info:

$cpu_info"

echo

}

function test_network {

info "start network test..."

info "contrast host is: $contrast_host, start iperf server."

nohup iperf3 -s -p 12345 -i 1 > /dev/null 2>&1 &

pid=`ps -ef | grep iperf3 | grep -v "grep" | awk "{print $2}"`

if [ $? -eq 0 ]

then

info "iperf3 server pid: $pid"

else

err "iperf3 server start failed."

fi

info "start iperf client, please wait a moment..."

echo "####network test####" > $test_sys_file

ssh $contrast_host "iperf3 -c $ctrl_host -p 12345 -i 1 -t 10 -w 100K" >> $test_sys_file

echo "" >> $test_sys_file

echo "" >> $test_sys_file

info "test done,save result to $test_sys_file killing iperf server, pid: $pid"

kill -9 $pid

echo

}

function set_mariadb {

info "start set mariadb..."

ssh $db_host "mysql"

if ! "$?" -eq 0 ; then

info "mariadb host: $db_host"

ssh $db_host <<EOF

yum install -y mariadb-server

systemctl start mariadb

systemctl enable mariadb

mysql_secure_installation << EOF

y

$mysql_passwd

$mysql_passwd

y

y

y

y

EOF

EOF

else

info "mysql already installed."

fi

# 初始化cm相关库

ssh $db_host <<EOF

mysql -u root -p"$mysql_passwd" -e "drop database scm;"

mysql -u root -p"$mysql_passwd" -e "drop database amon;"

mysql -u root -p"$mysql_passwd" -e "drop database hive;"

mysql -u root -p"$mysql_passwd" -e "CREATE DATABASE scm DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"

mysql -u root -p"$mysql_passwd" -e "GRANT ALL ON scm.* TO "scm"@"%" IDENTIFIED BY "scm";"

mysql -u root -p"$mysql_passwd" -e "CREATE DATABASE amon DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"

mysql -u root -p"$mysql_passwd" -e "GRANT ALL ON amon.* TO "amon"@"%" IDENTIFIED BY "amon";"

mysql -u root -p"$mysql_passwd" -e "CREATE DATABASE hive DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"

mysql -u root -p"$mysql_passwd" -e "GRANT ALL ON hive.* TO "hive"@"%" IDENTIFIED BY "hive";"

mysql -u root -p"$mysql_passwd" -e "SHOW DATABASES;"

mysql -u root -p"$mysql_passwd" -e "flush privileges;"

EOF

info "done."

echo

}

function set_scm_server {

info "start install cloudera-scm-server "

is_exists=`systemctl status cloudera-scm-server`

if [ ! -z "$is_exists" ]

then

info "cloudera-scm-server already installed."

else

info "yum install cloudera-scm-server"

yum install -y cloudera*

ansible_copy "src=$install_path/mysql-connector-java.jar dest=/usr/share/java/"

ansible_copy "src=$install_path/mysql-connector-java.jar dest=/opt/cloudera/cm/lib/"

/opt/cloudera/cm/schema/scm_prepare_database.sh -h $db_host -P 3306 mysql scm scm scm

service cloudera-scm-server start

systemctl enable cloudera-scm-server

fi

}

function need_ssh {

if [ ! -f /tmp/autocdh/hosts.bak ]

then

err "hosts not set, it may means ssh not init. try tu use <sh deploy_robot.sh init_ssh>."

fi

}

function init_ssh {

set_hosts

}

function install_softs {

install_httpd

unpack_repo_gz

bakup_repo

intranet_yum_repo

install_ansible

delete_void_repo

sync_repo

set_yum

need_ssh

}

function init_system {

need_ssh

need_cmd ansible

set_selinux

set_firewall

set_tuned

set_hugepage

set_swappiness

set_tmout

set_kernel

set_maxfiles

}

function init_devenv {

need_ssh

need_cmd ansible

set_java

}

function init_mysql {

need_ssh

set_mariadb

}

function test_system {

need_ssh

test_network

}

function init_cm {

need_ssh

need_cmd ansible

set_scm_server

}

SELF=$(cd $(dirname $0) && pwd)

cd $SELF

tmp_path=/tmp/autocdh

install_path=$tmp_path

test_sys_file=$SELF/test_sys.log

config_file=$SELF/deploy_robot.config

expect_file=$SELF/expect.sh

info "start deploy process."

exec=$1

init_config $config_file

# 控制主机与用户名、密码

get_config ${CONFIG_NANME[CTRL_HOST]} ctrl_host

get_config ${CONFIG_NANME[USER]} user

get_config ${CONFIG_NANME[PASSWD]} passwd

get_config ${CONFIG_NANME[CONTRAST]} contrast_host

get_config ${CONFIG_NANME[DB_HOST]} db_host

get_config ${CONFIG_NANME[DB_ROOT_PASSWD]} mysql_passwd

get_config ${CONFIG_NANME[CM_HOST]} cm_host

get_config ${CONFIG_NANME[CM_DB_PASSWD]} cm_db_passwd

get_config ${CONFIG_NANME[HTTP_SERVER_HOST]} http_server_host

get_home $user

init_hosts

if [ $exec == "init_ssh" ]

then

init_ssh

elif [ $exec == "install_softs" ]

then

install_softs

elif [ $exec == "init_sys" ]

then

init_system

elif [ $exec == "init_dev" ]

then

init_devenv

elif [ $exec == "init_mysql" ]

then

init_mysql

elif [ $exec == "test_sys" ]

then

test_system

elif [ $exec == "init_cm" ]

then

init_cm

elif [ $exec == "install_all" ]

then

install_softs

init_system

init_devenv

init_mysql

init_cm

test_system

else

info "nothing todo, exit...

try to use init_ssh|install_softs|init_sys|init_dev|init_mysql|test_sys|init_cm|install_all ?"

exit 0

fi

get_sysinfo

have_fun

info "install all done!!!"

5.2 主控配置文件

# 控制主机-执行脚本的机器

control_host=autocdh3

# 控制主机用户名

host_user=root

# 控制主机密码

host_passwd=123123

# 网络测试主机

contrast_host=autocdh3

# http服务主机

http_server_host=autocdh2

# mysql服务器地址

mysql_host=autocdh1

# mysql root密码

mysql_root_passwd=123123

# cm服务器地址

cm_host=autocdh3

# cm数据库密码

cm_db_passwd=scm

5.3 except 脚本

#!/bin/expect

if {$argc != 5} {

puts "Usage:cmd <exec> <host> <user> <passwd> <command>"

exit 1

}

proc init_mysql_passwd {init_passwd new_passwd} {

expect {

"*Enter password for user root*" { send "$init_passwd

"; exp_continue}

"*New password*" { send "$new_passwd

" ; exp_continue}

"*Re-enter new password*" { send "$new_passwd

"; exp_continue}

"*Do you wish to continue with the password provided*" { send "y

"; exp_continue}

"*Change the password for root*" { send "y

"; exp_continue}

"*Remove anonymous users*" { send "y

"; exp_continue}

"*Disallow root login remotely*" { send "

"; exp_continue}

"*Remove test database and access to it*" { send "y

"; exp_continue}

"*Reload privilege tables now*" { send "y

"; exp_continue}

"*Enter SCM password*" { send "$new_passwd

"; exp_continue}

"*#" { return 0}

}

return 1

}

proc connect {passwd} {

expect {

"(yes/no)?" {

send "yes

"

expect "*password:" {

send "$passwd

"

expect {

"*#" {

return 0

}

}

}

}

"*"s password:" {

send "$passwd

"

expect {

"Overwrite (y/n)" {

send "y

"

exp_continue

}

"*file in which to save the key*" {

send "

"

exp_continue

}

"*Enter passphrase*" {

send "

"

exp_continue

}

"*Enter same passphrase again*" {

send "

"

exp_continue

}

"*#" {

return 0

}

}

}

}

return 1

}

set timeout 30

set exec [lindex $argv 0]

set host [lindex $argv 1]

set user [lindex $argv 2]

set passwd [lindex $argv 3]

set cmd [lindex $argv 4]

if {$exec == "ssh"} {

spawn ssh $user@$host $cmd

if {[connect $passwd]} {

exit 1

}

} elseif {$exec == "scp"} {

spawn scp $cmd $user@$host:$cmd

if {[connect $passwd]} {

exit 1

}

} elseif {$exec == "get"} {

spawn scp $user@$host:$cmd $cmd

if {[connect $passwd]} {

exit 1

}

} elseif {$exec == "mysql_init"} {

spawn /usr/bin/mysql_secure_installation

if {[init_mysql_passwd $passwd $cmd]} {

exit 1

}

} elseif {$exec == "cm_init" } {

spawn /opt/cloudera/cm/schema/scm_prepare_database.sh -h $host mysql scm scm

if {[init_mysql_passwd $passwd $cmd]} {

exit 1

}

} else {

puts "exec type error"

}

expect eof

5.4 软件安装列表

expect

bc

net-tools

iotop

zip

unzip

telnet

wget

iperf3

fio

ntfs-3g

lzo

iftop

vim

lrzsz

net-tools

运行结果

以上是 离线自动化部署CDH 的全部内容, 来源链接: utcz.com/z/536503.html

回到顶部