首页 > 代码库 > zookeeper的高可用部署
zookeeper的高可用部署
说明:zookeeper是一个服务注册中心
2. zookeeper的部署
2.1 三台主机
192.168.56.15 192.168.56.16 192.168.56.17 [root@zk01 ~]# cat /etc/hosts 192.168.56.15 zk01 192.168.56.16 zk02 192.168.56.17 zk03
2.2 java环境
[root@zk01 ~]# java -version java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode) [root@zk01 ~]#
2.3 做成这样的
[root@zk01 ~]# cd /opt [root@zk01 opt]# ll total 8 lrwxrwxrwx 1 root root 11 Dec 25 01:24 jdk -> jdk1.7.0_80 drwxr-xr-x 8 10 143 4096 Apr 11 2015 jdk1.7.0_80 drwxr-xr-x 2 root root 61 Dec 25 01:30 tools lrwxrwxrwx 1 root root 15 Dec 25 01:29 zk01 -> zookeeper-3.4.9 drwxr-xr-x 12 1001 1001 4096 Dec 25 01:39 zookeeper-3.4.9 [root@zk01 opt]#
2.4 修改zookeeper配置文件(zk01)
[root@zk01 conf]# pwd /opt/zk01/conf cp zoo_sample.cfg zoo.cfg vi zoo.cfg dataDir=/opt/zk01/datadir dataLogDir=/opt/zk01/datalog #自己加的 server.1=192.168.56.15:2888:3888 server.2=192.168.56.16:2888:3888 server.3=192.168.56.17:2888:3888 mkdir /opt/zk01/datadir mkdir /opt/zk01/datalog [root@zk01 datadir]# cat myid 1 [root@zk01 datadir]# pwd /opt/zk01/datadir [root@zk01 datadir]#
2.5 修改zookeeper配置文件(zk02)
[root@zk02 conf]# pwd /opt/zk02/conf cp zoo_sample.cfg zoo.cfg vi zoo.cfg dataDir=/opt/zk02/datadir dataLogDir=/opt/zk02/datalog #自己加的 server.1=192.168.56.15:2888:3888 server.2=192.168.56.16:2888:3888 server.3=192.168.56.17:2888:3888 mkdir /opt/zk02/datadir mkdir /opt/zk02/datalog [root@zk02 datadir]# cat myid 2 [root@zk02 datadir]# pwd /opt/zk03/datadir [root@zk02 datadir]#
2.6 修改zookeeper配置文件(zk03)
[root@zk03 conf]# pwd /opt/zk03/conf cp zoo_sample.cfg zoo.cfg vi zoo.cfg dataDir=/opt/zk03/datadir dataLogDir=/opt/zk03/datalog #自己加的 server.1=192.168.56.15:2888:3888 server.2=192.168.56.16:2888:3888 server.3=192.168.56.17:2888:3888 mkdir /opt/zk03/datadir mkdir /opt/zk03/datalog [root@zk03 datadir]# cat myid 3 [root@zk03 datadir]# pwd /opt/zk03/datadir [root@zk03 datadir]#
2.7 启动zookeeper服务
按照顺序zk01 zk02 zk03的顺序
依次启动zookeeper服务
[root@zk01 bin]# pwd /opt/zk01/bin [root@zk01 bin]# ./zkServer.sh start
2.8 验证服务是否正常(每个都要验证下)
[root@zk01 bin]# ./zkCli.sh -server 192.168.56.15:2181 正常状态 [root@zk01 bin]# ./zkCli.sh -server 192.168.56.15:2181 Connecting to 192.168.56.15:2181 2016-12-25 02:11:10,892 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT 2016-12-25 02:11:10,900 [myid:] - INFO [main:Environment@100] - Client environment:host.name=zk01 2016-12-25 02:11:10,900 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_80 2016-12-25 02:11:10,905 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2016-12-25 02:11:10,905 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/opt/jdk1.7.0_80/jre 2016-12-25 02:11:10,906 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/zk01/bin/../build/classes:/opt/zk01/bin/../build/lib/*.jar:/opt/zk01/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zk01/bin/../lib/slf4j-api-1.6.1.jar:/opt/zk01/bin/../lib/netty-3.10.5.Final.jar:/opt/zk01/bin/../lib/log4j-1.2.16.jar:/opt/zk01/bin/../lib/jline-0.9.94.jar:/opt/zk01/bin/../zookeeper-3.4.9.jar:/opt/zk01/bin/../src/java/lib/*.jar:/opt/zk01/bin/../conf:.:/opt/jdk/lib:/opt/jdk/jre/lib:/opt/jdk/lib/tools.jar 2016-12-25 02:11:10,906 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2016-12-25 02:11:10,906 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2016-12-25 02:11:10,907 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2016-12-25 02:11:10,907 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2016-12-25 02:11:10,907 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2016-12-25 02:11:10,908 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-514.2.2.el7.x86_64 2016-12-25 02:11:10,908 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2016-12-25 02:11:10,908 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2016-12-25 02:11:10,909 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/zookeeper-3.4.9/bin 2016-12-25 02:11:10,918 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=192.168.56.15:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@2f49f848 Welcome to ZooKeeper! 2016-12-25 02:11:10,969 [myid:] - INFO [main-SendThread(192.168.56.15:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 192.168.56.15/192.168.56.15:2181. Will not attempt to authenticate using SASL (unknown error) 2016-12-25 02:11:10,975 [myid:] - INFO [main-SendThread(192.168.56.15:2181):ClientCnxn$SendThread@876] - Socket connection established to 192.168.56.15/192.168.56.15:2181, initiating session JLine support is enabled 2016-12-25 02:11:11,018 [myid:] - INFO [main-SendThread(192.168.56.15:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 192.168.56.15/192.168.56.15:2181, sessionid = 0x15931f6222c0002, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: 192.168.56.15:2181(CONNECTED) 0]
2.9查看每个服务器的状态信息
[root@zk01 bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/zk01/bin/../conf/zoo.cfg Mode: follower [root@zk01 bin]# [root@zk02 bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/zk02/bin/../conf/zoo.cfg Mode: leader [root@zk02 bin]# [root@zk03 bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/zk03/bin/../conf/zoo.cfg Mode: follower [root@zk03 bin]#
2.10 端口简介:
zookeepr 客户端的调用的端口是2181 在zoo.cfg中 server.1=192.168.56.15:2888:3888 2888 follower和 leader之间的通讯的端口 3888 是如果leader当机了 zookeeper服务器之间的选举的端口
本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1885812
zookeeper的高可用部署
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。