1、解压zookeeper
[root@localhost soft]# ls jdk1.7.0_80 jdk-7u80-linux-i586.tar.gz zookeeper-3.4.11 zookeeper-3.4.11.tar.gz [root@localhost soft]# tar -zxvf zookeeper-3.4.11.tar.gz
2、将zookeeper拷贝到/usr/zookeeper目录下,复制三份
[root@localhost soft]# cp -r ./zookeeper-3.4.11 /usr/zookeeper/zookeeper1 [root@localhost soft]# cp -r ./zookeeper-3.4.11 /usr/zookeeper/zookeeper2 [root@localhost soft]# cp -r ./zookeeper-3.4.11 /usr/zookeeper/zookeeper3
3、目录结构:
[root@localhost zookeeper]# pwd /usr/zookeeper [root@localhost zookeeper]# ls zookeeper1 zookeeper2 zookeeper3 [root@localhost zookeeper]#
4、新建data文件夹,再在data文件夹下创建文件myid,内容为1
[root@localhost data]# pwd /usr/zookeeper/zookeeper1/data [root@localhost data]# ls myid version-2 zookeeper_server.pid [root@localhost data]#
zookeeper1下的myid为1,zookeeper2下的myid为2,zookeeper3下的myid为3
[root@localhost data]# echo 1 >myid [root@localhost data]# cat myid 1 [root@localhost data]#
5、修改conf 文件夹下zoo_sample.cfg文件名为 zoo.cfg,修改其中的内容:
zookeeper1:
dataDir=/usr/zookeeper/zookeeper1/data
clientPort=2181
server.1=192.168.178.128:2881:3881
server.2=192.168.178.128:2882:3882
server.3=192.168.178.128:2883:3883
zookeeper2:
dataDir=/usr/zookeeper/zookeeper2/data
clientPort=2182
server.1=192.168.178.128:2881:3881
server.2=192.168.178.128:2882:3882
server.3=192.168.178.128:2883:3883
zookeeper3:
dataDir=/usr/zookeeper/zookeeper3/data
clientPort=2183
server.1=192.168.178.128:2881:3881
server.2=192.168.178.128:2882:3882
server.3=192.168.178.128:2883:3883
[root@localhost conf]# pwd /usr/zookeeper/zookeeper1/conf [root@localhost conf]# ls configuration.xsl log4j.properties zoo.cfg [root@localhost conf]# [root@localhost 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/zookeeper/zookeeper1/data # 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.178.128:2881:3881 server.2=192.168.178.128:2882:3882 server.3=192.168.178.128:2883:3883 [root@localhost conf]#
6、启动zookeeper
[root@localhost bin]# /usr/zookeeper/zookeeper1/bin/zkServer.sh start [root@localhost bin]# /usr/zookeeper/zookeeper2/bin/zkServer.sh start [root@localhost bin]# /usr/zookeeper/zookeeper3/bin/zkServer.sh start
7、查看zookeeper状态
[root@localhost bin]# /usr/zookeeper/zookeeper1/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/zookeeper/zookeeper1/bin/../conf/zoo.cfg Mode: follower [root@localhost bin]# /usr/zookeeper/zookeeper2/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/zookeeper/zookeeper2/bin/../conf/zoo.cfg Mode: follower [root@localhost bin]# /usr/zookeeper/zookeeper3/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/zookeeper/zookeeper3/bin/../conf/zoo.cfg Mode: leader [root@localhost bin]#
8、需要开启对应的端口或者把服务器的防火墙关掉,关掉防火墙命令:
[root@localhost bin]# service iptables stop [root@localhost bin]#