赞
踩
一、安装
cd /service
rz -e
tar zxvf zookeeper-3.4.6.tar.gz
cp ./zookeeper-3.4.6/conf/zoo_sample.cfg ./zookeeper-3.4.6/conf/zoo.cfg
二、修改配置
1、修改myid文件:
[root@h4 data]# pwd
/opt/zookeeper-3.4.5-cdh5.5.1/data
[root@h4 data]# more myid
4
[root@h4 data]#
mkdir -p /var/lib/zookeeper
touch /var/lib/zookeeper/myid
echo "1" >/var/lib/zookeeper/myid
cat /var/lib/zookeeper/myid
2、修改hosts配置: 以下ip地址换成实际部署的地址
server.0=192.168.1.100:2888:3888
server.1=192.168.1.101:2888:3888
server.2=192.168.1.102:2888:3888
以上不用修改hosts文件,直接在zoo.cfg文件下配置即可,要修改hosts也是可以的。
[root@beta-test-v5-zk01 ~]# cd /etc/
[root@beta-test-v5-zk01 etc]# vi hosts
#hosts文件内容如下
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.217.140 beta-test-v5-zk01.novalocal
192.168.217.140 zoo1
192.168.217.141 zoo2
192.168.217.142 zoo3
192.168.217.140 beta-test-v5-zk01
192.168.217.141 beta-test-v5-zk02
192.168.217.142 beta-test-v5-zk03
192.168.212.116 beta-test-V5-zk01
3、修改zookeeper配置文件路径:
vi /service/zookeeper-3.4.6/conf/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=/tmp/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 dataDir=/var/lib/zk/zookeeper dataLogDir=/var/lib/zk/logs server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
三、同样配置第二台和第三台
第二台机器:
mkdir -p /var/lib/zookeeper
touch /var/lib/zookeeper/myid
echo "2" >/var/lib/zookeeper/myid
cat /var/lib/zookeeper/myid
第三台机器:
mkdir -p /var/lib/zookeeper
touch /var/lib/zookeeper/myid
echo "3" >/var/lib/zookeeper/myid
cat /var/lib/zookeeper/myid
四、启动zookeeper 每台服务器各自启动
进入目录: /opt/zookeeper-3.4.5-cdh5.5.1
启动命令:sh bin/zkServer.sh start 回车后启动
查看状态:sh bin/zkServer.sh status 回车后返回本台服务器是leader还是follower 例如:
ZooKeeper JMX enabled by default
Using config: /service/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
----这样,说明启动正常
核心总结:zoo.cfg里面的ip配置,dataDir=/var/lib/zk/zookeeper
目录下myid的设置,zookeeper的运行依赖于jdk,在搭建之前需具备jdk环境。
参考链接
问题记录:
java.net.ConnectException: Connection refused
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at TCPClient.main(TCPClient.java:13)
原因分析:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。