zookeeper
单机安装
wget apache-zookeeper-3.7.1-bin.tar.gz
tar -zxf apache-zookeeper-3.7.1-bin.tar.gz
cd apache-zookeeper-3.7.1-bin
cp conf/zoo_sample.cfg conf/zoo.cfg
./bin/zkServer.sh start配置文件部分配置项说明
tickTime 服务器之间或客户端与服务器之间的心跳间隔,单位毫秒
dataDir 数据库快照保存位置
clientPort 服务器端口配置
initLimit 客户端初始化连接时最长能忍受失败时间(N*tickTime)
syncLimit Leader与Follower之间最长能忍受的请求和应答时间长度(N*tickTime)
server.N=IP:2888:3888
N表示这是第几号服务器,
2888是服务器与集群中的leader服务器交换信息的端口
3888表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader
配置成systemd
以CentOS 7为例。因为zookeeper是需要依赖JAVA的,所以需要配置JAVA环境变量
cat > /etc/systemd/system/zookeeper.service << EOF
[Unit]
Description=Apache zookeeper Daemon
[Service]
Environment=JAVA_HOME=/usr/local/jdk1.8.0_171
ExecStart=/usr/src/apache-zookeeper-3.7.1-bin/bin/zkServer.sh start /usr/src/apache-zookeeper-3.7.1-bin/conf/zoo.cfg
ExecStop=/usr/src/apache-zookeeper-3.7.1-bin/bin/zkServer.sh stop
PIDFile=/opt/zookeeper/zookeeper_server.pid
User=root
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
systemctl start zookeeper集群安装
zookeeper集群安装的配置相比于单机安装,配置中要增加一个server.N=ip_or_hostname:2888:3888的配置,有几个节点,就复制几行,每个服务器N的值不能相同。除了增加这个配置外,还要在zookeeper服务的dataDir这个目录下创建一个名为myid的文件,内容为本机的N值。例如,本机是server.1,则myid的内容则为1
zoo.cfg
# 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=/opt/zookeeper
# the port at which the clients will connect
clientPort=2181
# 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
server.1=172.23.210.22:2888:3888
server.2=172.23.210.23:2888:3888
server.3=172.23.210.24:2888:3888配置myid
echo N > /opt/zookeeper/myid # 每个节点的N要跟server.N配置中的N相同,myid的位置为“dataDir”的配置路径
./bin/zkServer.sh start使用systemctl控制参考[[#配置成systemd]]
最后更新于