ZooKeeper实践二:集群安装

系统环境(本次环境)
准备三台Linux服务器,系统要求如下:
Linux: CentOS 6.5 64bit Server
Java: 1.7.0_60 64-Bit Server VM
ZooKeeper 使用Java语言编写,运行环境需要Java环境支持,建议使用JDK1.6以上版本。Java环境请自行配置。给三台服务器各自配置IP。

下载ZooKeeper
在每一个服务器上下载ZooKeeper,本次使用的版本:zookeeper-3.4.5.tar.gz
将安装文件解压至某一目录:/usr/zookeeper-3.4.5

#tar zxvf zookeeper-3.4.5.tar.gz

配置ZooKeeper
1)三台服务器分别创建数据目录

Server1: #mkdir /var/zookeeperdata
Server2: #mkdir /var/zookeeperdata
Server3: #mkdir /var/zookeeperdata

2)分别在在数据目录中创建myid文件,并添加id值

Server1: #echo "1" > /var/zookeeperdata/myid
Server2: #echo "2" > /var/zookeeperdata/myid
Server3: #echo "3" > /var/zookeeperdata/myid

3)分别修改配置文件

Server1: #cd /usr/zookeeper-3.4.5/conf
Server1: #cp zoo_sample.cfg  zoo.cfg    
Server1: #vi zoo.cfg
    tickTime=2000
    initLinmit=10
    syncLimit=5
    dataDir=/var/zookeeperdata    
    clientPort=2181          
    server.1=server1 IP:2888:3888
    server.2=server2 IP:2888:3888
    server.3=server3 IP:2888:3888
Server2: #cd /usr/zookeeper-3.4.5/conf
Server2: #cp zoo_sample.cfg  zoo.cfg  
Server2: #vi zoo.cfg
    tickTime=2000
    initLinmit=10
    syncLimit=5
    dataDir=/var/zookeeperdata   
    clientPort=2181          
    server.1=server1 IP:2888:3888
    server.2=server2 IP:2888:3888
    server.3=server3 IP:2888:3888
Server3: #cd /usr/zookeeper-3.4.5/conf
Server3: #cp zoo_sample.cfg  zoo.cfg  
Server3: #vi zoo.cfg
    tickTime=2000
    initLinmit=10
    syncLimit=5
    dataDir=/var/zookeeperdata   
    clientPort=2181          
    server.1=server1 IP:2888:3888
    server.2=server2 IP:2888:3888
    server.3=server3 IP:2888:3888

增加集群实例到配置文件中,server.X中”X”表示每个数据目录中的myid的值
4)分别设置ZooKeeper环境变量(可选操作,方便操作,推荐配置)

#vi /etc/profile
 export ZOOKEEPER_HOME=/usr/zookeeper-3.4.5
 export PATH=$PATH:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/conf

分别启动ZooKeeper

Server1: #zkServer.sh start
Server2: #zkServer.sh start
Server3: #zkServer.sh start

查看运行状态

Server1: #zkServer.sh status
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: leader
Server2: #zkServer.sh status
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower
Server3: #zkServer.sh status
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower

我们看到有一台Server为leader,其余为follower。

查看ZooKeeper物理文件目录结构

Server1: #tree –L 3 /var/zookeeperdata
 /var/zookeeperdata
├── myid
├── version-2
│   ├── acceptedEpoch
│   ├── currentEpoch
│   └── snapshot.0
└── zookeeper_server.pid
Server2: #tree –L 3 /var/zookeeperdata
 /var/zookeeperdata
├── myid
├── version-2
│   ├── acceptedEpoch
│   ├── currentEpoch
│   └── snapshot.0
└── zookeeper_server.pid
Server3: #tree –L 3 /var/zookeeperdata
 /var/zookeeperdata
├── myid
├── version-2
│   ├── acceptedEpoch
│   ├── currentEpoch
│   └── snapshot.0
└── zookeeper_server.pid

停止ZooKeeper

Server1: #zkServer.sh stop
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zoo.cfg
Stooping zookeeper … STOPPED
Server2: #zkServer.sh stop
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zoo.cfg
Stooping zookeeper … STOPPED
Server3: #zkServer.sh stop
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zoo.cfg
Stooping zookeeper … STOPPED
posted @ 2015-02-10 21:42  Rickesy  阅读(187)  评论(0编辑  收藏  举报