Centos Zookeeper集群安装配置

1、文件准备

下载地址

https://zookeeper.apache.org/releases.html

上传文件至跟目录并解压到/opt 目录下

tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz -C /home/data/software
cd /home/data/software
mv apache-zookeeper-3.7.1-bin zookeeper

2、配置

配置conf文件

修改zoo.cfg文件 把原来文件夹中的zoo_sample.cfg改名为zoo.cfg

cd zookeeper/conf/
mv zoo_sample.cfg zoo.cfg
vi zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
maxClientCnxns=0               //添加一行
# The number of ticks that the initial 
# synchronization phase can take
initLimit=50                   //改成50
# 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=/home/data/software/zookeeper/data        //设置地址存放data
dataLogDir=/home/data/software/zookeeper/dataLog   //设置地址存放dataLog
# the port at which the clients will connect
clientPort=2181
server.1=172.19.230.101:2888:3888
server.2=172.19.230.103:2888:3888
server.3=172.19.230.105:2888:3888    //添加三行 地址为集群主机
# 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

把配置好的zoo.cfg文件复制给另外两台集群机器

scp zoo.cfg root@172.19.230.103:/home/data/software/zookeeper/conf/zoo.cfg
scp zoo.cfg root@172.19.230.105:/home/data/software/zookeeper/conf/zoo.cfg

配置项

说明

tickTime

用于计算的时间单元,以毫秒为单位,比如session超时:N*tickTime

initLimit

用于集群,允许从节点链接并同步到master节点的初始化连接时间,以tickTime的倍数来表示

syncLimit

用于集群,master主节点与从节点之间发送消息,请求和应答时间长度(心跳机制)

clientPort

连接服务器的端口,默认是2181

dataDir

快照日志目录,存放内存数据库快照的位置,必须配置

dataLogDir

事务日志目录,不配置则和dataDir共用

新建目录,刚才配置文件时的文件夹要存在。

mkdir /home/data/software/zookeeper/data
mkdir /home/data/software/zookeeper/dataLog
echo 1 > /home/data/software/zookeeper/data/myid

其他机器上也进行同样的操作,但把echo “1” 改成2和3

3、启动(每台)

cd /home/data/software/zookeeper/bin/
./zkServer.sh start

查看日志
cat zookeeper-root-server-localhost.localdomain.out

启动报错可能是端口未开放 2888、3888、2181

操作

./zkServer.sh start|stop|restart|status

客户端

连接
./zkCli.sh -server ${ip}:${port}

关闭
quit 或者按 Ctrl + C

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值