安装 ZooKeeper 并配置服务
安装 ZooKeeper 并配置服务。
官网
- 访问官方下载页面
- 安装
# 注意替换一下新的链接
curl -sSLO https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz -C /opt/
cd /opt
ln -s zookeeper-3.4.10 ./zookeeper
cd zookeeper
mkdir data
User
Create a zookeeper user
groupadd zookeeper
useradd -g zookeeper -d /opt/zookeeper -s /sbin/nologin zookeeper
Set the permissions:
chown -R zookeeper:zookeeper /opt/zookeeper/*
Config
vi /opt/zookeeper/conf/zoo.cfg
Add the following:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/data
clientPort=2181
server.1=192.168.187.75:2888:3888
server.2=192.168.187.77:2888:3888
server.3=192.168.187.78:2888:3888
Test the service:
/opt/zookeeper/bin/zkServer.sh start
Ctrl-c out of that and lets create a systemd unit file for the service.
Systemd
vi /usr/lib/systemd/system/zookeeper.service
Add the following:
[Unit]
Description=Zookeeper Service
[Service]
Type=simple
WorkingDirectory=/opt/zookeeper/
PIDFile=/opt/zookeeper/data/zookeeper_server.pid
SyslogIdentifier=zookeeper
User=zookeeper
Group=zookeeper
ExecStart=/opt/zookeeper/bin/zkServer.sh start
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
Restart=always
TimeoutSec=20
SuccessExitStatus=130 143
[Install]
WantedBy=multi-user.target
Systemd 配置文件
Systemd 的 unit 的配置文件位置 (redhat系): /usr/lib/systemd/system/
Systemd服务主要内容为:控制单元[unit]的定义、服务[service]的定义、安装[install]部分
- 控制单元 [Unit]:记录unit文件的通用信息
- Description:单元的描述,内容可以任意书写,
- 服务 [Service]:记录service的信息
- Type:service的种类,
- simple (默认): 启动的程序是主体程序,这个程序退出那么一切都退出
- forking: 标准 Unix Daemon 使用的启动方式。启动程序后会调用
fork()
函数,把必要的通信频道都设置好之后父进程退出,留下守护精灵的子进程 - oneshot: 仅启动,完成,没进程
- ExecStart: 服务启动时执行的命令,通常是服务的主体。若服务类型不是oneshot,那么它只接受一个命令,参数不限制。如果是多个命令用分号
;
隔开 - Restart: 定义服务何种情况下重启
- Type:service的种类,
- 安装 [Install]: 安装信息
- WantedBy: 任何情况下, 服务被启用
2.WantedBy=multi-user.target
多用户环境下启用
- WantedBy: 任何情况下, 服务被启用
Restart
Restart=always: 只要不是通过systemctl stop来停止服务,任何情况下都必须要重启服务,默认值为no
RestartSec=5: 重启间隔,比如某次异常后,等待5(s)再进行启动,默认值0.1(s)
StartLimitInterval: 无限次重启,默认是10秒内如果重启超过5次则不再重启,设置为0表示不限次数重启
Next
systemctl daemon-reload # 重新加载服务配置文件
systemctl enable zookeeper.service
systemctl start zookeeper.service
SystemCtl
systemctl --help # 查看帮助
# enable 是在 /etc/systemd/system/multi-user.target.wants/ 这个目录下 做 unit 配置文件的软链
systemctl enable | disable | is-enabled | status | is-active unit
systemctl get-default | set-default graphical.target | multi-user.target # islate 在线切换模式
Test
Running the following will give a client interface to the zookeeper service:
/opt/zookeeper/bin/zkCli.sh
There are some examples here but you can create and get info as shown below:
To check which nodes are followers and which is the leader try issuing the following commands to each node:
echo srvr | nc localhost 2181
Troubleshooting
- Reset the user permissions on the /opt/zookeeper directory recursively
- Switch off firewalld and/or check a telnet connect to port 2181 on each node
- Try switching to the zookeeper user (su – zookeeper -s /bin/bash) and run the zkServer.sh start command
Reference
https://zookeeper.apache.org/releases.html
https://blog.redbranch.net/2018/04/19/zookeeper-install-on-centos-7/
更多推荐
所有评论(0)