Rhel automatic installation of zookeeper shell scripts

Source: Internet
Author: User
Tags zookeeper

Rhel automatic installation of zookeeper shell scripts


A: This script runs the machine, Linux RHEL6

B,c,d,... : Machine to be installed zookeeper cluster, Linux RHEL6


First, on machine A that the script runs, determine that you can log on to the machine b,c,d to install ZK without password ssh,... , then you can run this script on a:

$./install_zookeeper

Premise:

B, C, D machine must be configured well 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 Di Stribution 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 will automatically install the zookeeper on the B,c,d machine and configure the relevant configuration file. But did not start them. Support for 1,3,5,7 servers.

#!/bin/bash## @file # install_zookeeper.sh## @date # 2014-12-21## @author # [email protected]## @version # 0.0.1p re## @usage #./install_zookeeper.sh############################################################################# ####***********************************************************# split_to_array# split string into array#**********    function Split_to_array () {old_ifs= "$IFS" ifs= "$ array=" ($) ifs= "$OLD _ifs"}#***********************************************************# install_zookeeper# Install Zookeeper On 1, 3 or 5 servers## parameters:# clientport-the ports at which the clients would connect to# servers-varying Argu Ments:1, 3, 5, up to 7# "ZkServer:serverPort:appPort" # Zkserver-ipaddr of Zookeeper server# Serverport-co Mmunication port for Zookeeper servers# appport-communication ports between zookeeper with other applications## Examp le:# 1) install_zookeeper 2181 zk1 ZK2zk3# 2) install_zookeeper 2181 192.168.122.201 192.168.122.202 192.168.122.203# 3) install_zookeeper "2181" "192.168.1 22.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 AP Pport destip destlogin serverport=2888 appport=3888 # parse the first argument Split_to_array $ ":" # The Port at which the clients would connect Clientport=${array[0]} # The directory where the snapshot is stored Datadi R= "/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 Zoo    Keeper servers: [$ARGC] "Exit $ERR _invalid_zk_servers; Fi local argv= "[email protected]" old_ifs= "$IFS" ifs= "" Local args= ($ARGV) ifs= "$OLD _ifs" # array Variable local ipaddrs= () local servers= () local sid=0 for a in ${args[@]} does let sid++ # che CK 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] does let sid=i+1 destip=${ipaddrs[$i]} [Email prot  Ected] $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 ' #!  {{[email protected]==> ' >> $ZOO _cfg "' for S in ${servers[*]} do ret= ' ssh $destlogin "Echo ' $s ' >> $ZOO _cfg" ' Done ret= ' ssh $destlogin "Echo ' #!<[email protected]}} ' >> $ZO        O_cfg "' Echo-e" OK. " Let i++ do 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 zk-cluster machine and start the zookeeper:

$/usr/lib/zookeeper/bin/zkserver.sh Start-foreground


Rhel automatic installation of zookeeper shell scripts

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.