Sam's Notes | Sam Blog

梦想还是要有的,万一实现了呢

0%

zookeeper

主要内容

zookeeper 安装

更新历史

单机安装

计划zookeeper安装路径为 /data/zookeeper , 以 apache-zookeeper-3.6.3 为例。

解压缩

1
2
3
tar xvf apache-zookeeper-3.6.3-bin.tar.gz -C /data
cd /data
mv apache-zookeeper-3.6.3-bin zookeeper

配置文件

1
2
cd /data/zookeeper/conf
cp zoo_sample.cfg zoo.cfg

zoo.cfg 内容如下,admin.serverPort 根据实际情况修改, 默认会 占用8081

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/data/zookeeper/data
# the port at which the clients will connect
clientPort=12181
admin.serverPort=12180

# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

systemctl 服务

  • 脚本
    vim /usr/lib/systemd/system/zookeeper.service
    zookeeper.service 内容如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    [Unit]
    Description=Zookeeper Service unit Configuration
    After=network.target

    [Service]
    Type=forking
    ExecStart=/data/zookeeper/bin/zkServer.sh start
    ExecStop=/data/zookeeper/bin/zkServer.sh stop
    PIDFile=/data/zookeeper/data/zookeeper_server.pid

    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
  • 执行以下命令重载unit配置文件

    1
    systemctl daemon-reload
  • 开机启动

    1
    2
    systemctl enable zookeeper
    systemctl start zookeeper