zookeeper的伪集群部署步骤

一、首先打开WinSCP,登录远程服务器

二、打开Xshell,连接远程服务器,使用Linux命令对远程服务器进行操作。

三、使用Xshell命令框将远程服务器路径定位到zookeeper文件夹下

四、下载zookeeper-3.4.10,并解压,复制三份放在/root/home/softwares/zookeeper路径下。分别命名为zookeeper-3.4.10_1,ookeeper-3.4.10_2,ookeeper-3.4.10_3。

五、cd zookeeper-3.4.10_1/conf/命令,定位到conf路径下,创建文件zoo.cfg

六、分别在zookeeper-3.4.10_1,zookeeper-3.4.10_3,zookeeper-3.4.10_3下创建data文件夹,并在data文件夹下创建logs文件夹

七、分别修改三个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=/home/softwares/zookeeper/zookeeper-3.4.10_1/data
dataLogDir=/home/softwares/zookeeper/zookeeper-3.4.10_1/data/logs
# 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
server.1=0.0.0.0:2888:3888
server.2=180.76.234.29:4888:5888
server.3=180.76.234.29:6888:788

1)由于是伪集群模式,所以三个clientPort端口号必须不一致,若在三台服务器上可以一样。

2)server.X=A:B:C 其中

   X:是一个数字,表示这是第几号server

   A:  是该server所在的IP地址

     B:   配置该server和集群中的leader交换信息所使用的的端口

     C:   配置选举leader时所使用的端口,由于配置的是伪集群,所以各个server的B,C参数必须不同

八、分别在/zookeeper-3.4.10_1/data,/zookeeper-3.4.10_2/data,/zookeeper-3.4.10_3/data路径下创建myid,并分别在文件里写入1,2,3。

九、分别进入/zookeeper-3.4.10_1/bin,/zookeeper-3.4.10_2/bin,/zookeeper-3.4.10_3/bin目录,输入命令:./zkServer.sh start 启动服务器。使用./zkServer.sh status命令查看三台服务器的运行状态。使用./zkServer.sh stop 命令停止服务器运行。

 

十、使用伪集群模式必须关闭防火墙。若没有关闭防火墙,会出现没有路由连接到主机的错误。

       rpm -qa  查看防火墙是否安装

       yum install iptables 如果防火墙没有安装,使用该命令安装防火墙(必须联网)

       service iptable status  查看防火墙状态

       service iptable start     开启防火墙

       service iptable status  关闭防火墙

原文地址:https://www.cnblogs.com/mercuryji/p/zookeeper_deploy_pseudocluster.html