contos7 安装zookeeper集群

1.软件版本:

zookeeper-3.4.6.tar.gz

2.下载地址:

https://mirrors.cnnic.cn/apache/zookeeper/

3.上传到机器目录:/usr/local

4.进入上传的目录后解压zookeeper:

tar -zxvf  zookeeper-3.4.6.tar.gz  zookeeper

# 进入zookeeper目录
cd zoookeeper/

# 创建data 和 logs目录
mkdir data logs

 

5.在 data 目录下创建 myid 文件,并写入编号

 cd ../data
 touch myid
 echo "1">>myid

  每台机器的myid里面的值对应server.后面的数字x。

 

6.需要开放3个端口(可选做)

[root@redhat66 data]# sudo /sbin/iptables -I INPUT -p tcp --dport 2181 -j ACCEPT
[root@redhat66 data]# sudo /sbin/iptables -I INPUT -p tcp --dport 2888 -j ACCEPT
[root@redhat66 data]# sudo /sbin/iptables -I INPUT -p tcp --dport 3888 -j ACCEPT

7.配置zookeeper环境变量

# 编辑 /etc/profile
[root@192 ~]# vi /etc/profile

# 在文件尾部新增如下内容:
#zookeeper
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$ZOOKEEPER_HOME/bin/:$PATH

# 使文件生效
source /etc/profile

 8.配置zookeeper启动文件

# 进入conf
cd conf/

# 拷贝文件
cp zoo_sample.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=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs/
server.1=192.168.0.165:2888:3888
server.2=192.168.0.166:2888:3888
server.3=192.168.0.167:2888:3888


# 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.x  x与myid文件中的内容保持一致

9.其他的机器重复步骤3-8步骤

10.分别启动三台机器上的zookeeper服务

zkServer.sh start

11.查看服务状态

zkServer.sh status

[root@192 bin]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower

 

 

[root@redhat66 bin]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader

 

 

[root@192 bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower

 

12.或者使用jps,有(4895 QuorumPeerMain)则启动成功

 

[root@192 bin]# jps
4922 Jps
4895 QuorumPeerMain

  

 

13.客户端连接

./zkCli.sh -server 192.168.0.166:2181

  

 

posted @ 2022-08-07 16:57  慕容天白  阅读(20)  评论(0编辑  收藏  举报