返回顶部

Centos7 安装zookeeper

(一) 安装

1. cd /usr/share,创建 zookeeper文件夹

2. 进入zookeeper

3. 下载zookeeper

wget https://archive.apache.org/dist/zookeeper/zookeeper-3.5.9/apache-zookeeper-3.5.9-bin.tar.gz

4. 解压

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

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

cd apache-zookeeper-3.5.9-bin/conf
cp zoo_sample.cfg zoo.cfg

6. 修改zoo.cfg中配置,改好后保存

 

 7. 编辑 /etc/profile, 在文件末尾追加内容

 

 生效profile

source /etc/profile

8. 启动zookeeper

cd bin
# 启动zookeeper
./zkServer.sh start

# 查看zookeeper状态
./zkServer.sh status

# 关闭zookeeper服务
./zkServer.sh stop

# 重启zookeeper服务
./zkServer.sh restart

 

(二)设置服务和开机启动

1. 添加到服务管理

vim /usr/lib/systemd/system/zookeeper.service

添加以下内容后,保存

[Unit]
Description=zookeeper-3.5.9
After=syslog.target network.target

[Service]
Restart=alwaysRestartSec=1
Type=forking
TimeoutSec=120

User=root

ExecStart=/usr/share/zookeeper/apache-zookeeper-3.5.9-bin/bin/zkServer.sh start
ExecStop=/usr/share/zookeeper/apache-zookeeper-3.5.9-bin/bin/zkServer.sh stop
ExecReload=/usr/share/zookeeper/apache-zookeeper-3.5.9-bin/bin/zkServer.sh restart

Restart=always

[Install]
WantedBy=multi-user.target

2. 生效服务及开机自启动

systemctl daemon-reload
systemctl enable zookeeper.service

3. 启动

# 启动
systemctl start zookeeper
# 查看状态 systemctl status zookeeper
# 停止
systemctl stop zookeeper

 

posted @ 2022-08-31 13:42  雨山木风  阅读(1507)  评论(0编辑  收藏  举报