目录
1 .环境安排
安装ZooKeeper
3 .运行测试
参考:
1.环境设定Required Software
ZooKeeper runs in Java,release 1.7 or greater (JDK7or greater, FreeBSD support requires openjdk7).itrunsasanensembleofzookeeperserversistheminimrecommendedsizeforation andwealsorecommendThanage、zookeeperisusuallydeployedondedicatedrhelboxes、with dual-core processors、2GB of RAM、and 80gb ide
此处安装ZooKeeper3.5.9需要JDK1.7或更高版本。 此处为JDK1.8,下载地址https://www.Oracle.com/Java/technologies/Java se/Java se-JDK8- downlo gies
(1)下载解压
#创建目录mkdir-p/usr/Java # # tar-zxvf JDK-8u 212-Linux-x64.tar.gz (2)下载和解压缩配置环境变量
打开/etc/profile文件,并在末尾添加以下内容
export Java _ home=/usr/Java/JDK1.8.0_ 212 export class path=. $ Java _ home/lib/dt.jar 360 $ Java
源/etc /配置文件(3)测试java环境
Java版本
2 .安装zookeeper https://zookeeper.Apache.org/releases.html # download
(1)下载解压
wget https://mirror.bit.edu.cn/Apache/zookeeper-3.5.9/Apache-zookeeper-3.5.9-qxd lb.tar .
CD Apache-zookeeper-3.5.9-qxd lb/CD conf/CP zoo _ sample.CFG zoo.CFG zerver.id=IP 3360 port 3360 ppg
server.1=192.168.11.29336028833603888 server.2=192.168.11.3033602883603888 server.3=192.168.168
# thenumberofmillisecondsofeachtickticktime=2000 # thenumberofticksthattheinitial # synchronizationphasecantakeinitlimit=100
tting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/var/lib/zookeeper/# the port at which the clients will connectclientPort=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=1server.1=192.168.111.129:2888:3888server.2=192.168.111.130:2888:3888server.3=192.168.111.131:2888:3888将该配置文件复制到其他两台机器对应目录下,内容保持不变。
注意:dataDir= 参数 配置的目录应该为空目录,不能复用有数据的目录,否则会导致zookeeper启动失败。
(3) 配置 myid
根据 server.id = ip:port:port 中, id 和 ip 的对应关系,分别在 三台节点机器的 dataDir=/var/lib/zookeeper/ 指定的目录下, 新建 myid 文件并且填入对应的数字。
vim /var/lib/zookeeper/myid节点1: ip 为192.168.111.129 机器为
节点2: ip 为192.168.111.130 机器为
节点3: ip 为192.168.111.131 机器为
注意:myid 文件只能填数字(具体要求如下引用),除此之外不能添加其他内容,空格也不能有,否则会报错(如下截图)。
The myid file consists of a single line containing only the text of that machine's id. So myid of server 1 would contain the text "1" and nothing else. The id must be unique within the ensemble and should have a value between 1 and 255. IMPORTANT: if you enable extended features such as TTL Nodes (see below) the id must be between 1 and 254 due to internal limitations.
3.运行测试(1)关闭防火墙
首先必须关闭每台机器的防火墙,否则会导致zookeeper启动失败
systemctl stop firewalld(2)启动服务
在第一台机器启动zookeeper 服务
cd apache-zookeeper-3.5.9-qxdlb/./qxdlb/zkServer.sh start查看启动状态
./qxdlb/zkServer.sh status发现并没有启动成功,查看系统日志。
cd apache-zookeeper-3.5.9-qxdlb/tail -f ./logs/zookeeper-root-server-node1.out发现是连接不到另外两台机器,分别启动另外两台机器上面的zookeeper服务。
(3)查看程序状态
节点1:
节点2:
节点3:
说明节点2是主节点,节点1和节点3是从节点。
(4)测试
qxdlb/zkCli.sh -server 192.168.111.129:2181,192.168.111.130:2181,192.168.111.131:2181安装成功。
参考:
1.jdk 下载
https://www.oracle.com/java/technologies/javase-downloads.html
2.zookeeper官网
https://zookeeper.apache.org/index.html
3.zookeeper下载
https://zookeeper.apache.org/releases.html#download
4.系统需求
https://zookeeper.apache.org/doc/r3.5.9/zookeeperAdmin.html#sc_systemReq
5.单机安装教程
https://zookeeper.apache.org/doc/r3.5.9/zookeeperStarted.html#sc_InstallingSingleMode
6.集群安装教程
https://zookeeper.apache.org/doc/r3.5.9/zookeeperStarted.html
https://zookeeper.apache.org/doc/r3.5.9/zookeeperStarted.html#sc_RunningReplicatedZooKeeper
https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_zkMulitServerSetup
7.配置文件参数说明
https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_configuration
8.其他
https://www.runoob.com/w3cnote/zookeeper-linux-cluster.html