在centos6.5中安裝zookeeper集羣

簡介html

 ZooKeeper服務器是用Java編寫建立,它運行在JVM。因此須要使用JDK 6或更高版本,在這裏就不說在centos安裝jdk環境了,直接進入正題,我搭建的是java

192.168.0.2,linux

192.168.0.4,git

192.168.0.5,三臺機器上的zookeeper集羣,下面演示的是,192.168.0.4的搭建過程,其它兩臺機器相似apache

一、首先我/usr/software/目錄下有zookeeper-3.4.5.tar.gz源碼包vim

[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

二、把源碼包解壓到/usr/local/路徑下,並修改文件名稱centos

[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

三、進入到zookeeper的conf目錄下,將zoo_sample.cfg這個文件複製爲zoo.cfg(必須是這個文件)tomcat

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

四、修改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

五、在zookeeper目錄下創建個新文件夾data(不建啓動zookeeper會報錯ide

[root@jacky zookeeper]# mkdir data

六、在data目錄下新建文件myid,文件內容爲0,與server.0相對應

[root@jacky data]# vim myid

七、配置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文件

到這裏集羣就搭建完成了

八、啓動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]# 
相關文章
相關標籤/搜索