安装
下载地址https://apache.org/dist/zookeeper/
1、解压
tar -zxvf zookeeper-3.4.12.tar.gz
2、更改配置文件
cd conf
mv zoo_sample.cfg zoo.cfg
data目录和logs目录默认是没有的,需要自己预先建立好
vim zoo.cfg
# 存放数据的目录
dataDir=/usr/local/zookeeper-3.4.12/data
# the port at which the clients will connect
clientPort=2181
# 存放日志
dataLogDir=/usr/local/zookeeper-3.4.12/logs
#zookeeper机器列表,server.order这里的Order依据集群的机器个数依次递增
server.1=master:2888:3888
server.2=node1:2888:3888
server.3=node2:2888:3888
3、在data目录新建myid文件
[root@master zookeeper-3.4.12]# cd data/
[root@master data]# vim myid
在myid文件中master写1,node1写2,node2写3,这里的1、2、3要和zoo.cfg中配置的order对应。
4、分发并更改myid
5、测试
在每台机器上依次使用./zkServer.sh start来启动zookeeper服务
待启动完成后使用 ./zkServer.sh status来查看该机器的身份
./zkCli.sh测试客户端,出现如下则为成功
2019-02-25 00:46:41,314 [myid:] - INFO [main:ZooKeeper@441] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@4b85612c
Welcome to ZooKeeper!
2019-02-25 00:46:41,371 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1028] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2019-02-25 00:46:41,555 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@878] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2019-02-25 00:46:41,688 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1302] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x100002e999c0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]