zookeeper集群部署
//
# zookeeper集群部署
# 安装jdk环境
# zookeeper安装
zookeeper-Apache下载地址 (opens new window)
# 配置zookeeper集群
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
tar xf zookeeper-3.4.14.tar.gz -C /opt
ln -s /opt/zookeeper-3.4.14/ /opt/zookeeper
cd /opt/zookeeper/
1
2
3
4
2
3
4
- 配置zoo.cfg
mkdir -p /data/zookeeper/{data,logs}
vi /opt/zookeeper/conf/zoo.cfg
1
2
2
单机模式示例
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
clientPort=2181
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
集群模式
添加hosts,或者DNS解析
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
clientPort=2181
server.1=hdss14-12.host.com:2888:3888
server.2=hdss14-21.host.com:2888:3888
server.3=hdss14-22.host.com:2888:3888
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- 添加myid
注意这个myid要与zoo.cfg里面的 server.ID 对应
[root@hdss14-12 src]# echo '1' > /data/zookeeper/data/myid
[root@hdss14-21 src]# echo '2' > /data/zookeeper/data/myid
[root@hdss14-22 src]# echo '3' > /data/zookeeper/data/myid
1
2
3
2
3
# 启动,检查
#启动
/opt/zookeeper/bin/zkServer.sh start
#三台都执行,再检查
/opt/zookeeper/bin/zkServer.sh status
1
2
3
4
5
2
3
4
5
- zookeeper启动异常,检查
bash -x /opt/zookeeper/bin/zkServer.sh start
找到java 执行的那条命令,在命令行执行,查看报错日志
1
2
3
2
3
[root@hdss14-12 zookeeper]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@hdss14-21 zookeeper]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@hdss14-22 zookeeper]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Mode: follower
# zookeeper添加到systemd
- 创建用户,修改权限
groupadd zookeeper
useradd -M -s /sbin/nologin -g zookeeper zookeeper
chown -R zookeeper.zookeeper /data/zookeeper/
1
2
3
2
3
- 添加zookeeper systemd
vi /usr/lib/systemd/system/zookeeper.service
[Unit]
Description=ZooKeeper Service
After=network.target
After=syslog.target
[Service]
Environment=ZOO_LOG_DIR=/data/zookeeper/logs
Environment=JAVA_HOME=/usr/local/jdk1.8
PIDFile=/data/zookeeper/data/zookeeper_server.pid
SyslogIdentifier=zookeeper
Type=forking
User=zookeeper
Group=zookeeper
ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop /opt/zookeeper/conf/zoo.cfg
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=default.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//
如果此文章对您有帮助,点击 -->> 请博主喝咖啡 (opens new window)
上次更新: 2022/07/10, 23:09:14