安装jdk
http://www.cnblogs.com/xiaojf/p/6568426.html
[root@m1 jar]# tar zxvf zookeeper-3.4.9.tar.gz -C ../
[root@m1 jar]# cd .. [root@m1 soft]# ll total 16 drwxr-xr-x. 2 root root 4096 Mar 17 18:18 jar drwxr-xr-x. 8 uucp 143 4096 Dec 12 16:50 jdk drwxrwxr-x. 6 1001 1001 4096 Mar 4 2016 scala-2.11.8 drwxr-xr-x. 10 1001 1001 4096 Aug 23 2016 zookeeper-3.4.9 [root@m1 soft]# cd zookeeper-3.4.9/ [root@m1 zookeeper-3.4.9]# ll total 1592 drwxr-xr-x. 2 1001 1001 4096 Aug 23 2016 bin -rw-rw-r--. 1 1001 1001 83539 Aug 23 2016 build.xml -rw-rw-r--. 1 1001 1001 90824 Aug 23 2016 CHANGES.txt drwxr-xr-x. 2 1001 1001 4096 Aug 23 2016 conf drwxr-xr-x. 10 1001 1001 4096 Aug 23 2016 contrib drwxr-xr-x. 2 1001 1001 4096 Aug 23 2016 dist-maven drwxr-xr-x. 6 1001 1001 4096 Aug 23 2016 docs -rw-rw-r--. 1 1001 1001 1953 Aug 23 2016 ivysettings.xml -rw-rw-r--. 1 1001 1001 3499 Aug 23 2016 ivy.xml drwxr-xr-x. 4 1001 1001 4096 Aug 23 2016 lib -rw-rw-r--. 1 1001 1001 11938 Aug 23 2016 LICENSE.txt -rw-rw-r--. 1 1001 1001 171 Aug 23 2016 NOTICE.txt -rw-rw-r--. 1 1001 1001 1770 Aug 23 2016 README_packaging.txt -rw-rw-r--. 1 1001 1001 1585 Aug 23 2016 README.txt drwxr-xr-x. 5 1001 1001 4096 Aug 23 2016 recipes drwxr-xr-x. 8 1001 1001 4096 Aug 23 2016 src -rw-rw-r--. 1 1001 1001 1368238 Aug 23 2016 zookeeper-3.4.9.jar -rw-rw-r--. 1 1001 1001 819 Aug 23 2016 zookeeper-3.4.9.jar.asc -rw-rw-r--. 1 1001 1001 33 Aug 23 2016 zookeeper-3.4.9.jar.md5 -rw-rw-r--. 1 1001 1001 41 Aug 23 2016 zookeeper-3.4.9.jar.sha1
[root@m1 zookeeper-3.4.9]# cd conf/ [root@m1 conf]# ll total 12 -rw-rw-r--. 1 1001 1001 535 Aug 23 2016 configuration.xsl -rw-rw-r--. 1 1001 1001 2161 Aug 23 2016 log4j.properties -rw-rw-r--. 1 1001 1001 922 Aug 23 2016 zoo_sample.cfg [root@m1 conf]# cp zoo_sample.cfg zoo.cfg
[root@m1 conf]# vi zoo.cfg
[root@m1 conf]# cat 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=/usr/local/soft/tmp/zookeeper/data dataLogDir=/usr/local/soft/tmp/zookeeper/log # 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 #2888,3888 are election port server.1=m1:2888:3888 server.2=s1:2888:3888 server.3=s2:2888:3888
创建目录
/usr/local/soft/tmp/zookeeper/data
/usr/local/soft/tmp/zookeeper/log
[root@m1 conf]# mkdir -p /usr/local/soft/tmp/zookeeper/log [root@m1 conf]# mkdir -p /usr/local/soft/tmp/zookeeper/data
关闭防火墙
[root@m1 zookeeper-3.4.9]# chkconfig iptables off [root@m1 zookeeper-3.4.9]# chkconfig iptables --list iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@m1 data]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@m1 data]# service iptables status
iptables: Firewall is not running.
复制文件到其他机器
[root@m1 soft]# scp -r ./zookeeper-3.4.9 root@s1:/usr/local/soft/ [root@m1 soft]# scp -r ./zookeeper-3.4.9 root@s2:/usr/local/soft/
分别创建对应服务id的myid文件
[root@m1 soft]# cd tmp/zookeeper/data/ [root@m1 data]# pwd /usr/local/soft/tmp/zookeeper/data [root@m1 data]# echo "1" >> ./myid
分别设置环境变量
[root@m1 data]# vi /etc/profile
export ZOOKEEPER_HOME=/usr/local/soft/zookeeper-3.4.9 export PATH=$PATH:$ZOOKEEPER_HOME/bin
[root@m1 data]# source /etc/profile
启动
[root@m1 data]# zkServer.sh start ZooKeeper JMX enabled by default Using config: /usr/local/soft/zookeeper-3.4.9/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@m1 data]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/soft/zookeeper-3.4.9/bin/../conf/zoo.cfg Error contacting service. It is probably not running. [root@m1 data]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/soft/zookeeper-3.4.9/bin/../conf/zoo.cfg Mode: follower
查看集群状态
[root@m1 data]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/soft/zookeeper-3.4.9/bin/../conf/zoo.cfg Mode: follower
完成