RHEL automatically installs the zookeeper shell script, rhelzookeeper

Source: Internet
Author: User

RHEL automatically installs the zookeeper shell script, rhelzookeeper
RHEL automatically installs the zookeeper shell script


A: This script runs on Linux RHEL6.

B, C, D,...: The machine on which zookeeper cluster is to be installed, Linux RHEL6


First, you can log on to machine B, C, D, and ,... and then you can run the script on:

$ ./install_zookeeper

Prerequisites:

B, C, D machine must be configured with repo, this script uses cdh5 repo, the following content is saved to:/etc/yum. repos. d/cloudera-cdh5.repo:

[cloudera-cdh5]# Packages for Cloudera's Distribution for Hadoop, Version 5, on RedHator CentOS 6 x86_64name=Cloudera's Distribution for Hadoop, Version 5baseurl=http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/gpgkey = http://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/RPM-GPG-KEY-cloudera    gpgcheck = 1enabled  = 1

The automatic installation script automatically installs zookeeper on machines B, C, and D and configures the relevant configuration files. But they are not started. Supports 1, 3, 5, and 7 servers.

#!/bin/bash## @file#   install_zookeeper.sh## @date#   2014-12-21## @author#   cheungmine@hgdb.net## @version#   0.0.1pre## @usage#   ./install_zookeeper.sh#################################################################################***********************************************************# split_to_array#   split string into array#***********************************************************function split_to_array() {    OLD_IFS="$IFS"    IFS="$2"    array=($1)    IFS="$OLD_IFS"}#***********************************************************# install_zookeeper#   install zookeeper on 1, 3 or 5 servers## Parameters:#   clientPort - the port at which the clients will connect to#   servers - varying arguments: 1, 3, 5, up to 7#     "zkServer:serverPort:appPort"#     zkServer - ipaddr of zookeeper server#     serverPort - communication port for zookeeper servers#     appPort - communication port between zookeeper with other applications## Example:#   1) install_zookeeper 2181 zk1 zk2 zk3#   2) install_zookeeper 2181 192.168.122.201 192.168.122.202 192.168.122.203#   3) install_zookeeper "2181" "192.168.122.201:2888:3888" "192.168.122.202:2888:3888" "192.168.122.203:2888:3888"#   4) install_zookeeper "2181:/var/lib/zookeeper" "192.168.122.201:2888:3888" "192.168.122.202:2888:3888" "192.168.122.203:2888:3888"#***********************************************************ERR_INVALID_ZK_SERVERS=1001function install_zookeeper() {    echo -e "<INFO> install zookeeper on cluster ..."    #chk_root    local ret clientPort dataDir len i ZOO_CFG server serverPort appPort destip destlogin    serverPort=2888    appPort=3888    # parse the first argument    split_to_array $1 ":"    # the port at which the clients will connect    clientPort=${array[0]}    # the directory where the snapshot is stored    dataDir="/var/lib/zookeeper"    if [ ${#array[*]} -eq 2 ]; then        dataDir=${array[1]}    fi    echo -e "<INFO> clientPort: $clientPort"    echo -e "<INFO> dataDir: $dataDir"    # zookeeper configure file    ZOO_CFG="/usr/lib/zookeeper/conf/zoo.cfg"    # get list of servers: args    shift    local argc=$#    if [ $argc -eq 1 -o $argc -eq 3 -o $argc -eq 5 -o $argc -eq 7 ]; then        echo -e "<INFO> zookeeper servers in cluster: [$argc]"    else        echo -e "<ERROR> invalid zookeeper servers: [$argc]"        exit $ERR_INVALID_ZK_SERVERS;    fi    local argv="$@"    OLD_IFS="$IFS"    IFS=" "    local args=($argv)    IFS="$OLD_IFS"    # array variable    local ipaddrs=()    local servers=()    local sid=0    for a in ${args[@]}    do        let sid++        # check if server format is either of:        #   serverIP        # or:        #   serverIP:serverPort:appPort        split_to_array $a ":"        serverIP=${array[0]}        if [ ${#array[*]} -ne 3 ]; then            a="$serverIP:$serverPort:$appPort";        fi        local server="server.$sid=$a"        servers[sid-1]=$server        echo $server        ipaddrs[sid-1]=$serverIP    done    # output array to one line string: echo ${servers[@]}    # get length of array    len=${#servers[*]}    i=0    while [ $i -lt $len ]    do        let sid=i+1        destip=${ipaddrs[$i]}        destlogin=root@$destip        echo -e "<INFO> configuring server.$sid: $destip ...\c"        ret=`ssh $destlogin "yum install -y zookeeper zookeeper-server && service zookeeper-server init --myid=$sid"`        ret=`ssh $destlogin "echo '#!{{install_zookeeper@hgdb.net==>' >> $ZOO_CFG"`        for s in ${servers[*]}        do            ret=`ssh $destlogin "echo '$s' >> $ZOO_CFG"`        done        ret=`ssh $destlogin "echo '#!<==install_zookeeper@hgdb.net}}' >> $ZOO_CFG"`        echo -e "OK."        let i++    done    echo "<INFO> zookeeper cluster installation completed successfully!"}#=======================================================================install_zookeeper "2181" "192.168.122.201" "192.168.122.202" "192.168.122.203"

Modify the last line according to the Configuration:

Install_zookeeper "2181" "192.168.122.201" "192.168.122.202" "192.168.122.203"

Note: You need to stop the firewall on each machine in zk-cluster and then start zookeeper:

$/Usr/lib/zookeeper/bin/zkServer. sh start-foreground


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.