您的位置:首页 > 其它

ubuntu16配置ZooKeeper集群(这里用的是Zookeeper3.4.10)

2018-01-30 13:05 375 查看
1.安装jdk:https://my.oschina.net/u/3316387/blog/1615301\

2.下载ZooKeeper:https://archive.apache.org/dist/zookeeper/,然后早/opt下创建一个目录zookeeper,将下载好的文件解压到这个目录。

3.在zookeeper目录下创建data,dataLog两个目录

4.在data下创建文件myid,并写入1,其他的机器分别写上2,3......可以随便定义。

5.进入/opt/zookeeper/zookeeper-3.4.10/conf/,创建文件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=/tmp/zookeeper
# 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

dataDir=/opt/zookeeper/data
dataLogDir=/opt/zookeeper/dataLog
server.1=192.168.1.201:2888:3888

server.2=192.168.1.202:2888:3888

server.3=192.168.1.203:2888:3888

说明:dataDir和dataLogDir需要自己创建,目录可以自己制定,对应即可。server.1中的这个1需要和192.168.1.201这个机器上的dataDir目录中的myid文件中的数值对应。server.2中的这个2需要和192.168.1.202这个机器上的dataDir目录中的myid文件中的数值对应。当然,数值你可以随便用,只要对应即可。2888和3888的端口号也可以随便用,因为在不同机器上,用成一样也无所谓。

6.进入/opt/zookeeper/zookeeper-3.4.10/bin/,编辑zkServer.sh 在程序的开头添加上:

export JAVA_HOME=/usr/lib/jvm/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH

不添加会出现以下错误:

JMX enabled by default

Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg

Error contacting service. It is probably not running.

7.最后启动zookeeper

sudo /opt/zookeeper/zookeeper-3.4.10/bin/zkServer.sh start

查看状态

sudo /opt/zookeeper/zookeeper-3.4.10/bin/zkServer.sh status
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: