zhiyou01 192.168.233.129
zhiyou02 192.168.233.132
zhiyou03 192.168.233.133
安装之前:
设置好静态ip
jdk给配置好
ssh免密登录
关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
安装过程:
在一台电脑上配置好,然后发送到其他的电脑上;
1.上传zookeeper到user/zookeeper下
[root@zhiyou01 zookeeper]# ls
zookeeper-3.4.12.tar.gz
2.解压
[root@zhiyou01 zookeeper]# tar -zxvf zookeeper-3.4.12.tar.gz
3.修改zoo.cfg 文件
$zookeeper/conf
3.1 生成zoo.cfg
[root@zhiyou01 zookeeper]# cd /usr/zookeeper/zookeeper-3.4.12/conf
[root@zhiyou01 conf]# ls
configuration.xsl log4j.properties zoo_sample.cfg
[root@zhiyou01 conf]#
[root@zhiyou01 conf]# mv zoo_sample.cfg zoo.cfg #生成zoo.cfg
[root@zhiyou01 conf]# ls
configuration.xsl log4j.properties zoo.cfg
[root@zhiyou01 conf]#
zookeeper的默认配置文件为zookeeper/conf/zoo_sample.cfg,需要将其修改为
zoo.cfg。其中各配置项的含义,解释如下:
1.tickTime:CS通信心跳时间
Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 ?ckTime 时间
就会发送一个心跳。?ckTime以毫秒为单位。
tickTime=2000
2.initLimit:LF初始通信时限
集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(?ckTime的
数量)。
initLimit=5
3.syncLimit:LF同步通信时限
集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(?ckTime的数
量)。
syncLimit=2
4.dataDir:数据文件目录
Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
dataDir=/home/michael/opt/zookeeper/data
5.clientPort:客户端连接端口
客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
clientPort=2181
6.服务器名称与地址:集群信息(服务器编号,服务器地址,LF通信端口,选举端口)
这个配置项的书写格式比较特殊,规则如下:
server.N=YYY:A:B
3.2修改
3.2.1修改dateDir
dataDir=/usr/zookeeper/data
3.3.3追加内容:
server.01=192.168.233.129:2888:3888
server.02=192.168.233.132:2888:3888
server.03=192.168.233.133:2888:3888
4.在dateDir (dataDir=/usr/zookeeper/data)目录下 创建一个myid文件,
在里面添加内容,内容是 server.N中的N
(server.01 内容就是 01 位置对ip地址对应 )
zhiyou01 ----- 01
zhiyou02 ------- 02
zhiyou03 --------03
[root@zhiyou01 data]# echo "01">myid
5.把配置好的zk拷贝到其他节点上
(jdk 也要发 /etc/profile也要发送 拷贝之后需要 resource /etc/profile)
scp -r 本地目录 其他节点的用户名@IP:目录
[root@zhiyou01 data]# scp -r /usr/java/ root@192.168.233.132:/usr/java/
[root@zhiyou01 data]# scp -r /usr/java/ root@192.168.233.133:/usr/java/
[root@zhiyou01 data]# scp -r /etc/profile root@192.168.233.132:/etc/profile
[root@zhiyou01 data]# scp -r /etc/profile root@192.168.233.133:/etc/profile
刷新环境变量
把zookeeper给发过去
[root@zhiyou01 data]# scp -r /usr/zookeeper/
root@192.168.233.132:/usr/zookeeper/
[root@zhiyou01 data]# scp -r /usr/zookeeper/
root@192.168.233.133:/usr/zookeeper/
6. zhiyou02 把myid --02
[root@zhiyou02 usr]# cd /usr/zookeeper/data/
[root@zhiyou02 data]# echo "02">myid
[root@zhiyou02 data]# cat myid
02
[root@zhiyou02 data]#
zhiyou03 把myid--03
[root@zhiyou03 usr]# cd /usr/zookeeper/data/
[root@zhiyou03 data]# echo "03">myid
[root@zhiyou03 data]# cat myid
03
[root@zhiyou03 data]#
7.分别启动zk
[root@zhiyou01 ~]# cd /usr/zookeeper/zookeeper-3.4.12/bin/
[root@zhiyou01 bin]# ls
README.txt zkCleanup.sh zkCli.cmd zkCli.sh zkEnv.cmd zkEnv.sh zkServer.cmd
zkServer.sh
[root@zhiyou01 bin]# ./zkServer.sh start
8.查看状态
[root@zhiyou01 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower
[root@zhiyou01 bin]#
9.查看进程: jps
[root@zhiyou03 bin]# jps
18214 Jps
18153 QuorumPeerMain
测试: 把leader的进程给结束了
[root@zhiyou03 bin]# kill -9 18153
[root@zhiyou03 bin]# jps
18224 Jps
[root@zhiyou03 bin]#
又产生了新的领导
[root@zhiyou02 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower
[root@zhiyou02 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: leader
[root@zhiyou02 bin]#
数据同步
1.进入zkClient
[root@zhiyou01 bin]# ./zkCli.sh
Connecting to localhost:2181
2018-05-31 17:03:00,806 [myid:] - INFO [main:Environment@100] - Client
environment:zookeeper.version=3.4.12-
e5259e437540f349646870ea94dc2658c4e44b3b, built on 03/27/2018 03:55 GMT
2018-05-31 17:03:00,822 [myid:] - INFO [main:Environment@100] - Client
environment:host.name=zhiyou01
2018-05-31 17:03:00,822 [myid:] - INFO [main:Environment@100] - Client
environment:java.version=1.8.0_141
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:java.vendor=Oracle Corporation
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:java.home=/usr/java/jdk1.8.0_141/jre
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:java.class.path=/usr/zookeeper/zookeeper-
3.4.12/bin/../build/classes:/usr/zookeeper/zookeeper-
3.4.12/bin/../build/lib/*.jar:/usr/zookeeper/zookeeper-3.4.12/bin/../lib/slf4j-log4j12-
1.7.25.jar:/usr/zookeeper/zookeeper-3.4.12/bin/../lib/slf4j-api-
1.7.25.jar:/usr/zookeeper/zookeeper-3.4.12/bin/../lib/netty-
3.10.6.Final.jar:/usr/zookeeper/zookeeper-3.4.12/bin/../lib/log4j-
1.2.17.jar:/usr/zookeeper/zookeeper-3.4.12/bin/../lib/jline-
0.9.94.jar:/usr/zookeeper/zookeeper-3.4.12/bin/../lib/audience-annotations-
0.5.0.jar:/usr/zookeeper/zookeeper-3.4.12/bin/../zookeeper-
3.4.12.jar:/usr/zookeeper/zookeeper-
3.4.12/bin/../src/java/lib/*.jar:/usr/zookeeper/zookeeper-
3.4.12/bin/../conf:/usr/java/jdk1.8.0_141/lib/
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:java.io.tmpdir=/tmp
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:java.compiler=<NA>
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:os.name=Linux
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:os.arch=amd64
2018-05-31 17:03:00,829 [myid:] - INFO [main:Environment@100] - Client
environment:os.version=3.10.0-514.el7.x86_64
2018-05-31 17:03:00,830 [myid:] - INFO [main:Environment@100] - Client
environment:user.name=root
2018-05-31 17:03:00,830 [myid:] - INFO [main:Environment@100] - Client
environment:user.home=/root
2018-05-31 17:03:00,830 [myid:] - INFO [main:Environment@100] - Client
environment:user.dir=/usr/zookeeper/zookeeper-3.4.12/bin
2018-05-31 17:03:00,831 [myid:] - INFO [main:ZooKeeper@441] - Initiating client
connection, connectString=localhost:2181 sessionTimeout=30000
watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@22d8cfe0
Welcome to ZooKeeper!
2018-05-31 17:03:00,952 [myid:] - INFO [main-
SendThread(localhost:2181):ClientCnxn$SendThread@1028] - Opening socket
connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using
SASL (unknown error)
JLine support is enabled
2018-05-31 17:03:01,075 [myid:] - INFO [main-
SendThread(localhost:2181):ClientCnxn$SendThread@878] - Socket connection
established to localhost/127.0.0.1:2181, initiating session
2018-05-31 17:03:01,105 [myid:] - INFO [main-
SendThread(localhost:2181):ClientCnxn$SendThread@1302] - Session establishment
complete on server localhost/127.0.0.1:2181, sessionid = 0x10000b834fd0000,
negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
查看zookeeper上面的内容
[zk: localhost:2181(CONNECTED) 0] ls / #查看
[zookeeper]
创建一个文件
create /文件 文件里面的内容
[zk: localhost:2181(CONNECTED) 1] create /zhiyou01 hello
WATCHER::
WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/
Created /zhiyou01
[zk: localhost:2181(CONNECTED) 2]
查看文件的内容
[zk: localhost:2181(CONNECTED) 5] get /zhiyou01
hello
cZxid = 0x500000002
ctime = Thu May 31 17:06:02 CST 2018
mZxid = 0x500000002
mtime = Thu May 31 17:06:02 CST 2018
pZxid = 0x500000002
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0
[zk: localhost:2181(CONNECTED) 6]
到其他的zookeeper里面去查看,看是否同步
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper, zhiyou01]
[zk: localhost:2181(CONNECTED) 1]
Hadoop+zookeeper的集群安装
最新推荐文章于 2023-07-13 20:12:11 发布