环境:linux系统版本:centos7、jdk环境:jdk1.8、zookeeper:apache-zookeeper-3.5.9
dataDir=/usr/local/apache-zookeeper-3.5.9/data
dataLogDir=/usr/local/apache-zookeeper-3.5.9/log
如果想配置集群的话,请在clientPort下面添加服务器的ip。如
server.1=192.168.180.1:2888:3888
server.2=192.168.180.2:2888:3888
如果是配置集群,还需要在前面配置过的dataDir路径下新增myid文件,在data目录下创建文件,文件名为“myid”, 编辑该“myid”文件,并在对应的IP的机器上输入对应的编号。
如在192.168.180.1上,“myid”文件内容就是1。在192.168.180.2上,内容就是2。
注:需创建对应的目录
export ZOOKEEPER_HOME=/usr/local/ apache-zookeeper-3.5.9/
export PATH=$PATH:$ZOOKEEPER_HOME/bin
启动成功效果:
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper*/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
提示:
Connecting to localhost:2181
..........
..........
..........
Welcome to ZooKeeper!
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
效果:
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper*/bin/../conf/zoo.cfg
Mode: standalone
create /zk-test 123
get /zk-test
delete /zk-test
查看状态时一直报错:ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.5.9/bin/../conf/zoo.cfg
Client port found: 2888. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.
原因及解决:可能是由于XX-bin.tar.gz 和XX.tar.gz区别::前者解开就能用,包含的是二进制程序和一些配置;后者解开是完整开发目录,需要去编译才能安装使用。更换为apache-zookeeper-3.5.9-bin.tar.gz即ok。
原因及解决:或者是版本问题,更换为低版本zookeeper-3.4.13.tar.gz即可。