zookeeper集群搭建

一台服务其中利用不同端口搭建zookeeper集群,三个zookeeper实例,请在配置好jdk环境前提下操作

 

1 将zookeeper上传到服务器。
2 解压缩tar -zxf zookeeper-3.4.10.tar.gz
3 在/usr/local/目录下创建一个solrcloud目录。把zookeeper解压后的文件夹复制到此目录下三份。分别命名为zookeeper1、2、3
[root@bogon ~]# mkdir /usr/local/solrcloud

[root@bogon ~]# mv zookeeper-3.4.6 /usr/local/solrcloud/zookeeper1

[root@bogon ~]# cd /usr/local/solrcloud

[root@bogon solrcloud]# ll

total 4

drwxr-xr-x. 10 1000 1000 4096 Feb 20  2014 zookeeper1

[root@bogon solrcloud]# cp -r zookeeper1/ zookeeper2

[root@bogon solrcloud]# cp -r zookeeper1/ zookeeper3

[root@bogon solrcloud]#
4 配置zookeeper。

1、在每个zookeeper文件夹下创建一个data目录。

2、在data文件夹下创建一个文件名称为myid,文件的内容就是此zookeeper的编号1、2、3

cd zk1/data/
touch myid
echo 1 > myid 

  

3、把每个下conf目录下的zoo_sample.cfg文件复制一份改名为zoo.cfg

分别按如下修改配置

zookeeper1

# 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
dataDir=/opt/SolrCloudZookeeper/zookeeper1/data
# the port at which the clients will connect
clientPort=2181
server.1=192.168.10.131:2881:3881
server.2=192.168.10.131:2882:3882
server.3=192.168.10.131:2883:3883
# 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

 

 

zookeeper2

# 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
dataDir=/opt/SolrCloudZookeeper/zookeeper2/data
# the port at which the clients will connect
clientPort=2182
server.1=192.168.10.131:2881:3881
server.2=192.168.10.131:2882:3882
server.3=192.168.10.131:2883:3883
# 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

 

 

zookeeper3

# 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
dataDir=/opt/SolrCloudZookeeper/zookeeper3/data
# the port at which the clients will connect
clientPort=2183
server.1=192.168.10.131:2881:3881
server.2=192.168.10.131:2882:3882
server.3=192.168.10.131:2883:3883
# 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

#修改dataDir,指向data目录

dataDir=/usr/local/solr-cloud/zookeeper03/data/

#solr的通讯端口(集群中不能重复)

clientPort=2184

 

#第一个端口为通讯端口,第二个为投票选举端口

server.1=192.168.31.241:2887:3887

server.2=192.168.31.241:2888:3888

server.3=192.168.31.241:2889:3889 

5 启动zookeeper。

进入zookeeper1/bin目录下。

./zkServer.sh start  //启动zookeeper
./zkServer.sh start-foreground //(可以查看启动日志,ctrl+c退出后自动关闭zookeeper) 

./zkServer.sh stop //关闭

./zkServer.sh status//查看状态

  

  

状态信息如下,代表启动成功

[root@bogon solrcloud]# zookeeper1/bin/zkServer.sh status

JMX enabled by default

Using config: /usr/local/solrcloud/zookeeper1/bin/../conf/zoo.cfg

Mode: follower

[root@bogon solrcloud]# zookeeper2/bin/zkServer.sh status

JMX enabled by default

Using config: /usr/local/solrcloud/zookeeper2/bin/../conf/zoo.cfg

Mode: leader

[root@bogon solrcloud]# zookeeper3/bin/zkServer.sh status

JMX enabled by default

Using config: /usr/local/solrcloud/zookeeper3/bin/../conf/zoo.cfg

Mode: follower

[root@bogon solrcloud]#

 

配置集群统一启动批处理
cd zookeeper01/bin
./zkServer.sh start
cd ../../
cd zookeeper02/bin
./zkServer.sh start
cd ../../
cd zookeeper03/bin
./zkServer.sh start

 

posted @ 2018-08-24 14:25  wdmiye  阅读(173)  评论(0编辑  收藏  举报