安装zookeeper的集群是用到了3个节点:分别是ywjyapp56,ywjyapp57,ywjyapp568。也就是说要在这三个节点上部署zookeeper。这里需要注意一点:zookeeper集群的节点数必须是奇数,并且至少为3个。这里涉及到zookeeper的选举算法。
1、首先肯定是从官网下载相应的tar包,并解压
网址:http://zookeeper.apache.org/releases.html#download。
解压:tar -zxvf zookeeper-3.4.8.tar.gz
2、添加环境变量
export ZOOKEEPER_HOME=/home/was/zookeeper/zookeeper-3.4.8
export PATH=$PATH:$ZOOKEEPER_HOME/bin 3、修改配置文件 cd zookeeper-3.4.68/conf ,将zoo_sample.cfg复制为zoo.cfg,并修改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=/home/was/zookeeper/zkdata
dataLogDir=/home/was/zookeeper/zklog
# 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
server.1=ywjyapp56:2888:3888
server.2=ywjyapp57:2888:3888
server.3=ywjyapp58:2888:3888
在这里需要注意zoo.cfg的配置文件中的dataDir和dataLogDir的路径当中的文件夹必须要已存在,否则后面启动zkServer服务的时候会失败,ywjyapp56、ywjyapp57、ywjyapp58为主机名
4、在dataDir对应的路径文件夹下(我这里是zkdata文件夹),创建一个myid的文件,并在该文件中输入对应集群各节点的id,我这里对应的是ywjyapp56 对应的就是1,这个是与
server.1=ywjyapp56 :2888:3888对应的。各个节点分别输入对应的id值即可。
5、启动zkServer
./bin/zkServer.sh start
在各节点上执行:./zkServer.sh start
6、此时可以通过./zkServer.sh status 命令来查看节点的启动状态。 这里需要注意点,只有当至少启动了三个节点之后,该命令才会产生结果。否则会显示:zookeeper Error contacting service. It is probably not running错误 当你启动了至少三个节点之后,执行该命令可以看到: 至此,zookeeper的安装工作结束。 7、关闭zookeeper服务 zkServer.sh stop 关闭 zkServer.sh restart 重启 |
zookeeper 环境搭建
最新推荐文章于 2024-07-05 19:15:38 发布
|