zookeeper集群部署

安装java环境(略)

安装zookeeper集群

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
mkdir -p /export/servers
tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz -C /export/servers/
mv /export/servers/apache-zookeeper-3.5.5-bin /export/servers/zookeeper
cp /export/servers/zookeeper/conf/zoo_sample.cfg /export/servers/zookeeper/conf/zoo.cfg

vi /export/servers/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/export/data/zookeeper/
dataLogDir=/export/log/zookeeper/
clientPort=2181
maxClientCnxns=1000
autopurge.snapRetainCount=3
autopurge.purgeInterval=2
server.0=172.26.10.167:2888:3888
server.1=172.26.10.168:2888:3888
server.2=172.26.10.169:2888:3888

vi /export/servers/zookeeper/conf/java.env
#!/bin/bash
export JAVA_HOME=/export/servers/jdk1.8.0_192/
export JVMFLAGS="-Xms1024m -Xmx2048m $JVMFLAGS"

vi /export/servers/zookeeper/bin/zkEnv.sh

(修改下面的参数zookeeper.out存储路径)

ZOO_LOG_DIR="/export/log/zookeeper/"

上述操作在三台主机上都执行,或者直接拷贝。

第1机器创建相应文件夹

mkdir /export/data/zookeeper/
mkdir /export/log/zookeeper/
echo "0" > /export/data/zookeeper/myid

第2机器创建相应文件夹

mkdir /export/data/zookeeper/
mkdir /export/log/zookeeper/
echo "1" > /export/data/zookeeper/myid

第3机器创建相应文件夹

mkdir /export/data/zookeeper/
mkdir /export/log/zookeeper/
echo "2" > /export/data/zookeeper/myid

启动方式:

编写zookeeper的启动文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
vim  /usr/lib/systemd/system/zookeeper.service

[Unit]
Description=Apache Zookeeper server (Kafka)
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=forking
Environment=JAVA_HOME=/export/servers/jdk1.8.0_192/
ExecStart=/export/servers/zookeeper/bin/zkServer.sh start
ExecStop=/export/servers/zookeeper/bin/zkServer.sh stop
ExecReload=/export/servers/zookeeper/bin/zkServer.sh restart

[Install]
WantedBy=multi-user.target

上述操作在三台主机上都执行,或者直接拷贝。
1
2
3
4
5
6
7
8
9
10
11
重新加载:systemctl daemon-reload

启动:systemctl start zookeeper

开机自启:systemctl enable zookeeper

停止:systemctl stop zookeeper

重启:systemctl restart zookeeper

查看状态:systemctl status zookeeper