CentOS7 Zookeeper安装

cd /opt
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
tar -xvf zookeeper-3.4.6.tar.gz -C /opt
cd zookeeper-3.4.6/
mkdir data
echo "1" > data/myid
#其它节点请修改1为其它值,集群内不重复

cat > /opt/zookeeper-3.4.6/conf/zoo.cfg <<EOF
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper-3.4.6/data
dataLogDir=/opt/zookeeper-3.4.6/log
clientPort=2181
maxClientCnxns=3000

#replace these with you real ip
server.1=192.168.6.117:2888:3888
server.2=192.168.6.118:2888:3888
server.3=192.168.6.119:2888:3888
EOF


#设置日志
sed -i 's/zookeeper.root.logger=INFO, CONSOLE/zookeeper.root.logger=INFO, CONSOLE, ROLLINGFILE/g' /opt/zookeeper-3.4.6/conf/log4j.properties
sed -i 's$ZOO_LOG_DIR="."$ZOO_LOG_DIR="../log"$g' /opt/zookeeper-3.4.6/bin/zkEnv.sh
sed -i 's$ZOO_LOG4J_PROP="INFO,CONSOLE"$ZOO_LOG4J_PROP="INFO,ROLLINGFILE"$g' /opt/zookeeper-3.4.6/bin/zkEnv.sh


启动zookeeper:/opt/zookeeper-3.4.6/bin/zkServer.sh start
停止zookeeper:/opt/zookeeper-3.4.6/bin/zkServer.sh stop
检查集群状态 : /opt/zookeeper-3.4.6/bin/zkServer.sh status
集群有应该有且只有1个leader,其它的都为follower


#设置zookeeper自启动
cat > /usr/lib/systemd/system/zookeeper.service <<EOF
[Unit]
Description=Zookeeper service
After=network.target

[Service]
Type=simple
PIDFile=/opt/zookeeper-3.4.6/data/zookeeper_server.pid
ExecStart=/opt/zookeeper-3.4.6/bin/zkServer.sh start
ExecStop=/opt/zookeeper-3.4.6/bin/zkServer.sh stop

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable zookeeper

 

posted @ 2020-08-05 15:49  肖哥哥  阅读(269)  评论(0编辑  收藏  举报
生命不息  奋斗不止  每天进步一点点