CentOS 6学习笔记(十三)–CentOS6环境搭建ZooKeeper集群
安装 ZooKeeper 单机版
建议阅读我之前发布的笔记:
CentOS 6学习笔记(六)–CentOS6环境安装ZooKeeper
搭建 ZooKeeper 集群
本笔记通过在单台服务器上运行 3 个 ZooKeeper 实例的方式来模拟 ZooKeeper 集群。
本篇笔记是为后续搭建 SolrCloud 做准备。
创建 ZooKeeper 实例
mkdir /usr/local/solr-cloud
cp -r zookeeper-3.4.6 /usr/local/solr-cloud/zookeeper01
cp -r zookeeper-3.4.6 /usr/local/solr-cloud/zookeeper02
cp -r zookeeper-3.4.6 /usr/local/solr-cloud/zookeeper03
配置 ZooKeeper 实例
配置实例 1
cd /usr/local/solr-cloud/zookeeper01
mkdir data
cd /usr/local/solr-cloud/zookeeper01/data
echo 1 >myid
cd /usr/local/solr-cloud/zookeeper01/conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
在 zoo.cfg 配置以下内容
dataDir=/usr/local/solr-cloud/zookeeper01/data
#ZooKeeper提供服务的端口
clientPort=2181
#2881 2882 2883是节点之间内部通信的端口
#3881 3882 3883是节点之间投票选举的端口
server.1=192.168.25.155:2881:3881
server.2=192.168.25.155:2882:3882
server.3=192.168.25.155:2883:3883
配置实例 2
cd /usr/local/solr-cloud/zookeeper02
mkdir data
cd /usr/local/solr-cloud/zookeeper02/data
echo 2 >myid
cd /usr/local/solr-cloud/zookeeper02/conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
在 zoo.cfg 配置以下内容
dataDir=/usr/local/solr-cloud/zookeeper02/data
clientPort=2182
server.1=192.168.25.155:2881:3881
server.2=192.168.25.155:2882:3882
server.3=192.168.25.155:2883:3883
配置实例 3
cd /usr/local/solr-cloud/zookeeper03
mkdir data
cd /usr/local/solr-cloud/zookeeper03/data
echo 3 >myid
cd /usr/local/solr-cloud/zookeeper03/conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
在 zoo.cfg 配置以下内容
dataDir=/usr/local/solr-cloud/zookeeper03/data
clientPort=2183
server.1=192.168.25.155:2881:3881
server.2=192.168.25.155:2882:3882
server.3=192.168.25.155:2883:3883
使用
编写脚本文件启动 ZooKeeper 集群
vim /usr/local/solr-cloud/start-zk-all.sh
cd /usr/local/solr-cloud/zookeeper01/bin
./zkServer.sh start
cd /usr/local/solr-cloud/zookeeper02/bin
./zkServer.sh start
cd /usr/local/solr-cloud/zookeeper03/bin
./zkServer.sh start
修改权限
cd /usr/local/solr-cloud
chmod u+x start-zk-all.sh
开启 ZooKeeper 集群
/usr/local/solr-cloud/start-zk-all.sh
查看状态
/usr/local/solr-cloud/zookeeper01/bin/zkServer.sh status
/usr/local/solr-cloud/zookeeper02/bin/zkServer.sh status
/usr/local/solr-cloud/zookeeper03/bin/zkServer.sh status
编写脚本文件关闭 ZooKeeper 集群
vim /usr/local/solr-cloud/shutdown-zk-all.sh
cd /usr/local/solr-cloud/zookeeper01/bin
./zkServer.sh stop
cd /usr/local/solr-cloud/zookeeper02/bin
./zkServer.sh stop
cd /usr/local/solr-cloud/zookeeper03/bin
./zkServer.sh stop
修改权限
cd /usr/local/solr-cloud
chmod u+x shutdown-zk-all.sh
关闭 ZooKeeper 集群
/usr/local/solr-cloud/shutdown-zk-all.sh
维护指令总结
#开启 ZooKeeper 集群
/usr/local/solr-cloud/start-zk-all.sh
#查看状态
/usr/local/solr-cloud/zookeeper01/bin/zkServer.sh status
/usr/local/solr-cloud/zookeeper02/bin/zkServer.sh status
/usr/local/solr-cloud/zookeeper03/bin/zkServer.sh status
#关闭 ZooKeeper 集群
/usr/local/solr-cloud/shutdown-zk-all.sh
开机自启
vim /etc/rc.d/rc.local
添加
/usr/local/solr-cloud/start-zk-all.sh