zookeeper集群的搭建
1. 下载解压zookeeper
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
tar -zxvf zookeeper-3.4.9.tar.gz
2. 安装配置
2.1 将zookeeper拷贝到/usr/local/solrcloud下,复制三份分别并将目录名改为zookeeper1、zookeeper2、zookeeper3
mkdir /usr/local/solrcloud
cp -r zookeeper-3.4.9 /usr/local/solrcloud/zookeeper1
cp -r zookeeper-3.4.9 /usr/local/solrcloud/zookeeper2
cp -r zookeeper-3.4.9 /usr/local/solrcloud/zookeeper3
2.2 进入zookeeper1文件夹,创建data目录。并在data目录中创建一个myid文件内容为“1”(echo 1 >> data/myid)。
mkdir /usr/local/solrcloud/zookeeper1/data
cd /usr/local/solrcloud/zookeeper1/data
echo 1 >> myid
//同理去处理z2,和z3
mkdir /usr/local/solrcloud/zookeeper2/data
mkdir /usr/local/solrcloud/zookeeper3/data
cd /usr/local/solrcloud/zookeeper2/data
echo 2 >> myid
cd /usr/local/solrcloud/zookeeper3/data
echo 3 >> myid
2.3 进去zookeeper1/conf文件夹,把zoo_sample.cfg改名为zoo.cfg
cd /usr/local/solrcloud/zookeeper1/conf
mv zoo_sample.cfg zoo.cfg
修改它们的zoo.cfg
dataDir=/usr/local/solrcloud/zookeeper1/data
clientPort=2181(zookeeper2中为2182、zookeeper3中为2183)
添加:
server.1=192.168.1.105:2881:3881
server.2=192.168.1.105:2882:3882
server.3=192.168.1.105:2883:3883
vim /usr/local/solrcloud/zookeeper1/conf/zoo.cfg
复制两份到z2,z3
cd /usr/local/solrcloud/zookeeper1/conf/
cp -f zoo.cfg /usr/local/solrcloud/zookeeper2/conf/
cp -f zoo.cfg /usr/local/solrcloud/zookeeper3/conf/
编辑其他两个zoo.cfg
vim /usr/local/solrcloud/zookeeper2/conf/zoo.cfg
vim /usr/local/solrcloud/zookeeper3/conf/zoo.cfg
2.4 启动三个zookeeper
/usr/local/solrcloud/zookeeper1/bin/zkServer.sh start
/usr/local/solrcloud/zookeeper2/bin/zkServer.sh start
/usr/local/solrcloud/zookeeper3/bin/zkServer.sh start
2.5 开启zookeeper用到的端口,或者直接关闭防火墙
//三个客户端端口,如果是真集群就不用改端口了,IP不一样就行了
firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --zone=public --add-port=2182/tcp --permanent
firewall-cmd --zone=public --add-port=2183/tcp --permanent
//下面三个是表示这个服务器与集群中的 Leader 服务器交换信息的端口
firewall-cmd --zone=public --add-port=2881/tcp --permanent
firewall-cmd --zone=public --add-port=2882/tcp --permanent
firewall-cmd --zone=public --add-port=2883/tcp --permanent
//下面三个是表示万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口
firewall-cmd --zone=public --add-port=3881/tcp --permanent
firewall-cmd --zone=public --add-port=3882/tcp --permanent
firewall-cmd --zone=public --add-port=3883/tcp --permanent
//重新加载
firewall-cmd --reload
3. 查看他们的状态
/usr/local/solrcloud/zookeeper1/bin/zkServer.sh status
/usr/local/solrcloud/zookeeper2/bin/zkServer.sh status
/usr/local/solrcloud/zookeeper3/bin/zkServer.sh status