1.安装 JDK
tar -zxvf jdk-8u261-linux-x64.tar.gz -C /opt/soft/
2.配置 root 用户环境变量 在.bash_profile 中添加 java 环境变量
vim /etc/profile
export JAVA_HOME=/opt/soft/jdk1.8.0_261
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
验证是否安装成功
java -version
https://archive.apache.org/dist/zookeeper/
下载 apache-zookeeper-3.7.1-bin.tar.gz安装包,放置到上面三台服务器一个目录下(/opt/package)
进入到/apps/目录下,解压tar包
tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz -C /opt/soft
mv apache-zookeeper-3.7.1-bin/ zookeeper-3.7.1
cd /opt/soft/zookeeper-3.7.1/conf
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/soft/zookeeper-3.7.1/data/zookeeper
dataLogDir=/opt/soft/zookeeper-3.7.1/logs/zookeeper
clientPort=2181
autopurge.purgeInterval=0
globalOutstandingLimit=200
server.1=node01:2888:3888
server.2=node02:2888:3888
server.3=node03:2888:3888
mkdir -p /opt/soft/zookeeper-3.7.1/data/zookeeper
mkdir -p /opt/soft/zookeeper-3.7.1/logs/zookeeper
配置完成后将当前的zookeeper目录同步到其他两个节点
ssh_do_scp.sh ~/bin/node.list /opt/soft/zookeeper-3.7.1 /opt/soft/
vim /opt/soft/zookeeper-3.7.1/data/zookeeper/myid
node01为1,
node02为2,
node03为3
vim /etc/profile
export ZOOKEEPER_HOME=/opt/soft/zookeeper-3.7.1
export PATH=$PATH:$ZOOKEEPER_HOME/bin
source /etc/profile
cd /opt/soft/zookeeper-3.7.1
zkServer.sh start
zkServer.sh status
其中有一个节点是leader,有两个节点是follower,证明zookeeper集群是部署成功的。
[root@node01 zookeeper-3.7.1]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper-3.7.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@node02 zookeeper-3.7.1]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper-3.7.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
[root@node03 zookeeper-3.7.1]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper-3.7.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
zkCli.sh -server localhost:2181
zkCli.sh -server node01/node02/node03:2181
如果出现拒绝连接,查看防火墙是否关闭,关闭防火墙service iptables stop重启zookeeper,或排查是否配置有误
创建目录成功
[zk: localhost:2181(CONNECTED) 1] create /test 111
Created /test
[zk: localhost:2181(CONNECTED) 2] ls /
[test, zookeeper]
[zk: localhost:2181(CONNECTED) 3] get /test
111