CentOS7 安装 zookeeper

ZooKeeper的安装模式分为三种,分别为:单机模式(stand-alone)、集群模式和集群伪分布模式。

一、下载zookeeper

下载zookeeper到/home/hadoop,并且解压

wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
tar -zxvf zookeeper-3.4.3.tar.gz


二、设置环境变量

修改/etc/profile文件,添加下列红色部分

ZOOKEEPER_HOME=/home/hadoop/zookeeper-3.4.6
JAVA_HOME=/usr/java/jdk1.7.0_17
JRE_HOME=/usr/java/jdk1.7.0_17/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$ZOOKEEPER_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$ZOOKEEPER_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH ZOOKEEPER_HOME


将zookeeper-3.3.6/conf目录下面的 zoo_sample.cfg修改为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=/tmp/zookeeper
# the port at which the clients will connect
#clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
 
  
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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.1=192.168.116.20:12887:13887
server.2=192.168.116.21:12887:13887
server.3=192.168.116.22:12887:13887

#server.A=B:C:D

#A是一个数字,表示这个是第几号服务器,B是这个服务器的ip地址,C第一个端口用来集群成员的信息交换,表示的是这个服务器与集群中的Leader服务器交换信息的端口



 
  

三、创建ServerID标识

集群模式下还要配置一个文件myid,这个文件在dataDir目录下,这个就是配置文件,值为server.A=B:C:D的A值

四、启动Zookeeper 

[root@localhost bin]# netstat -at|grep 2181  --查看Zookeeper 端口
[root@localhost bin]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 192.168.116.141:22      192.168.116.1:59763     ESTABLISHED
tcp        0      0 192.168.116.141:22      192.168.116.1:60221     ESTABLISHED
tcp        0     96 192.168.116.141:22      192.168.116.1:59738     ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
[root@localhost bin]# ./zkServer.sh start  --启动Zookeeper 
JMX enabled by default
Using config: /home/hadoop/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost bin]# jps  --查看Zookeeper 服务进程,名称为QuorumPeerMain。
3535 Jps
3518 QuorumPeerMain
[root@localhost bin]# ./zkServer.sh stop

五、查看状态

[root@localhost bin]# ./zkServer.sh status
JMX enabled by default
Using config: /home/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader



你可能感兴趣的:(Java,dubbo)