zookerper安装部署

********************单节点安装zk*************************
上传zk安装包到服务器/mnt目录下:

[root@chavin ~]$ ll /mnt/zookeeper-3.4.5.tar.gz
-rw-r--r--. 1 root root 16402010 Mar 11 15:33 /mnt/zookeeper-3.4.5.tar.gz

解压安装文件并更改权限:

[root@chavin mnt]$ tar -zxvf zookeeper-3.4.5.tar.gz -C /usr/local/
[root@chavin zookeeper-3.4.5]$ cd /usr/local/
[root@chavin local]$ chown -R hadoop:hadoop zookeeper-3.4.5/

编辑配置文件:
[hadoop@chavin zookeeper-3.4.5]$ mkdir -p data/zkdata
[hadoop@chavin zookeeper-3.4.5]$ cd data/zkdata/
[hadoop@chavin zkdata]$ pwd
/usr/local/zookeeper-3.4.5/data/zkdata
[hadoop@chavin zkdata]$ cd ../../conf/
[hadoop@chavin conf]$ cp zoo_sample.cfg zoo.cfg
[hadoop@chavin conf]$ cat 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目录##################################
dataDir=/usr/local/zookeeper-3.4.5/data/zkdata
###############################################配置dataDir目录##################################
# 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

启动zkserver:

[hadoop@chavin zookeeper-3.4.5]$ bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@chavin zookeeper-3.4.5]$ jps
55039 QuorumPeerMain
55058 Jps

[hadoop@chavin zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: standalone
[hadoop@chavin zookeeper-3.4.5]$ bin/zkCli.sh
Connecting to localhost:2181
... ...

至此,单节点zk服务器安装完成.

********************************集群模式安装zk****************************************

上传zk安装包到节点1的/mnt目录下:
[root@db01 ~]# cd /mnt
[root@db01 mnt]# ll zookeeper-3.4.5.tar.gz
-rw-r--r--. 1 root root 16402010 Mar 11 23:35 zookeeper-3.4.5.tar.gz


解压安装文件并更改权限:

[root@chavin mnt]$ tar -zxvf zookeeper-3.4.5.tar.gz -C /usr/local/
[root@chavin zookeeper-3.4.5]$ cd /usr/local/
[root@chavin local]$ chown -R hadoop:hadoop zookeeper-3.4.5/


编辑配置文件:
[hadoop@chavin zookeeper-3.4.5]$ mkdir -p data/zkdata
[hadoop@chavin zookeeper-3.4.5]$ cd data/zkdata/
[hadoop@chavin zkdata]$ pwd
/usr/local/zookeeper-3.4.5/data/zkdata
[hadoop@chavin zkdata]$ cd ../../conf/
[hadoop@chavin conf]$ cp zoo_sample.cfg zoo.cfg
[root@db01 conf]# cat 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.
#######################cluster#########################################
dataDir=/usr/local/zookeeper-3.4.5/data/zkdata
server.1=db01:2888:3888
server.2=db02:2888:3888
server.3=db03:2888:3888
server.4=db04:2888:3888
server.5=db05:2888:3888
#######################cluster#########################################
# 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
[root@db01 conf]#

编辑myid文件:

[root@db01 zkdata]# pwd
/usr/local/zookeeper-3.4.5/data/zkdata
[root@db01 zkdata]# touch myid
[root@db01 zkdata]# vim myid
[root@db01 zkdata]# cat myid
1

同步安装目录:

[root@db01 local]# scp -r zookeeper-3.4.5/ db02:/usr/local/
[root@db01 local]# scp -r zookeeper-3.4.5/ db03:/usr/local/
[root@db01 local]# scp -r zookeeper-3.4.5/ db04:/usr/local/
[root@db01 local]# scp -r zookeeper-3.4.5/ db05:/usr/local/

修改相应用户所有者权限:

[root@db01 local]# chown -R hadoop:hadoop zookeeper-3.4.5/
[root@db02 local]# chown -R hadoop:hadoop zookeeper-3.4.5/
[root@db03 local]# chown -R hadoop:hadoop zookeeper-3.4.5/
[root@db04 local]# chown -R hadoop:hadoop zookeeper-3.4.5/
[root@db05 local]# chown -R hadoop:hadoop zookeeper-3.4.5/

修改各个服务器的myid文件:

db01      1
db02      2
db03      3
db04      4
db05      5

分别启动zk集群服务器:

[hadoop@db01 zookeeper-3.4.5]$ bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[hadoop@db02 zookeeper-3.4.5]$ bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[hadoop@db03 zookeeper-3.4.5]$ bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[hadoop@db04 zookeeper-3.4.5]$ bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[hadoop@db05 zookeeper-3.4.5]$ bin/zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

查看各个节点状态:

[hadoop@db01 zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower

[hadoop@db02 zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower

[hadoop@db03 zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: leader

[hadoop@db04 zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower

[hadoop@db05 zookeeper-3.4.5]$ bin/zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower

posted @ 2017-03-31 16:37  ChavinKing  阅读(1092)  评论(0编辑  收藏  举报