systemd(CentOS7)启动zookeeper

1.准备zookeeper用户

groupadd zookeeper
useradd  -M -s /bin/false -g zookeeper zookeeper

2.准备工作目录

mkdir -p /zookeeper/{data,conf,logs,src}
wget -P /zookeeper/src https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz
tar zxf /zookeeper/src/zookeeper-3.4.13.tar.gz
chown zookeeper.zookeeper -R /zookeeper
chmod 750 -R /zookeeper
ln -s /zookeeper/src/zookeeper-3.4.13 /opt/zookeeper

3.创建zookeeper配置文件:/zookeeper/conf/zoo.cfg

  • Standalone模式:
tickTime=2000
initLimit=10
syncLimit=5
clientPort=2181
dataDir=/zookeeper/data
dataLogDir=/zookeeper/data/logs
  • Clustered模式:
tickTime=2000
initLimit=10
syncLimit=5
clientPort=2181
dataDir=/zookeeper/data
dataLogDir=/zookeeper/data/logs

server.1=zk1:2888:3888
server.2=zk2:2888:3888
server.3=zk3:2888:3888

Clustered模式下需要创建myid文件,节点对应id:echo "1" > /zookeeper/data/myid

4.编写systemd.service服务脚本:/etc/systemd/system/zookeeper.service

[Unit]
Description=ZooKeeper Service
After=network.target
After=syslog.target

[Service]
Environment=ZOO_LOG_DIR=/zookeeper/logs
SyslogIdentifier=zookeeper

Type=forking
User=zookeeper
Group=zookeeper
ExecStart=/opt/zookeeper/bin/zkServer.sh start /zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop /zookeeper/conf/zoo.cfg
ExecReload=/opt/zookeeper/bin/zkServer.sh restart /zookeeper/conf/zoo.cfg


[Install]
WantedBy=default.target

重新加载配置信息:systemctl daemon-reload
启动zookeeper:systemctl start zookeeper.service
关掉zookeeper:systemctl stop zookeeper.service
查看进程状态及日志:systemctl status zookeeper.service
开机自启动:systemctl enable zookeeper.service
关闭自启动:systemctl disable zookeeper.service

posted @   javaite  阅读(2027)  评论(0编辑  收藏  举报
编辑推荐:
· 继承的思维:从思维模式到架构设计的深度解析
· 如何在 .NET 中 使用 ANTLR4
· 后端思维之高并发处理方案
· 理解Rust引用及其生命周期标识(下)
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
阅读排行:
· Cursor预测程序员行业倒计时:CTO应做好50%裁员计划
· 当职场成战场:降职、阴谋与一场硬碰硬的抗争
· 用99元买的服务器搭一套CI/CD系统
· Excel百万数据如何快速导入?
· 35岁程序员的中年求职记:四次碰壁后的深度反思
点击右上角即可分享
微信分享提示