Zookeeper集群
Last updated
Was this helpful?
Last updated
Was this helpful?
Apache ZooKeeper是一个为分布式应用所设计的开源协调服务,其设计目的是为了减轻分布式应用程序所承担的协调任务。它可以为用户提供同步、配置管理、分组和命名等服务。在这里,对ZooKeeper的完全分布式集群安装部署进行介绍。
一、基本环境
JDK :1.7.0_75(要求1.6+)
ZooKeeper:3.4.12
主机数:3
(要求3+,且必须是奇数,因为ZooKeeper的选举算法)
主机名
IP地址
JDK
ZooKeeper
myid
god.cn
192.168.127.87
1.7.0_75
server.1
1
obd.cn
192.168.127.99
1.7.0_75
server.2
2
mod.cn
192.168.127.101
1.7.0_75
server.3
3
二、master节点上安装配置 下载地址:
1、下载并解压ZooKeeper-3.4.12.tar.gz
这里路径为
/usr/local/zookeeper-3.4.12
2、设置the Java heap size
(个人感觉一般不需要配置)
保守地use a maximum heap size of 3GB for a 4GB machine
3、$ZOOKEEPER_HOME/conf/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/fesh/data/zookeeper
# the port at which the clients will connect
clientPort=2181
server.1=god.cn:2888:3888 #(主机名、心跳端口、数据端口)
server.2=obd.cn:2888:3888
server.3=mod.cn:2888:3888
4、/usr/local/data/zookeeper/myid
在节点配置的dataDir指定的目录下面,创建一个myid文件,里面内容为一个数字,用来标识当前主机,$ZOOKEEPER_HOME/conf/zoo.cfg文件中配置的server.X,则myid文件中就输入这个数字X。(即在每个节点上新建并设置文件myid,其内容与zoo.cfg中的id相对应)这里god.cn节点为 1
5、设置日志conf/log4j.properties
改为
将
改为---每天一个log日志文件,而不是在同一个log文件中递增日志
在改为DailyRollingFileAppender同时,需要注释log4j.appender.ROLLINGFILE.MaxFileSize,这个属性是RollingFileAppender
bin/zkEvn.sh
改为
参考:Zookeeper运维的一些经验
三、从god.cn节点分发文件到其他节点
1、在god.cn节点的/usr/local/目录下
2、在obd.cn节点的/usr/local/目录下
修改为 2
3、在mod.cn节点的/usr/local/目录下
修改为3
四、其他配置
1、在每个节点配置/etc/hosts (并保证每个节点/etc/hostname中分别为god.cn、obd.cn、mod.cn) 主机 -IP地址映射
2、在每个节点配置环境变量/etc/profile
五、启动
在每个节点上$ZOOKEEPER_HOME目录下,运行 (这里的启动顺序为 master > slave1 > slave2 )
并用命令查看启动状态
god.cn节点
obd.cn节点
mod.cn节点
zookeeper启动、停止相关命令: