zookeeper版本
下载地址:http://archive.apache.org/dist/zookeeper/zookeeper-3.5.8/
服务器准备
1.集群至少准备3台服务器
2.例如:
192.168.1.1
192.168.1.2
192.168.1.3
解压文件
tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz
修改配置文件
进入安装目录下的conf文件夹,修改zoo_example.cfg文件名
mv zoo_example.cfg zoo.cfg
修改后结构如下:
编辑zoo.cfg文件
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.
dataDir=/opt/zookeeper/data
# the port at which the clients will connect
clientPort=2181
#set admin server port
admin.serverPort=8081
# 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
server.0=192.168.1.1:2888:3888
server.1=192.168.1.2:2888:3888
server.2=192.168.1.3:2888:3888
在zoo.cfg中dataDir中的目录(/opt/zookeeper/data)下创建文件
touch myid
vim myid
myid的内容与zoo.cfg的server后所带的数字相对应,
例如:192.168.1.1 myid的内容就应该是0
修改环境变量:
vim /etc/profile
在末尾加上
#set zookeeper environment
export ZK_HOME=/opt/apache-zookeeper-3.5.8
export PATH=$PATH:$ZK_HOME/bin
刷新并验证环境变量
source /etc/profile
echo $PATH
启动zookeeper
zkServer.sh start
如果遇到权限启动错误
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.5.8/bin/ ../config/zoo.cfg
Starting zookeeper ... zkServer.sh: line 149: /opt/zookeeper/zookeeper_server.pid : Permission denied
修改zookeeper安装目录权限
chmod -R 777 zookeeper-3.5.8/
启动检查
通过命令检查zookeeper启动状态
zkServer.sh status
mode为 follower或leader则启动成功
如果启动失败,查看日志
#切换到安装目录/opt/apache-zookeeper-3.5.8/logs
cd /opt/apache-zookeeper-3.5.8/logs
#查看错误日志
vim zookeeper-root-server-host-192-168-1-1.out
这里列出一种错误情况(端口占用:8080)
端口占用可通过zoo.cfg中admin.serverPort属性修改,此处已改为8081
启动集群
在每台服务器上都执行以上操作,最后执行命令
#启动服务
zkServer.sh start
#验证服务
zkServer.sh status