zookeeper集群安装
zookeeper3.4.9 的tar包链接为https://pan.baidu.com/s/1bpqZ9bHgzeri53AWgW2L4Q 提取码:sbp0 永久有效。
实验之前准备工作:
zookeeper集群节点规划
三台测试机全部关闭防火墙,要是生产环境建议开放防火墙规则即可,不建议直接关闭防火墙。
每台主机重命名,方便互相之间的通讯联系。
以第一台为例:
vim /etc/sysconfig/network HOSTNAME=hadoop1
其它两台分别命令为 hadoop2和 hadoop3,最好重启生效。
做hosts主机记录中做域名解析,三台都一样
vim /etc/hosts 192.168.241.130 hadoop1 192.168.241.133 hadoop2 192.168.241.134 hadoop3
开始正式部署环境:
1:首先在第一台机器上(hadoop100)安装部署,上传安装包,解压
修改配置文件
tar xvf zookeeper-3.4.9.tar.gz mv zookeeper-3.4.9 zookeeper cd zookeeper/conf/ mv zoo_sample.cfg zoo.cfg
编辑配置文件。
vi conf/zoo.cfg dataDir=/usr/local/zookeeper/data server.0=hadoop1:2888:3888 server.1=hadoop2:2888:3888 server.2=hadoop3:2888:3888
解释说明:2888为通讯端口,3888为选举端口
2:把hadoop1上的zookeeper拷贝到其他两个节点
scp -rpq zookeeper hadoop2:/data/soft scp -rpq zookeeper hadoop3:/data/soft
3(注意):需要在集群中的每台机器下面创建一个myid文件 保存当前节点的编号信息
myid文件的位置在:${dataDir}参数配置目录下面。以第一台为例:
cd /data/soft/zookeeper mkdir data cd data vi myid 0 cat myid 0
文件的内容根据上面指定的每个节点对应的编号0,1,2
4:启动
分别在每个节点上都启动
sh bin/zkServer.sh start
此时查看文件信息目录内容
ll 总用量 1608 drwxr-xr-x. 2 1001 1001 4096 8月 23 2016 bin -rw-rw-r--. 1 1001 1001 83539 8月 23 2016 build.xml -rw-rw-r--. 1 1001 1001 90824 8月 23 2016 CHANGES.txt drwxr-xr-x. 2 1001 1001 4096 4月 19 10:19 conf drwxr-xr-x. 10 1001 1001 4096 8月 23 2016 contrib drwxr-xr-x. 3 root root 4096 4月 19 10:41 data drwxr-xr-x. 2 1001 1001 4096 8月 23 2016 dist-maven drwxr-xr-x. 6 1001 1001 4096 8月 23 2016 docs -rw-rw-r--. 1 1001 1001 1953 8月 23 2016 ivysettings.xml -rw-rw-r--. 1 1001 1001 3499 8月 23 2016 ivy.xml drwxr-xr-x. 4 1001 1001 4096 8月 23 2016 lib -rw-rw-r--. 1 1001 1001 11938 8月 23 2016 LICENSE.txt -rw-rw-r--. 1 1001 1001 171 8月 23 2016 NOTICE.txt -rw-rw-r--. 1 1001 1001 1770 8月 23 2016 README_packaging.txt -rw-rw-r--. 1 1001 1001 1585 8月 23 2016 README.txt drwxr-xr-x. 5 1001 1001 4096 8月 23 2016 recipes drwxr-xr-x. 8 1001 1001 4096 8月 23 2016 src -rw-rw-r--. 1 1001 1001 1368238 8月 23 2016 zookeeper-3.4.9.jar -rw-rw-r--. 1 1001 1001 819 8月 23 2016 zookeeper-3.4.9.jar.asc -rw-rw-r--. 1 1001 1001 33 8月 23 2016 zookeeper-3.4.9.jar.md5 -rw-rw-r--. 1 1001 1001 41 8月 23 2016 zookeeper-3.4.9.jar.sha1 -rw-r--r--. 1 root root 9280 4月 19 11:13 zookeeper.out
查看每台的服务状态
hadoop1的状态为foller
[root@hadoop1 zookeeper]# sh bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /data/soft/zookeeper/bin/../conf/zoo.cfg Mode: follower
hadoop2的状态为foller
[root@hadoop2 zookeeper]# sh bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /data/soft/zookeeper/bin/../conf/zoo.cfg Mode: follower
hadoop3的转态为leader,说明hadoop3为主节点。
[root@hadoop3 zookeeper]# sh bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /data/soft/zookeeper/bin/../conf/zoo.cfg Mode: leader
进入客户端模式可以查看相关信息:
sh bin/zkCli.sh Connecting to localhost:2181 2018-04-19 10:49:05,854 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT 2018-04-19 10:49:05,858 [myid:] - INFO [main:Environment@100] - Client environment:host.name=hadoop3 2018-04-19 10:49:05,858 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_152 2018-04-19 10:49:05,862 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2018-04-19 10:49:05,862 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/jdk1.8.0_152/jre 2018-04-19 10:49:05,862 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/data/soft/zookeeper/bin/../build/classes:/data/soft/zookeeper/bin/../build/lib/*.jar:/data/soft/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/data/soft/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/data/soft/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/data/soft/zookeeper/bin/../lib/log4j-1.2.16.jar:/data/soft/zookeeper/bin/../lib/jline-0.9.94.jar:/data/soft/zookeeper/bin/../zookeeper-3.4.9.jar:/data/soft/zookeeper/bin/../src/java/lib/*.jar:/data/soft/zookeeper/bin/../conf:.:/usr/local/jdk1.8.0_152/lib/dt.jar:/usr/local/jdk1.8.0_152/lib/tools.jar 2018-04-19 10:49:05,863 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2018-04-19 10:49:05,863 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2018-04-19 10:49:05,863 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2018-04-19 10:49:05,863 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2018-04-19 10:49:05,863 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2018-04-19 10:49:05,863 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-431.el6.x86_64 2018-04-19 10:49:05,864 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2018-04-19 10:49:05,864 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2018-04-19 10:49:05,864 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/data/soft/zookeeper 2018-04-19 10:49:05,870 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@579bb367 Welcome to ZooKeeper! 2018-04-19 10:49:05,918 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled 2018-04-19 10:49:06,041 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session 2018-04-19 10:49:06,056 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x262dbc746fb0001, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] ls / [zookeeper]
解释说明 :
领导者(leader),负责进行投票的发起和决议,更新系统状态
学习者(learner),包括跟随者(foller)和观察者(observer),
foller用于接受客户端请求并向客户端返回结果,在选主过程中参与投票。
observer可以接受客户端连接,将写请求转发给leader,但不参加投票过程,只同步leader的状态,observer的目的是为了扩展系统,提高读取速度。
客户端(client),请求发起者
结束语:
好了,这就是简单的zookeeper集群安装,我看网上很多地方写的特复杂,我就简化了一下,希望能帮助大家快速入门zookeeper,下次的博客就是对zookeeper使用的相关命令做解释,希望有兴趣的小伙伴可以看看。