在centos6.5中安装zookeeper集群

简介

 ZooKeeper服务器是用Java编写创建,它运行在JVM。所以需要使用JDK 6或更高版本,在这里就不说在centos安装jdk环境了,直接进入正题,我搭建的是

192.168.0.2,

192.168.0.4,

192.168.0.5,三台机器上的zookeeper集群,下面演示的是,192.168.0.4的搭建过程,其它两台机器类似

1、首先我/usr/software/目录下有zookeeper-3.4.5.tar.gz源码包

[root@jacky software]# ls -l
总用量 190220
-rw-r--r--. 1 root root   8938514 12月 30 11:06 apache-tomcat-7.0.73.tar.gz
-rw-r--r--. 1 root root  27768439 12月 30 11:18 dubbo-admin-2.8.4.war
-rw-r--r--. 1 root root   4885101 12月 29 21:29 git-2.0.0.tar.gz
-rw-r--r--. 1 root root 136775360 12月 28 22:31 jdk-7u80-linux-i586.rpm
-rw-r--r--. 1 root root  16402010 10月 25 19:57 zookeeper-3.4.5.tar.gz

2、把源码包解压到/usr/local/路径下,并修改文件名称

[root@jacky software]# tar -xvzf zookeeper-3.4.5.tar.gz -C /usr/local/
[root@jacky software]# cd /usr/local/
[root@jacky local]# mv zookeeper-3.4.5.tar.gz zookeeper

3、进入到zookeeper的conf目录下,将zoo_sample.cfg这个文件复制为zoo.cfg(必须是这个文件)

[root@jacky jacky]# cd /usr/local/zookeeper/conf
[root@jacky local]# mv zoo_sample.cfg zoo.cfg

4、修改zoo.cfg文件内容

# 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=/usr/local/zookeeper/data        #修改数据路径
# the port at which the clients will connect
clientPort=2181
#
# 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.0=192.168.0.2:2888:3888    #修改三台机器zookeeper集群
server.1=192.168.0.4:2888:3888
server.2=192.168.0.5:2888:3888

5、在zookeeper目录下建立个新文件夹data(不建启动zookeeper会报错

[root@jacky zookeeper]# mkdir data

6、在data目录下新建文件myid,文件内容为0,与server.0相对应

[root@jacky data]# vim myid

7、配置zookeeper环境变量

[root@jacky data]# vim /etc/profile

 在文件末尾加上

 export JAVA_HOME=/usr/java/jdk1.7.0_80
 export ZOOKEEPER_HOME=/usr/local/zookeeper
 export PATH=$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$PATH
 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

然后source /etc/profile文件

到这里集群就搭建完成了

8、启动192.168.0.4机器的zookeeper

[root@jacky conf]# zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... already running as process 13667.
[root@jacky conf]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@jacky conf]# 

 

posted @ 2016-12-30 00:33  坏~牧羊人  阅读(1723)  评论(0编辑  收藏  举报