Zookeeper 설치

■ Zookeeper를 아래의 3대의 Linux CentOS7이 설치된 서버에 설치하고자 한다. 각 서버의 호스트파일(/etc/hosts)에 아래의 정보가 등록되어있다.

[nextman@centos01 etc]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.192.128	centos01
192.168.192.130	centos02
192.168.192.133	centos03
192.168.192.132	centos04
192.168.192.131	centos05
[nextman@centos01 etc]$ 
Zookeeper 설치 대상 서버 정보
Host Name IP
centos01 192.168.192.128
centos02 192.168.192.130
centos03 192.168.192.133

 

■ zookeeper 다운로드 위치
http://zookeeper.apache.org 에서 다운로드
http://apache.mirror.cdnetworks.com/zookeeper/stable/에서 stable 버전의 링크 주소 복사
■ wget으로 zookeeper 다운로드 및 압축풀기, 링크

[nextman@centos01 program]$ wget http://apache.mirror.cdnetworks.com/zookeeper/stable/zookeeper-3.4.8.tar.gz
[nextman@centos01 program]$ tar zxvf zookeeper-3.4.8.tar.gz
[nextman@centos01 program]$ mv zookeeper-3.4.8 /usr/local/
[nextman@centos01 program]$ cd /usr/local/
[nextman@centos01 local]$ ln -s zookeeper-3.4.8/ zookeeper

 

■ zookeeper 데이터 디렉토리 생성 및 zoo.cfg파일 만들기(zoo_sample.cfg파일을 copy해서 생성)

[nextman@centos01 conf]$ mkdir /home/data/zookeeper
[nextman@centos01 local]$ cd zookeeper/conf
[nextman@centos01 conf]$ cp zoo_sample.cfg zoo.cfg

 

■ zoo.cfg 파일 수정 – dataDir, server.1, server.2, server.3 정보 등록
dataDir=/home/data/zookeeper
server.1=centos01:2888:3888
server.2=centos02:2888:3888
server.3=centos03:2888:3888

[nextman@centos01 conf]$ vi zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/data/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

server.1=centos01:2888:3888
server.2=centos02:2888:3888
server.3=centos03:2888:3888

 

■ 각 서버에 myid파일 생성 – myid 파일은 반드시 zoo.cfg의 dataDir디렉토리(/home/data/zookeeper)에 있어야 함.
# centos01서버의 /home/data/zookeeper/myid 파일에 ‘1’ 저장
# centos02서버의 /home/data/zookeeper/myid 파일에 ‘2’ 저장
# centos03서버의 /home/data/zookeeper/myid 파일에 ‘3’ 저장

[nextman@centos01 conf]$ vi /home/data/zookeeper/myid
1
:wq
[nextman@centos02 conf]$ vi /home/data/zookeeper/myid
2
:wq
[nextman@centos03 conf]$ vi /home/data/zookeeper/myid
3
:wq

 

■ zookeeper 환경변수 추가

[nextman@centos01 conf]$ vi ~/.bash_profile
export JAVA_HOME=/usr/local/java
export TOMCAT_HOME=/usr/local/tomcat
export MAVEN_HOME=/usr/local/maven
export HADOOP_HOME=/usr/local/hadoop
export ZOOKEEPER_HOME=/usr/local/zookeeper

PATH=$ZOOKEEPER_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$MAVEN_HOME/bin:$TOMCAT_HOME/bin:$JAVA_HOME/bin:$PATH:$HOME/.local/bin:$HOME/bin

 

■ zookeeper 시작 – 각 서버( centos01, centos02, centos03 )에서 zkServer.sh start 스크립트 명령어로 각각 실행한다.

[nextman@centos01 conf]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[nextman@centos02 conf]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[nextman@centos03 conf]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

 

■ zookeeper 실행확인 – zookeeper를 실행하면 실행한 디렉토리에 zookeeper.out라는 이름의 로그파일이 생성된다. 에러 로그가 있는지 확인하자. 그리고 아래와 같이 jps명령어로 zookeeper 데몬이 떠 있는지 확인할 수 있다. QuorumPeerMain이 zookeeper 데몬명이고 숫자는 Process ID인데 kill 명령어로 zookeeper 데몬을 내릴 수 있다. 물론 정상적인 경우에는 zkServer.sh stop 명령어로 zookeeper 데몬을 내려야 한다.

[nextman@centos03 ~]$ jps
2111 QuorumPeerMain
2138 Jps
[nextman@centos03 ~]$ kill 2111
[nextman@centos03 ~]$ jps
2151 Jps
[nextman@centos03 ~]$

 

■ zookeeper 접속 – zkCli.sh 스크립트로 접속할 수 있으며, 접속후 help로 도움말을 확인할 수 있다.

[nextman@centos01 zookeeper]$ zkCli.sh -server centos01:2181
Connecting to centos01:2181
...
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: centos01:2181(CONNECTED) 0] help

 

■ zookeeper 종료 – 각각의 서버에서(centos01, centos02, centos03) zkServer.sh stop 스크립트를 실행해야 한다.

[nextman@centos01 ~]$ zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED