工程师计划 linux zookeeper集群安装

zookeeper集群安装

zookeeper(2181)

1.机器ip,设置免密

192.168.94.10
192.168.94.11
192.168.94.12
#免密设置,在三台机器上分别执行
ssh-keygen #一直按回车即可
ssh-copy-id 192.168.94.10 #修改输入密码
ssh-copy-id 192.168.94.11 #修改输入密码
ssh-copy-id 192.168.94.12 #修改输入密码

2.上传安装包到10

tar -xvf apache-zookeeper-3.6.2-bin.tar.gz -C /opt
cd /opt
mv zookeeper-3.6.2 zookeeper

3.在三台机器上分别修改环境变量

vim /etc/profile

export JAVA_HOME=/opt/jdk
export ZOOKEEPER_HOME=/opt/zookeeper
export PATH=$PATH:$JAVA_HOME:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:

:wq

source /etc/profile

4.创建data和datalog目录

cd /opt/zookeeper
mkdir {data,datalog}

5.在data下创建myid文件

cd /opt/zookeeper/data
echo 10 > /myid

6.修改配置文件

cd /opt/zookeeper/conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/data
dataLogDir=/opt/zookeeper/datalog
clientPort=2181
#server.10中的10和myid中的值一致
server.10=192.168.94.10:2888:3888
server.11=192.168.94.11:2888:3888
server.12=192.168.94.12:2888:3888
:wq
vim zkEN
#zoo.cfg参数说明
参数说明:
1、tickTime=2000
zookeeper中使用的基本时间单位, 毫秒值.
2、initLimit=10
zookeeper集群中的包含多台server, 其中一台为leader, 集群中其余的server为follower.
initLimit参数配置初始化连接时, follower和leader之间的最长心跳时间。
此时该参数设置为10, 说明时间限制为10倍tickTime, 即10*2000=20000ms=20s.
3、syncLimit=5
该参数配置leader和follower之间发送消息, 请求和应答的最大时间长度.
此时该参数设置为5, 说明时间限制为5倍tickTime, 即10000ms.
4、dataDir=/usr/local/soft/zookeeper3.5.5/data
数据目录. 可以是任意目录.
5、dataLogDir=/usr/local/soft/zookeeper3.5.5/datalog
log目录, 同样可以是任意目录. 如果没有设置该参数, 将使用和dataDir相同的设置.
6、clientPort=2181
监听client连接的端口号,通过ip:2181端口进入zookeeper的文件系统
7、server.101=192.1.101:2888:3888
2888是leader与跟随者通信的接口,当leader挂掉后跟随者通过3888通信选举出新leader

7.集群配置

#把配置好的zookeeper拷贝到其他节点
scp -r /opt/zookeeper root@192.168.94.11:/opt/
scp -r /opt/zookeeper root@192.168.94.12:/opt/
修改11和12上的myid
ssh root@192.168.94.11 "echo 11 >/opt/zookeeper/data/myid"
ssh root@192.168.94.12 "echo 12 >/opt/zookeeper/data/myid"

8、编写启动脚本

#修改zkEnv.sh
vim /opt/zookeeper/bin/zkEnv.sh
...
ZOOBINDIR="${ZOOBINDIR:-/usr/bin}"
ZOOKEEPER_PREFIX="${ZOOBINDIR}/.."
#增加JAVA_HOME
JAVA_HOME=/opt/jdk
...
:wq
#创建集群启动脚本
cd /opt 
vim zookeeper-all.sh
#!/bin/bash
case $1 in
"start"){
for i in 192.168.94.10 192.168.94.11 192.168.94.12
do
echo --------------------------zookeeper $i 启动 -------------------
ssh $i "/opt/zookeeper/bin/zkServer.sh start"
done
}
;;
"stop"){
for i in 192.168.94.10 192.168.94.11 192.168.94.12
do
echo --------------------------zookeeper $i 关闭 -------------------
ssh $i "/opt/zookeeper/bin/zkServer.sh stop"
done
}
;;
"status"){
for i in 192.168.94.10 192.168.94.11 192.168.94.12
do
echo --------------------------zookeeper $i 状态 --------------------
ssh $i "/opt/zookeeper/bin/zkServer.sh status|grep Mode"
done
}
;;
""){
echo "参数选项 start|stop|status"
}
;;
esac

:wq
#增加可执行权限
chmod +x zookeeper-all.sh
#启动集群
/opt/zookeeper-all.sh start

9.验证

#查看集群分配状态
/opt/zookeeper-all.sh status
#客户端链接
zkCli.sh -server 192.168.94.10:2181
2022-06-09 14:50:19,017 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=3.10.0-693.el7.x86_64
2022-06-09 14:50:19,017 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2022-06-09 14:50:19,017 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2022-06-09 14:50:19,017 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/opt/zookeeper/bin
2022-06-09 14:50:19,017 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=23MB
2022-06-09 14:50:19,018 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=228MB
2022-06-09 14:50:19,018 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=29MB
2022-06-09 14:50:19,021 [myid:] - INFO  [main:ZooKeeper@1006] - Initiating client connection, connectString=192.168.94.10:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@36aa7bc2
2022-06-09 14:50:19,025 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2022-06-09 14:50:19,033 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2022-06-09 14:50:19,043 [myid:] - INFO  [main:ClientCnxn@1716] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2022-06-09 14:50:19,058 [myid:192.168.94.10:2181] - INFO  [main-SendThread(192.168.94.10:2181):ClientCnxn$SendThread@1167] - Opening socket connection to server zjx/192.168.94.10:2181.
2022-06-09 14:50:19,058 [myid:192.168.94.10:2181] - INFO  [main-SendThread(192.168.94.10:2181):ClientCnxn$SendThread@1169] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2022-06-09 14:50:19,125 [myid:192.168.94.10:2181] - INFO  [main-SendThread(192.168.94.10:2181):ClientCnxn$SendThread@999] - Socket connection established, initiating session, client: /192.168.94.10:44930, server: zjx/192.168.94.10:2181
2022-06-09 14:50:19,138 [myid:192.168.94.10:2181] - INFO  [main-SendThread(192.168.94.10:2181):ClientCnxn$SendThread@1433] - Session establishment complete on server zjx/192.168.94.10:2181, session id = 0xa0003bae05d0002, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: 192.168.94.10:2181(CONNECTED) 0] 
zookeeper集群安装
© 2021 京ICP备2021027871号-1
联系我们

联系我们

18513870113

在线咨询: QQ交谈

邮箱: 1140136143@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部