189 8069 5689

zookeeper集群安装

今天闲来无事,重新安装zookeeper 环境。由于个人有几台虚拟主机。总共四台服务器。

创新互联长期为近千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为八公山企业提供专业的成都网站设计、网站建设、外贸网站建设八公山网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。

其中选择三台做zookeeper集群。具体ip如下:

IP地址 主机名称 100.xx.xx.31 master 100.xx.xx.72 slave1 100.xx.xx.122 slave2

如合配置主机名,可以修改linux hosts文件。具体文件路径: /var/hosts,内容如下:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
100.xx.xx.31 xxxx-xxxx
100.xx.xx.31 master
100.xx.xx.72 slave1
100.xx.xx.122 slave2
~

修改完上述配置过后,下载zookeeper, 我下载的版本:zookeeper-3.4.9

下载完成,直接解压,zookeeper 目录结构:

drwxr-xr-x 10 1001 1001 4096 Aug 23 15:42 .
drwxr-xr-x 6 root root 4096 Dec 4 12:20 ..
drwxr-xr-x 2 1001 1001 4096 Dec 4 02:07 bin
-rw-rw-r-- 1 1001 1001 83539 Aug 23 15:39 build.xml
-rw-rw-r-- 1 1001 1001 90824 Aug 23 15:39 CHANGES.txt
drwxr-xr-x 2 1001 1001 4096 Dec 4 02:04 conf
drwxr-xr-x 10 1001 1001 4096 Aug 23 15:39 contrib
drwxr-xr-x 2 1001 1001 4096 Aug 23 15:44 dist-maven
drwxr-xr-x 6 1001 1001 4096 Aug 23 15:40 docs
-rw-rw-r-- 1 1001 1001 1953 Aug 23 15:39 ivysettings.xml
-rw-rw-r-- 1 1001 1001 3499 Aug 23 15:39 ivy.xml
drwxr-xr-x 4 1001 1001 4096 Aug 23 15:40 lib
-rw-rw-r-- 1 1001 1001 11938 Aug 23 15:39 LICENSE.txt
-rw-rw-r-- 1 1001 1001 171 Aug 23 15:39 NOTICE.txt
-rw-rw-r-- 1 1001 1001 1770 Aug 23 15:39 README_packaging.txt
-rw-rw-r-- 1 1001 1001 1585 Aug 23 15:39 README.txt
drwxr-xr-x 5 1001 1001 4096 Aug 23 15:39 recipes
drwxr-xr-x 8 1001 1001 4096 Aug 23 15:40 src
-rw-rw-r-- 1 1001 1001 1368238 Aug 23 15:39 zookeeper-3.4.9.jar
-rw-rw-r-- 1 1001 1001 819 Aug 23 15:42 zookeeper-3.4.9.jar.asc
-rw-rw-r-- 1 1001 1001 33 Aug 23 15:39 zookeeper-3.4.9.jar.md5
-rw-rw-r-- 1 1001 1001 41 Aug 23 15:39 zookeeper-3.4.9.jar.sha1

找到conf 目录

cpzoo_sample.cfg zoo.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=/var/work/data/zookeeper
# the port at which the clients will connect
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=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
~

根据需要调整你要修改标好的配置。

需要说明下zookeeper 几个端口的意思:

zookeeper监听三个端口: 2181用来监听zookeeper客户端连接, 2888,如果是领导者, 用来监听跟随者连接, 3888用来在选举领导者阶段, 用来监听其他服务器的连接。

配置文件修改完成后,需要创建myid 文件,myid 文件存在data目录下,本次安装data目录:/var/work/data/zookeeper

根据zoo.cfg 配置,分别在不同server 上myid写入:1,2,3 。

ok, 基本搞定,接下来启动zookeeper .

[root@xxxx bin]# ./zkServer.sh start

停用zookeeper

[root@xxxxbin]# ./zkServer.sh stoo

大功告成,下次我们再分享zookeeper 详细配置。


文章标题:zookeeper集群安装
文章源于:http://cdxtjz.cn/article/cjodih.html

其他资讯