linux下Zookeeper集群安装

目录

 

一、准备3台linux虚拟机

二、安装zookeeper

下载安装包   

解压zookeeper       

进入到zookeeper路径下,copy一份zoo.cfg  

在zoo.cfg里面增加

配置一个文件 myid

 启动zookeeper

注意


一、准备3台linux虚拟机

此处不再介绍,可以搜索其他博文,推荐一篇博文 https://www.cnblogs.com/chengssblog/p/6531964.html

二、安装zookeeper

  • 下载安装包   

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz

  • 解压zookeeper       

tar -zxvf zookeeper-3.4.10.tar.gz

  • 进入到zookeeper路径下,copy一份zoo.cfg  

cp  zoo_sample.cfg  zoo.cfg

  • 在zoo.cfg里面增加

server.1=192.168.11.129:2181:3181:observer

server.2=192.168.11.131:2181:3181

server.3=192.168.11.135:2181:3181

该zoo.cfg文件为zookeeper的配置文件

# 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.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181

tickTime:基本事件单元,以毫秒为单位。它用来控制心跳和超时,默认情况下最小的会话超时时间为两倍的 tickTime。

dataDir:存放内存数据的地方

clientPort:用户于zookeeper相连的端口

initLimit:Leader允许F在 initLimit 时间内完成这个工作,请求和响应时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 10*2000=20 秒

syncLimit:检测机器的存活状态,请求和响应时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 5*2000=10 秒

tickTime=2000
dataDir=/usr/zdatadir
dataLogDir=/usr/zlogdir
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.11.128:2888:3888
server.2=192.168.11.129:2888:3888
server.3=192.168.11.130:2888:3888

server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号

如果需要配置obverse,则在最后面加上":observer",如:server.4=192.168.11.131:2888:3888:observer

  • 配置一个文件 myid

除了修改 zoo.cfg 配置文件,集群模式下还要配置一个文件 myid,这个文件在 dataDir 目录下,这个文件里面就有一个数据就是 A 的值,Zookeeper 启动时会读取这个文件,拿到里面的数据与 zoo.cfg 里面的配置信息比较从而判断到底是那个 server。

  •  启动zookeeper

其他几台服务器(注意差别,其他的服务器的serveri.ID,对应的MYID要修改)也对应配置上后,启动zookeeper

./zkServer.sh start

启动后,在bin目录下会生成一个zookeeper.out文件,此为zookeeper的运行日志,可以查看日志输出

tail -f zookeeper.out 

注意

如果启动后日志报错,一般为未关闭防火墙

关闭防火墙:

  1. 重启后永久生效

开启:chkconfig iptables on

关闭:chkconfig iptables off

  1. 即时生效

开启:service iptables start

关闭:service iptables stop

猜你喜欢

转载自blog.csdn.net/mk33092250/article/details/100392429