1.安装好zookeeper
2.配置环境变量/etc/profile添加以下
export ZK_HOME=//data/apache-zookeeper-3.6.0/
export PATH=$PATH:$ZK_HOME/bin
source /etc/profile
3.进入/etc/systemd/system
vim zookeeper.service
[Unit]
# Zookeeper服务的描述
Description=Zookeeper Service
# 服务依赖?在什么服务之后启动,一般为在网络服务启动后启动
After=network.target
[Service]
# 服务类型?如果是shell脚本的方式,则Type=forking,否则不指定作何值(也就是去掉该配置项)
Type=forking
# 启动环境参数
# 此脚本指定了Zookeeper日志和Java的目录
Environment=ZOO_LOG_DIR=/data/zookeeper/logs/
Environment=JAVA_HOME=/usr/local/jdk1.8
# 启动命令
ExecStart=/data/apache-zookeeper-3.6.0/bin/zkServer.sh start
# 停止命令
ExecStop=/data/apache-zookeeper-3.6.0/bin/zkServer.sh stop
# 重启命令
ExecReload=/data/apache-zookeeper-3.6.0/bin/zkServer.sh restart
[Install]
WantedBy=multi-user.target
#系统重新加载服务
systemctldaemon-reload
#设置开机自启动
systemctl enable zookeeper.service
启动命令:systemctl start zookeeper.service
停止命令:systemctl stop zookeeper.service
重启命令:systemctl restart zookeeper.service
查看状态命令:systemctl status zookeeper.service
关闭开机启动
systemctl disable zookeeper.service
网友评论