安装 ZooKeeper 并配置服务

3 篇文章 0 订阅

官网

  1. 访问官方下载页面
  2. 安装
# 注意替换一下新的链接
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]部分

  1. 控制单元 [Unit]:记录unit文件的通用信息
    1. Description:单元的描述,内容可以任意书写,
  2. 服务 [Service]:记录service的信息
    1. Type:service的种类,
      1. simple (默认): 启动的程序是主体程序,这个程序退出那么一切都退出
      2. forking: 标准 Unix Daemon 使用的启动方式。启动程序后会调用 fork() 函数,把必要的通信频道都设置好之后父进程退出,留下守护精灵的子进程
      3. oneshot: 仅启动,完成,没进程
    2. ExecStart: 服务启动时执行的命令,通常是服务的主体。若服务类型不是oneshot,那么它只接受一个命令,参数不限制。如果是多个命令用分号 ; 隔开
    3. Restart: 定义服务何种情况下重启
  3. 安装 [Install]: 安装信息
    1. WantedBy: 任何情况下, 服务被启用
      2. WantedBy=multi-user.target 多用户环境下启用
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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值