集群搭建(二)zookeeper搭建

【搭建】

1、导入tar包

2、解压tar包(不需要安装,已经编译好的,需要实现安装jdk,教程如下:http://www.cnblogs.com/monco/p/7514716.html

3、编辑目录下conf文件中的文件,将zoo_simple.cfg 文件复制一份 ,并修改文件名为zoo.cfg

4、修改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/data/zkdata
# the port at which the clients will connect
clientPort=2181

server.1=192.168.200.140:2888:3888
server.2=192.168.200.141:2888:3888
server.3=192.168.200.142:2888:3888

其中dataDir设置为你当前启动用户可以访问到的位置,如果这个文件夹位置找不到,那么将会爆粗,连接不上

server.1=192.168.200.140:2888:3888
server.2=192.168.200.141:2888:3888
server.3=192.168.200.142:2888:3888

 设置server地址,配置的每个server都是一台新的服务器,因为zookeeper需要奇数台机器搭建(半数以上机制),端口号默认使用2888:3888(集群内通信端口(leader监听端口),选举leader端口)

具体配置的解释在(https://www.cnblogs.com/yuyijq/p/3438829.html)这位大佬的博客中查看,我就不做过多解释

5、在指定的dataDir下创建相应的文件夹

6、将这台机器克隆成三台(修改克隆之后的IP请见http://www.cnblogs.com/monco/p/9046614.html

7、在dataDir下创建文件myid,如果设置的IP地址前面的server是server.1的话,那么myid中就只要写1就好了,可以通过echo 1 > myid 来写入文件,其他两台服务器也是如此

8、进入解压目录bin下,执行zkServer.sh start,三台都启动后,输入 zkServer.sh status 看是否出现leader,或者follower,出现的话,就说明已经完成并且已经启动

9、bin目录下,输入zkCli.sh,出现如下画面,启动客户端,可以对节点进行操作了。具体操作方法下篇详解。

【问题】:当zookeeper启动报出“Error contacting service. It is probably not running.”错误的时候,在确认自己的配置没有出错的时候,可以将conf目录下配置的zoo.cfg中的datair目录中除了myid这个文件,其他的文件都可以删除,然后重新启动,就好了

猜你喜欢

转载自www.cnblogs.com/monco/p/9050997.html