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 RedHat or CentOS 6 x86_64
Name = Cloudera's Distribution for Hadoop, Version 5
Base url = 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 = 1
Enabled = 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
# 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 = 1001
Function 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:
# ServerIP
# Or:
# ServerIP: serverPort: appPort
Split_to_array $ ":"
ServerIP =$ {array [0]}
If [$ {# array [*]}-ne 3]; then
A = "$ serverIP: $ serverPort: $ appPort ";
Fi
Local server = "server. $ sid = $"
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> processing ing server. $ sid: $ destip... \ c"
Ret = 'ssh $ destlogin "yum install-y 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
-------------------------------------- Split line --------------------------------------
ZooKeeper cluster configuration
Use ZooKeeper to implement distributed shared locks
Distributed service framework ZooKeeper-manage data in a distributed environment
Build a ZooKeeper Cluster Environment
Test Environment configuration of ZooKeeper server cluster
ZooKeeper cluster Installation
-------------------------------------- Split line --------------------------------------
This article permanently updates the link address: