文章目录

  • 安装
    • 离线安装
    • 常用命令
    • 注册服务

安装

离线安装

1.创建一个文件夹,如

mkdir -p /opt/zookeeper

2.将zookeeper的包上传到服务器上该文件夹下,并进行解压

tar -zxvf apache-zookeeper-3.8.3-bin.tar.gz

3.进入conf文件夹,复制zoo_sample.cfg,命名为zoo.cfg

cd ./apache-zookeeper-3.8.3-bin/confcp zoo_sample.cfg zoo.cfg

4.修改zoo.cfg

# 数据存放位置dataDir=/data/zookeeper# 日志存放位置dataLogDir=/data/log/zookeeper

5.vim/etc/profile配置环境变量

#zookeeper-3.8.3 config startexport ZOOKEEPER_HOME=/opt/zookeeper/apache-zookeeper-3.5.9-binexport PATH=$ZOOKEEPER_HOME/bin:$PATHexport PATH #zookeeper-3.8.3 config end

然后运行加载环境配置

source /etc/profile

6.配置启动的JAVA(如果你系统环境的JAVA符合,则跳过此步骤),编辑bin目录下的zkEvn.sh

JAVA=/opt/jdk8/bin/javaJAVA_HOME=/opt/jdk8

常用命令

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,添加如下内容

[Unit]Description=zookeeper-3.8.3After=syslog.target network.target[Service]Restart=alwaysRestartSec=1Type=forkingTimeoutSec=120User=rootExecStart=/opt/zookeeper/apache-zookeeper-3.8.3-bin/bin/zkServer.sh startExecStop=/op/zookeeper/apache-zookeeper-3.8.3-bin/bin/zkServer.sh stopExecReload=/opt/zookeeper/apache-zookeeper-3.8.3-bin/bin/zkServer.sh restartRestart=always[Install]WantedBy=multi-user.target

2.然后服务注册加载,添加启动,启动

systemctl daemon-reloadsystemctl enable zookeepersystemctl start zookeeper

———————————-END———————————-

天行健,君子以自强不息;地势坤,君子以厚德载物