CentOS 7에 Zookeeper 설치하기
설치 및 셋팅 2016. 8. 9. 12:16
설치
주키퍼 설치
1 2 3 4 5 | $ wget http: //apache .mirror.cdnetworks.com /zookeeper/stable/zookeeper-3 .4.9. tar .gz $ tar zxvf zookeeper-3.4.9. tar .gz $ mv zookeeper-3.4.9 /usr/share/ $ cd /usr/share/ $ ln -s zookeeper-3.4.9 zookeeper |
주키퍼 데이터 폴더 생성
1 | $ mkdir -p /home/data/zookeeper |
주키퍼 설정
zoo_sample.cfg를 zoo.cfg 이름으로 복사 후, dataDir 설정하고, server 추가
1 2 3 | $ cd zookeeper /conf $ cp zoo_sample.cfg zoo.cfg $ vi zoo.cfg |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # 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=192.168.199.128:2888:3888 server.2=192.168.199.129:2888:3888 server.3=192.168.199.130:2888:3888 |
각 서버의 주키퍼 데이터 폴더에 myid 파일을 생성해 고유 아이디값 저장
1 2 3 4 5 6 7 8 9 | # 192.168.199.128 $ vi /home/data/zookeeper/myid 1 # 192.168.199.129 $ vi /home/data/zookeeper/myid 2 # 192.168.199.130 $ vi /home/data/zookeeper/myid 3 |
부팅시 자동으로 실행하도록 서비스 등록
1 2 | $ cd /etc/init .d $ vi zookeeper-server |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #!/bin/sh # # chkconfig: - 80 05 # description: zookeeper server # BIN_PATH= /usr/share/zookeeper/bin case $1 in start) ${BIN_PATH} /zkServer .sh start ;; stop) ${BIN_PATH} /zkServer .sh stop;; status) ${BIN_PATH} /zkServer .sh status;; restart) ${BIN_PATH} /zkServer .sh restart;; *) echo "require start|stop|status|restart" ;; esac |
1 2 3 | $ chmod +x zookeeper-server $ chkconfig --add zookeeper-server $ chkconfig zookeeper-server on |
켜고 끄고 해보기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $ service zookeeper-server start ZooKeeper JMX enabled by default Using config: /usr/share/zookeeper/bin/ .. /conf/zoo .cfg Starting zookeeper ... STARTED $ service zookeeper-server status ZooKeeper JMX enabled by default Using config: /usr/share/zookeeper/bin/ .. /conf/zoo .cfg Mode: leader $ service zookeeper-server stop ZooKeeper JMX enabled by default Using config: /usr/share/zookeeper/bin/ .. /conf/zoo .cfg Stopping zookeeper ... STOPPED |
노드를 생성하고 조회하고 지워보기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | $ cd /usr/share/zookeeper $ bin /zkCli .sh -server 192.168.199.128:2181 # /zk_test 노드 생성하고, 그 노드에 my_data라는 데이터 넣기 [zk: 192.168.199.128:2181(CONNECTED) 0]create /zk_test my_data Created /zk_test # 조회 [zk: 192.168.199.128:2181(CONNECTED) 1] ls / [zookeeper, zk_test] # 노드 데이터 얻기 [zk: 192.168.199.128:2181(CONNECTED) 2] get /zk_test my_data cZxid = 0x10 ctime = Wed Aug 10 00:05:03 KST 2016 mZxid = 0x10 mtime = Wed Aug 10 00:05:03 KST 2016 pZxid = 0x10 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0 # 노드 데이터 설정 [zk: 192.168.199.128:2181(CONNECTED) 3] set /zk_test hello cZxid = 0x10 ctime = Wed Aug 10 00:05:03 KST 2016 mZxid = 0x11 mtime = Wed Aug 10 00:05:36 KST 2016 pZxid = 0x10 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 5 numChildren = 0 # 노드 지우기 [zk: 192.168.199.128:2181(CONNECTED) 4] delete /zk_test [zk: 192.168.199.128:2181(CONNECTED) 5] ls / [zookeeper] |