文章目录
安装
离线安装
1.创建一个文件夹,如
shell
mkdir -p /opt/zookeeper
2.将zookeeper的包上传到服务器上该文件夹下,并进行解压
shell
tar -zxvf apache-zookeeper-3.8.3-bin.tar.gz
3.进入conf文件夹,复制zoo_sample.cfg,命名为zoo.cfg
shell
cd ./apache-zookeeper-3.8.3-bin/conf
cp zoo_sample.cfg zoo.cfg
4.修改zoo.cfg
shell
# 数据存放位置
dataDir=/data/zookeeper
# 日志存放位置
dataLogDir=/data/log/zookeeper
5.vim /etc/profile配置环境变量
shell
#zookeeper-3.8.3 config start
export ZOOKEEPER_HOME=/opt/zookeeper/apache-zookeeper-3.5.9-bin
export PATH=$ZOOKEEPER_HOME/bin:$PATH
export PATH
#zookeeper-3.8.3 config end
然后运行加载环境配置
shell
source /etc/profile
6.配置启动的JAVA(如果你系统环境的JAVA符合,则跳过此步骤),编辑bin目录下的zkEvn.sh
shell
JAVA=/opt/jdk8/bin/java
JAVA_HOME=/opt/jdk8
常用命令
shell
cd /opt/zookeeper/apache-zookeeper-3.8.3-bin/bin
# 启动zookeeper
./zkServer.sh start
# 查看zookeeper状态
./zkServer.sh status
# 关闭zookeeper服务
./zkServer.sh stop
# 重启zookeeper服务
./zkServer.sh restart
注册服务
1.编辑vim /etc/systemd/system/zookeeper.service,添加如下内容
shell
[Unit]
Description=zookeeper-3.8.3
After=syslog.target network.target
[Service]
Restart=alwaysRestartSec=1
Type=forking
TimeoutSec=120
User=root
ExecStart=/opt/zookeeper/apache-zookeeper-3.8.3-bin/bin/zkServer.sh start
ExecStop=/op/zookeeper/apache-zookeeper-3.8.3-bin/bin/zkServer.sh stop
ExecReload=/opt/zookeeper/apache-zookeeper-3.8.3-bin/bin/zkServer.sh restart
Restart=always
[Install]
WantedBy=multi-user.target
2.然后服务注册加载,添加启动,启动
shell
systemctl daemon-reload
systemctl enable zookeeper
systemctl start zookeeper
----------------------------------END----------------------------------
天行健,君子以自强不息;地势坤,君子以厚德载物