主頁 > 資料庫 > 離線自動化部署CDH

離線自動化部署CDH

2022-05-11 08:24:25 資料庫

離線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 '\033[1;4;%sm %s: %s \033[0m\n' "$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 '\033[1;32m %s \033[0m\n\n' "$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=https://www.cnblogs.com/shun57/p/${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\n",$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=https://www.cnblogs.com/etc/yum.repos.d/TZcdh.repo dest=/etc/yum.repos.d/TZcdh.repo"
    ansible all -m copy -a "src=https://www.cnblogs.com/etc/yum.repos.d/TZansible.repo dest=/etc/yum.repos.d/TZansible.repo"
    ansible all -m copy -a "src=https://www.cnblogs.com/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=https://www.cnblogs.com/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=https://www.cnblogs.com/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=https://www.cnblogs.com/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=https://www.cnblogs.com/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=https://www.cnblogs.com/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 "\nnet.ipv4.tcp_tw_reuse = 1
        \nnet.ipv4.tcp_tw_recycle = 1
        \nnet.ipv4.tcp_keepalive_time = 1200
        \nnet.ipv4.ip_local_port_range = 10000 65000
        \nnet.ipv4.tcp_max_syn_backlog = 8192
        \nnet.ipv4.tcp_max_tw_buckets = 5000
        \nfs.file-max = 655350
        \nnet.ipv4.route.gc_timeout = 100
        \nnet.ipv4.tcp_syn_retries = 1
        \nnet.ipv4.tcp_synack_retries = 1
        \nnet.core.netdev_max_backlog = 16384
        \nnet.ipv4.tcp_max_orphans = 16384
        \nnet.ipv4.tcp_fin_timeout = 2
        \net.core.somaxconn=32768
        \nkernel.threads-max=196605
        \nkernel.pid_max=196605
        \nvm.max_map_count=393210"  >> /etc/sysctl.conf
    else
        info "kernel already installed."
    fi
    ansible all -m copy -a "src=https://www.cnblogs.com/etc/sysctl.conf dest=/etc/sysctl.conf"
    info "setting kernel done."
    echo
}

function set_maxfiles {
    curr=`ulimit -a`
    info "current max files: $curr \n 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=https://www.cnblogs.com/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: \n$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=https://www.cnblogs.com/shun57/p/$install_path/mysql-connector-java.jar dest=/usr/share/java/"
        ansible_copy "src=https://www.cnblogs.com/shun57/p/$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\n"; exp_continue}
    "*New password*" { send "$new_passwd\n" ; exp_continue}
    "*Re-enter new password*" { send "$new_passwd\n"; exp_continue}
    "*Do you wish to continue with the password provided*" { send "y\n"; exp_continue}
    "*Change the password for root*" { send "y\n"; exp_continue}
    "*Remove anonymous users*" { send "y\n"; exp_continue}
    "*Disallow root login remotely*" { send "\n"; exp_continue}
    "*Remove test database and access to it*" { send "y\n"; exp_continue}
    "*Reload privilege tables now*" { send "y\n"; exp_continue}
    "*Enter SCM password*" { send "$new_passwd\n"; exp_continue}
    "*#" { return 0}
  }
  return 1
}

proc connect {passwd} {
   expect {
       "(yes/no)?" {
           send "yes\n"
           expect "*password:" {
                send "$passwd\n"
                expect {
                    "*#" {
                        return 0
                    }
                }
           }
       }
       "*'s password:" {
           send "$passwd\n"
           expect {
                "Overwrite (y/n)" {
                    send "y\n"
                    exp_continue
                }
                "*file in which to save the key*" {
                    send "\n"
                    exp_continue
                }
                "*Enter passphrase*" {
                    send "\n"
                    exp_continue
                }
                "*Enter same passphrase again*" {
                    send "\n"
                    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

運行結果

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/472314.html

標籤:大數據

上一篇:創建計算重復行的重復欄位

下一篇:大資料Hadoop之——Flink中的Window API+時間語意+Watermark

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • GPU虛擬機創建時間深度優化

    **?桔妹導讀:**GPU虛擬機實體創建速度慢是公有云面臨的普遍問題,由于通常情況下創建虛擬機屬于低頻操作而未引起業界的重視,實際生產中還是存在對GPU實體創建時間有苛刻要求的業務場景。本文將介紹滴滴云在解決該問題時的思路、方法、并展示最終的優化成果。 從公有云服務商那里購買過虛擬主機的資深用戶,一 ......

    uj5u.com 2020-09-10 06:09:13 more
  • 可編程網卡芯片在滴滴云網路的應用實踐

    **?桔妹導讀:**隨著云規模不斷擴大以及業務層面對延遲、帶寬的要求越來越高,采用DPDK 加速網路報文處理的方式在橫向縱向擴展都出現了局限性。可編程芯片成為業界熱點。本文主要講述了可編程網卡芯片在滴滴云網路中的應用實踐,遇到的問題、帶來的收益以及開源社區貢獻。 #1. 資料中心面臨的問題 隨著滴滴 ......

    uj5u.com 2020-09-10 06:10:21 more
  • 滴滴資料通道服務演進之路

    **?桔妹導讀:**滴滴資料通道引擎承載著全公司的資料同步,為下游實時和離線場景提供了必不可少的源資料。隨著任務量的不斷增加,資料通道的整體架構也隨之發生改變。本文介紹了滴滴資料通道的發展歷程,遇到的問題以及今后的規劃。 #1. 背景 資料,對于任何一家互聯網公司來說都是非常重要的資產,公司的大資料 ......

    uj5u.com 2020-09-10 06:11:05 more
  • 滴滴AI Labs斬獲國際機器翻譯大賽中譯英方向世界第三

    **桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......

    uj5u.com 2020-09-10 06:11:29 more
  • MPP (Massively Parallel Processing)大規模并行處理

    1、什么是mpp? MPP (Massively Parallel Processing),即大規模并行處理,在資料庫非共享集群中,每個節點都有獨立的磁盤存盤系統和記憶體系統,業務資料根據資料庫模型和應用特點劃分到各個節點上,每臺資料節點通過專用網路或者商業通用網路互相連接,彼此協同計算,作為整體提供 ......

    uj5u.com 2020-09-10 06:11:41 more
  • 滴滴資料倉庫指標體系建設實踐

    **桔妹導讀:**指標體系是什么?如何使用OSM模型和AARRR模型搭建指標體系?如何統一流程、規范化、工具化管理指標體系?本文會對建設的方法論結合滴滴資料指標體系建設實踐進行解答分析。 #1. 什么是指標體系 ##1.1 指標體系定義 指標體系是將零散單點的具有相互聯系的指標,系統化的組織起來,通 ......

    uj5u.com 2020-09-10 06:12:52 more
  • 單表千萬行資料庫 LIKE 搜索優化手記

    我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......

    uj5u.com 2020-09-10 06:13:25 more
  • 滴滴Ceph分布式存盤系統優化之鎖優化

    **桔妹導讀:**Ceph是國際知名的開源分布式存盤系統,在工業界和學術界都有著重要的影響。Ceph的架構和演算法設計發表在國際系統領域頂級會議OSDI、SOSP、SC等上。Ceph社區得到Red Hat、SUSE、Intel等大公司的大力支持。Ceph是國際云計算領域應用最廣泛的開源分布式存盤系統, ......

    uj5u.com 2020-09-10 06:14:51 more
  • es~通過ElasticsearchTemplate進行聚合~嵌套聚合

    之前寫過《es~通過ElasticsearchTemplate進行聚合操作》的文章,這一次主要寫一個嵌套的聚合,例如先對sex集合,再對desc聚合,最后再對age求和,共三層嵌套。 Aggregations的部分特性類似于SQL語言中的group by,avg,sum等函式,Aggregation ......

    uj5u.com 2020-09-10 06:14:59 more
  • 爬蟲日志監控 -- Elastc Stack(ELK)部署

    傻瓜式部署,只需替換IP與用戶 導讀: 現ELK四大組件分別為:Elasticsearch(核心)、logstash(處理)、filebeat(采集)、kibana(可視化) 下載均在https://www.elastic.co/cn/downloads/下tar包,各組件版本最好一致,配合fdm會 ......

    uj5u.com 2020-09-10 06:15:05 more
最新发布
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:33:24 more
  • MySQL中binlog備份腳本分享

    關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......

    uj5u.com 2023-04-20 08:28:06 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:27:27 more
  • 快取與資料庫雙寫一致性幾種策略分析

    本文將對幾種快取與資料庫保證資料一致性的使用方式進行分析。為保證高并發性能,以下分析場景不考慮執行的原子性及加鎖等強一致性要求的場景,僅追求最終一致性。 ......

    uj5u.com 2023-04-20 08:26:48 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:26:35 more
  • 云時代,MySQL到ClickHouse資料同步產品對比推薦

    ClickHouse 在執行分析查詢時的速度優勢很好的彌補了MySQL的不足,但是對于很多開發者和DBA來說,如何將MySQL穩定、高效、簡單的同步到 ClickHouse 卻很困難。本文對比了 NineData、MaterializeMySQL(ClickHouse自帶)、Bifrost 三款產品... ......

    uj5u.com 2023-04-20 08:26:29 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:25:13 more
  • Redis 報”OutOfDirectMemoryError“(堆外記憶體溢位)

    Redis 報錯“OutOfDirectMemoryError(堆外記憶體溢位) ”問題如下: 一、報錯資訊: 使用 Redis 的業務介面 ,產生 OutOfDirectMemoryError(堆外記憶體溢位),如圖: 格式化后的報錯資訊: { "timestamp": "2023-04-17 22: ......

    uj5u.com 2023-04-20 08:24:54 more
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:24:03 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:23:11 more