部署zookeeper集群

部署zookeeper集群

Deng YongJie's blog 249 2022-08-28

部署zookeeper集群

前提条件:部署好jdk8环境

注意: 查看客户端版本号要与集群的版本对应,否则会出现警告等报错信息

wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/apache-zookeeper-3.6.3-bin.tar.gz
tar zxf apache-zookeeper-3.6.3-bin.tar.gz -C /usr/local/zookeeper
cd /usr/local/zookeeper/apache-zookeeper-3.6.3-bin/

mkdir /usr/local/zookeeper
pvcreate /dev/sdb
vgcreate -s 16M zookeeper /dev/sdb
lvcreate -l 100%FREE -n lv1 zookeeper
lvs
mkfs.xfs /dev/zookeeper/lv1 
mount /dev/zookeeper/lv1 /usr/local/zookeeper/
echo `blkid /dev/zookeeper/lv1 | awk '{print $2}' | sed 's/\"//g'` /usr/local/zookeeper xfs defaults 0 0 >> /etc/fstab
cat /etc/fstab 
mv * ../zookeeper/
cd ..
rm -rf apache-zookeeper-3.6.3-bin*
cd zookeeper/
scp /root/apache-zookeeper-3.6.3-bin.tar.gz 192.168.3.35:/usr/local/
scp /root/apache-zookeeper-3.6.3-bin.tar.gz 192.168.3.36:/usr/local/

vim /etc/profile
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH

groupadd zookeeper
useradd zookeeper  -g zookeeper
source /etc/profile
echo $ZOOKEEPER_HOME

cd /usr/local/zookeeper/conf
mv zoo_sample.cfg zoo.cfg
vim zoo.cfg 
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/zookeeper/data
dataLogDir=/zookeeper/logs
clientPort=2181
server.1=192.168.88.11:2888:3888
server.2=192.168.88.12:2888:3888
server.3=192.168.88.13:2888:3888

cd ..
mkdir data
mkdir logs

vim data/myid
1

scp conf/zoo.cfg 192.168.3.35:/usr/local/zookeeper/conf/
scp conf/zoo.cfg 192.168.3.36:/usr/local/zookeeper/conf/
chown -R zookeeper.zookeeper /usr/local/zookeeper/

scp /root/jdk-8u172-linux-x64.rpm 192.168.3.35:/usr/local/
scp /root/jdk-8u172-linux-x64.rpm 192.168.3.36:/usr/local

vim /usr/lib/systemd/system/zookeeper.service
[Unit]
Description=zookeeper

[Service]
Type=forking
Environment=ZOO_LOG_DIR=/usr/local/zookeeper/logs/
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart
Restart=always
User=zookeeper
Group=zookeeper

[Install]
WantedBy=multi-user.target


chown -R zookeeper.zookeeper /usr/local/zookeeper
systemctl daemon-reload
systemctl start zookeeper
systemctl status zookeeper
systemctl enable zookeeper

#注意,3.5版本之后必须要使用bash执行脚本查看状态,否则会报错zkENV.sh  java_home的问题。换成bash执行即可
bash $ZOOKEEPER_HOME/bin/zkServer.sh status
bash $ZOOKEEPER_HOME/bin/zkCli.sh -server 192.168.3.34:2181
bash $ZOOKEEPER_HOME/bin/zkServer.sh status