TagCloud

Friday, November 2, 2012

Apache ZooKeeper


Apache ZooKeeper

- ZooKeeper is a high-performance coordination service for distributed applications.

ZooKeeper 는 분산어플리케이션을 위한 고성능 조정서비스 입니다.



ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them ,which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.

분산환경에서 운영되는 서비스들을 유지보수 할 때, 중앙관리를 위한 서비스를 제공하는것이 Zookeeper  의 목적인것 같음. Hadoop 과 같은 수많은 시스템으로 구성된 분산환경에서, 버그를 수정한다던지 설정을 초기화해야 한다던지의 업무를 해야 한다면 많은 노력이 필요할 것이다. 이때 이러한 역할을 중앙에서 관리할 수 있다면 해서 시작된것이 프로젝트의 시작인것 같음. 아무튼 분산환경에 배포된 어플리케이션을 관리하기가 어려운 점을 보완하기 위한 서비스를 제공하는것이 ZooKeeper 이라 이해됨.



CentOS 6.3 을 기준으로 ZooKeeper 3.4.4 설치 및 테스트(Single Node)를 진행함


# 1. 소스 다운로드 및 압축 해제
[luvu@vm srv]$ wget http://apache.mirror.cdnetworks.com/zookeeper/zookeeper-3.4.4/zookeeper-3.4.4.tar.gz
[luvu@vm srv]$ tar -xvf ./zookeeper-3.4.4.tar.gz
[luvu@vm srv]$ mv zookeeper-3.4.4.tar.gz zookeeper
# 2. 설정파일 복사 및 작성
[luvu@vm zookeeper]$ vi cp conf/zoo_sample.cfg zoo.cfg
[luvu@vm zookeeper]$ vi conf/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=/srv/zookeeper/data
# the port at which the clients will connect
clientPort=2181
#
# 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

# 3. 서버 실행
[luvu@vm zookeeper]$ bin/zkServer.sh start

JMX enabled by default
Using config: /srv/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

# 4. 방화벽 포트 해제 및 클라이언트 실행
[luvu@vm zookeeper]$ iptables -I INPUT -p tcp --dport 2181 -j ACCEPT
[luvu@vm zookeeper]$ service iptables save
[luvu@vm zookeeper]$ service iptables restart
[luvu@vm zookeeper]$ bin/zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2012-11-02 20:00:54,914 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.4-1386507, built on 09/17/2012 08:33 GMT
2012-11-02 20:00:54,916 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=localhost
2012-11-02 20:00:54,916 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.6.0_35
2012-11-02 20:00:54,919 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Sun Microsystems Inc.
2012-11-02 20:00:54,919 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/local/lib64/jdk1.6.0_35/jre
2012-11-02 20:00:54,920 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/srv/zookeeper/bin/../build/classes:/srv/zookeeper/bin/../build/lib/*.jar:/srv/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/srv/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/srv/zookeeper/bin/../lib/netty-3.2.2.Final.jar:/srv/zookeeper/bin/../lib/log4j-1.2.15.jar:/srv/zookeeper/bin/../lib/jline-0.9.94.jar:/srv/zookeeper/bin/../zookeeper-3.4.4.jar:/srv/zookeeper/bin/../src/java/lib/*.jar:/srv/zookeeper/bin/../conf:/usr/local/lib64/jdk1.6.0_35/jre/ext:/usr/local/lib64/jdk1.6.0_35/lib/tools.jar
2012-11-02 20:00:54,920 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/local/lib64/jdk1.6.0_35/jre/lib/amd64/server:/usr/local/lib64/jdk1.6.0_35/jre/lib/amd64:/usr/local/lib64/jdk1.6.0_35/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-11-02 20:00:54,921 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2012-11-02 20:00:54,922 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=
2012-11-02 20:00:54,922 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2012-11-02 20:00:54,922 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2012-11-02 20:00:54,923 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=2.6.32-279.9.1.el6.x86_64
2012-11-02 20:00:54,923 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=luvu
2012-11-02 20:00:54,923 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/luvu
2012-11-02 20:00:54,931 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/srv/zookeeper-3.4.4
2012-11-02 20:00:54,932 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@66edc3a2
Welcome to ZooKeeper!

# 5. 도움말
[zk: 127.0.0.1:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
 connect host:port
 get path [watch]
 ls path [watch]
 set path data [version]
 rmr path
 delquota [-n|-b] path
 quit 
 printwatches on|off
 create [-s] [-e] path data acl
 stat path [watch]
 close 
 ls2 path [watch]
 history 
 listquota path
 setAcl path acl
 getAcl path
 sync path
 redo cmdno
 addauth scheme auth
 delete path [version]
 setquota -n|-b val path
[zk: 127.0.0.1:2181(CONNECTED) 1] 
# 6. ls 커맨드 
[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[zookeeper]
# 7. 새로운 znode 생성 및 myTest String 생성
[zk: 127.0.0.1:2181(CONNECTED) 2] create /playforum_test myTest
Created /playforum_test
[zk: 127.0.0.1:2181(CONNECTED) 3] ls /
[playforum_test, zookeeper]
# 8. playforum_test znode 데이터 확인
[zk: 127.0.0.1:2181(CONNECTED) 4] get /playforum_test
myTest
cZxid = 0x13
ctime = Fri Nov 02 20:03:55 KST 2012
mZxid = 0x13
mtime = Fri Nov 02 20:03:55 KST 2012
pZxid = 0x13
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0
# 9. 데이터 변경
[zk: 127.0.0.1:2181(CONNECTED) 5] set /playforum_test junk
cZxid = 0x13
ctime = Fri Nov 02 20:03:55 KST 2012
mZxid = 0x14
mtime = Fri Nov 02 20:04:20 KST 2012
pZxid = 0x13
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
# 10. 데이터 삭제
[zk: 127.0.0.1:2181(CONNECTED) 6] delete /playforum_test
[zk: 127.0.0.1:2181(CONNECTED) 7] ls /
[zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 8] 



참고사항
1. JDK 1.7.X 에서 session timed out 오류가 있었음
-> JDK 1.6.X 로 변경시 정상동작 확인


참고문서
http://zookeeper.apache.org
https://cwiki.apache.org/confluence/display/ZOOKEEPER/Index
http://www.mimul.com/pebble/default/2010/12/30/1293709016460.html
http://www.xenomity.com/112
http://bench87.tistory.com/228
http://ir.bagesoft.com/664