安装解压zookeeper后进入解压后的文件
[root@xuniji zookeeper-3.4.5]# cd conf/
[root@xuniji conf]# ll
鎬荤敤閲16
-rw-r--r--. 1 houyiqia games 535 10鏈 1 2012 configuration.xsl
-rw-r--r--. 1 houyiqia games 2161 10鏈 1 2012 log4j.properties
-rw-r--r--. 1 root root 808 1鏈 10 2018 zoo.cfg
-rw-r--r--. 1 houyiqia games 808 10鏈 1 2012 zoo_sample.cfg
[root@xuniji conf]# vi 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=/root/zkdata (修改为自己创建的目录,下面会用到这个目录,这也是可能造成启动失败、容易忽视的地方)
# 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
(添加这三行 之后设置myid必须与server后的数字一致,也是zookeeper启动失败原因之一,可查看zookeeper.out日志看是什么原因造成)
保存退出
[root@xuniji conf]# mkdir /root/zkdata (创建上面修改的目录)
[root@xuniji ~]# cd /root/zkdata
[root@xuniji zkdata]# ll
鎬荤敤閲0
[root@xuniji zkdata]# echo 1 > myid
[root@xuniji zkdata]# ll
鎬荤敤閲4
-rw-r--r--. 1 root root 2 7鏈 11 19:15 myid
[root@xuniji zkdata]# cat myid
1
将本机安装zookeeper的目录复制到其他主机
[root@xuniji ~]# scp -r apps/ 192.168.1.118:/root
The authenticity of host '192.168.1.118 (192.168.1.118)' can't be established.
RSA key fingerprint is 0f:3d:4b:70:62:96:26:2c:85:91:49:e5:34:2b:3e:3d.
Are you sure you want to continue connecting (yes/no)? yes
在目标主机上创建目录
[root@linux3 ~]# mkdir zkdata
[root@linux3 ~]# echo 3 > zkdata/myid
[root@linux3 ~]#
启动
必须先关闭防火墙 service iptable stop
[root@linux2 zookeeper-3.4.5]# bin/zkServer.sh start
JMX enabled by default
Using config: /root/apps/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@linux2 zookeeper-3.4.5]# bin/zkServer.sh status
JMX enabled by default
Using config: /root/apps/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: leader
查看端口是否被占用
我的端口是2181(查看端口:进入zookeeper的conf目录)
[root@xuniji conf]# vi 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=/root/zkdata
# 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
server.1=192.168.100.130:2888:3888
server.2=192.168.100.129:2888:3888
server.3=192.168.100.131:2888:3888
[root@xuniji zookeeper-3.4.5]# netstat -apn | grep 2181 (查看端口是否被占用)
tcp 0 0 :::2181 :::* LISTEN 4212/java (端口被4212占用)
[root@xuniji zookeeper-3.4.5]# kill -9 4212(杀掉被占用的端口)
[root@xuniji zookeeper-3.4.5]# netstat -apn | grep 2181
[root@xuniji zookeeper-3.4.5]#
这样就可以启动成功了用了一个下午终于解决了启动失败问题