三台机器 ip地址(可以通过修改host指定别名给机器)
10.86.43.164
10.86.43.154
10.93.0.192
三台机器分别执行(建议在home目录下创建对应的目录)
cd /home/q/
sudo mkdir zookeeper
cd zookeeper/
sudo wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.5.2-alpha/zookeeper-3.5.2-alpha.tar.gz
sudo tar -xvf zookeeper-3.5.2-alpha.tar.gz
cd zookeeper-3.5.2-alpha
cd conf/
sudo cp zoo_sample.cfg zoo.cfg
sudo vim 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.
# the port at which the clients will connect
dataDir=/home/q/zookeeper/data
dataLogDir=/home/q/zookeeper/logs
# the port at which the clients will connect
clientPort=4180
server.1=10.86.43.164:2888:3888
server.2=10.86.43.154:2888:3888
server.3=10.93.0.192:2888:3888
# 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
可以指定一些参数 clientPort dataDir 等 dataDir 比较重要 指定后需要在对应的目录下创建myid
保存后
cd /home/q/zookeeper/data
vim myid
创建一个myid文件,里面内容为一个数字,用来标识当前主机,conf/zoo.cfg文件中配置的server.X中X为什么数字,则myid文件中就输入这个数字 10.86.43.164 对应的是1
三台机器分别做此操作
然后启动服务
cd home//q/zookeeper/ zookeeper-3.5.2-alpha/bin/
sudo zkServer.sh start
第一次启动的日志在 对应目录下的logs里面
/home/q/zookeeper/zookeeper-3.5.2-alpha/logs
tail -f zookeeper-root-server-l-webcall5.support.wap.dev.cn0.out
第一台和第二台启动都会报
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:444)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:485)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:513)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:919)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:1087)
属于正常现象
继续启动其他两台即可
验证状态
home/q/zookeeper/zookeeper-3.5.2-alpha/bin]$ sudo ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/q/zookeeper/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 4180. Client address: localhost.
Mode: follower
网友评论