ZooKeeper实践三:伪集群安装

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

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

#tar zxvf zookeeper-3.4.5.tar.gz

配置ZooKeeper
1)分别创建数据目录

#mkdir /var/zookeeperdata1
#mkdir /var/zookeeperdata2
#mkdir /var/zookeeperdata3

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

#echo "1" > /var/zookeeperdata1/myid
#echo "2" > /var/zookeeperdata2/myid
#echo "3" > /var/zookeeperdata3/myid

3)分别修改配置文件

#cd /usr/zookeeper-3.4.5/conf
#cp zoo_sample.cfg  zk1.cfg    
#vi zk1.cfg
    tickTime=2000
    initLinmit=10
    syncLimit=5
    dataDir=/var/zookeeperdata1    
    clientPort=2181          
    server.1=server IP:2888:3888
    server.2=server IP:2889:3889
    server.3=server IP:2890:3890

#cp zoo_sample.cfg  zk2.cfg  
#vi zk2.cfg
    tickTime=2000
    initLinmit=10
    syncLimit=5
    dataDir=/var/zookeeperdata2   
    clientPort=2182      
    server.1=server IP:2888:3888
    server.2=server IP:2889:3889
    server.3=server IP:2890:3890
#cp zoo_sample.cfg  zk3.cfg  
#vi zk3.cfg
    tickTime=2000
    initLinmit=10
    syncLimit=5
    dataDir=/var/zookeeperdata3   
    clientPort=2183          
    server.1=server IP:2888:3888
    server.2=server IP:2889:3889
    server.3=server IP:2890:3890

dataDir分别指向各自数据目录,clientPort使用不同端口。
增加集群实例到配置文件中,server.X中”X”表示每个数据目录中的myid的值,server也使用不同端口。

4)设置ZooKeeper环境变量(可选操作,方便操作,推荐配置)

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

分别启动ZooKeeper
需要指定配置文件

#zkServer.sh start zk1.cfg
#zkServer.sh start zk2.cfg
#zkServer.sh start zk3.cfg

查看运行状态
需要指定配置文件

#zkServer.sh status zk1.cfg
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zk1.cfg
Mode: leader
#zkServer.sh status zk2.cfg
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zk2.cfg
Mode: follower
#zkServer.sh status zk3.cfg
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zk3.cfg
Mode: follower

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

查看ZooKeeper物理文件目录结构

#tree –L 3 /var/zookeeperdata1
 /var/zookeeperdata1
├── myid
├── version-2
│   ├── acceptedEpoch
│   ├── currentEpoch
│   └── snapshot.0
└── zookeeper_server.pid
#tree –L 3 /var/zookeeperdata2
 /var/zookeeperdata2
├── myid
├── version-2
│   ├── acceptedEpoch
│   ├── currentEpoch
│   └── snapshot.0
└── zookeeper_server.pid
#tree –L 3 /var/zookeeperdata3
 /var/zookeeperdata3
├── myid
├── version-2
│   ├── acceptedEpoch
│   ├── currentEpoch
│   └── snapshot.0
└── zookeeper_server.pid

停止ZooKeeper

#zkServer.sh stop zk1.cfg
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zk1.cfg
Stooping zookeeper … STOPPED
#zkServer.sh stop zk2.cfg
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zk2.cfg
Stooping zookeeper … STOPPED
#zkServer.sh stop zk3.cfg
JMX enabled by default
Using config: /usr/zookeeper-3.4.5/bin/../conf/zk3.cfg
Stooping zookeeper … STOPPED
posted @ 2015-02-10 22:04  Rickesy  阅读(150)  评论(0编辑  收藏  举报