Zookeeper集群搭建配置

Dcr 1年前 ⋅ 991 阅读

集群配置
Zookeeper集群原则上需要2n+1个实例才能保证集群有效性,所以集群规模最少3个.
演示我就不用多台机器了,毕竟机器有限,还是采用单机多端口
1.创建数据文件存储目录

$ cd /usr/local/zookeeper
$ mkdir data

2.添加主配置文件

$ cd conf
$ cp zoo_sample.cfg zoo.cfg

3.修改配置
先把dataDir=/tmp/zookeeper注释掉,然后添加以下核心配置

dataDir=/usr/local/zookeeper/data
server.1=172.18.2.181:2881:3881
server.2=172.18.2.181:2882:3882
server.3=172.18.2.181:2883:3883

4.创建myid文件

$ cd ../data
$ touch myid
$ echo "1">>myid

每个实例的myid里面的值对应server.后面的数字x
5.开放3个端口

 $ sudo /sbin/iptables -I INPUT -p tcp --dport 2881 -j ACCEPT
 $ sudo /sbin/iptables -I INPUT -p tcp --dport 2882 -j ACCEPT
 $ sudo /sbin/iptables -I INPUT -p tcp --dport 2883 -j ACCEPT
 $ sudo /sbin/iptables -I INPUT -p tcp --dport 3883 -j ACCEPT
 $ sudo /sbin/iptables -I INPUT -p tcp --dport 3882 -j ACCEPT
 $ sudo /sbin/iptables -I INPUT -p tcp --dport 3881 -j ACCEPT

 $ sudo /etc/rc.d/init.d/iptables save
 $ sudo /etc/init.d/iptables restart

6.启动集群

nohup ./zkServer.sh start-foreground /usr/local/zookeeper/conf/zoo1.cfg  >> log.file 2>>log.error &
nohup ./zkServer.sh start-foreground /usr/local/zookeeper/conf/zoo2.cfg  >> log.file 2>>log.error &
nohup ./zkServer.sh start-foreground /usr/local/zookeeper/conf/zoo3.cfg  >> log.file 2>>log.error &

7.查看集群状态

cd /usr/local/zookeeper/bin/
./zkServer.sh status /usr/local/zookeeper/conf/zoo3.cfg

ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/conf/zoo3.cfg
myid could not be determined, will not able to locate clientPort in the server configs.
Client port found:  2183. Client address: localhost. Client SSL: false.
Mode: follower

全部评论: 0

    我有话说: