zookeeper搭建
一、安装准备
1. 三台虚拟机
2. jdk环境准备
二、下载zookeeper、解压
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz tar -zxvf zookeeper-3.4.13.tar.gz
三、配置环境变量
vim /etc/profile ## zookeeper export ZK_HOME=/usr/local/zookeeper-3.4.13 export PATH=$ZK_HOME/bin:$PATH source /etc/profile
四、配置zookeeper的配置文件
配置文件地址:/usr/local/zookeeper-3.4.13/conf
cp zoo_sample.cfg zoo.cfg ## 配置文件修改部分 dataDir=/usr/local/zookeeper-3.4.13/data/ server.1=kyle1:2888:3888 server.2=kyle2:2888:3888 server.3=kyle3:2888:3888
解释:
server.X=A:B:C
X-代表服务器编号
A-代表ip
B和C-代表端口,这个端口用来系统之间通信 (2888:connect to other peers 。3888:another port for leader election)
五、根据datadir配置X
1. 新建 data 文件夹
/usr/local/zookeeper-3.4.13/data
2. 文件夹里面创建 myid 文件
[root@kyle1 data]# vim myid [root@kyle1 data]# cat myid 1
3. 在对应的机器上填写对应的X的值
六、启动服务器
1. 刷新环境变量
2. 关闭对应端口的防火墙
[root@kyle1 zookeeper-3.4.13]# source /etc/profile [root@kyle1 zookeeper-3.4.13]# firewall-cmd --zone=public --add-port=2888/tcp --permanent success [root@kyle1 zookeeper-3.4.13]# firewall-cmd --zone=public --add-port=3888/tcp --permanent success
systemctl restart firewalld
3. 启动
zkServer.sh start
ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper-3.4.13/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
问题:
1、启动之后, zkServer.sh status 提示 :Error contacting service. It is probably not running。
这是因为启动了只启动了一个节点。启动完成三个节点就好了。
2018-11-17 19:49:27,286 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer$QuorumServer@184] - Resolved hostname: 192.168.0.111 to address: /192.168.0.111 2018-11-17 19:49:27,287 [myid:1] - WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@584] - Cannot open channel to 3 at election address /192.168.0.112:3888 java.net.ConnectException: 拒绝连接 (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:558) at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:610) at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:838) at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:957)