1、准备三台服务,ip如下
192.168.37.183192.168.37.150192.168.37.86
2、防火墙
zookeeper服务应限制访问ip,将集群节点和需要访问zookeeper的ip添加到trusted区域
安装、启动防火墙
yum install firewalld.noarchsystemctl enable firewalld.servicesystemctl start firewalld.service
不同的服务器执行不同的命令
(1)192.168.37.183服务器
firewall-offline-cmd --zone=trusted --add-source=192.168.37.150firewall-offline-cmd --zone=trusted --add-source=192.168.37.86systemctl reload firewalldfirewall-cmd --list-all-zones
(2)192.168.37.150服务器
firewall-offline-cmd --zone=trusted --add-source=192.168.37.183firewall-offline-cmd --zone=trusted --add-source=192.168.37.86systemctl reload firewalldfirewall-cmd --list-all-zones
(3)192.168.37.86服务器
firewall-offline-cmd --zone=trusted --add-source=192.168.37.183firewall-offline-cmd --zone=trusted --add-source=192.168.37.150systemctl reload firewalldfirewall-cmd --list-all-zones
3、zookeeper集群搭建
新建zookeeper数据目录
mkdir /home/trimps/zoodata
不同的服务器执行不同的命令
(1)192.168.37.183服务器
echo "1" > /home/trimps/zoodata/myid
(2)192.168.37.150服务器
echo "2" > /home/trimps/zoodata/myid
(3)192.168.37.86服务器
echo "3" > /home/trimps/zoodata/myid
将apache-zookeeper-3.7.0-bin.tar.gz文件上传到/home/trimps/software目录,解压
tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz
主要配置(各服务器配置相同)
vi zoo.cfgtickTime=2000initLimit=10syncLimit=5dataDir=/home/trimps/zoodataclientPort=3292server.1=192.168.37.183:3999:4999server.2=192.168.37.150:3999:4999server.3=192.168.37.86:3999:4999
启动、查看状态、停止命令
bin/zkServer.sh startbin/zkServer.sh statusbin/zkServer.sh stop
4、查看状态
(1)192.168.37.183服务器
[root@0003 apache-zookeeper-3.7.0-bin]# bin/zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfgClient port found: 3292、Client address: localhost、Client SSL: false.Mode: follower
(2)192.168.37.150服务器
[root@0002 apache-zookeeper-3.7.0-bin]# bin/zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfgClient port found: 3292、Client address: localhost、Client SSL: false.Mode: leader
(3)192.168.37.86服务器
[root@0001 apache-zookeeper-3.7.0-bin]# bin/zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfgClient port found: 3292、Client address: localhost、Client SSL: false.Mode: follower
5、测试
客户端连接192.168.37.183服务器并新建一个节点,客户端连接192.168.37.183、192.168.37.150、192.168.37.86服务器并查看节点信息
(1)192.168.37.183服务器
[root@0003 apache-zookeeper-3.7.0-bin]# bin/zkCli.sh -server 192.168.37.183:3292Connecting to 192.168.37.183:32922022-02-23 21:41:14,655 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC2022-02-23 21:41:14,659 [myid:] - INFO [main:Environment@98] - Client environment:host.name=localhost2022-02-23 21:41:14,659 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_3022022-02-23 21:41:14,661 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Bisheng2022-02-23 21:41:14,661 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/home/trimps/software/bisheng-jdk1.8.0_302/jre2022-02-23 21:41:14,661 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/classes:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../build/classes:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../build/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-jute-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/snappy-java-1.1.7.7.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-log4j12-1.7.30.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-api-1.7.30.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_servlet-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_hotspot-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_common-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-resolver-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-handler-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-common-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-codec-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-buffer-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/metrics-core-4.1.12.1.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/log4j-1.2.17.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jline-2.14.6.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-server-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-security-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-io-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-http-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-databind-2.10.5.1.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-core-2.10.5.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-annotations-2.10.5.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/commons-cli-1.4.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/audience-annotations-0.12.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../conf:.:/home/trimps/software/bisheng-jdk1.8.0_302/lib/dt.jar:/home/trimps/software/bisheng-jdk1.8.0_302/lib/tools.jar2022-02-23 21:41:14,661 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/aarch64:/lib:/usr/lib2022-02-23 21:41:14,661 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/tmp2022-02-23 21:41:14,661 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=
(2)192.168.37.150服务器
[root@0002 apache-zookeeper-3.7.0-bin]# bin/zkCli.sh -server 192.168.37.150:3292Connecting to 192.168.37.150:32922022-02-23 21:44:53,818 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC2022-02-23 21:44:53,821 [myid:] - INFO [main:Environment@98] - Client environment:host.name=localhost2022-02-23 21:44:53,821 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_3022022-02-23 21:44:53,823 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Bisheng2022-02-23 21:44:53,823 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/home/trimps/software/bisheng-jdk1.8.0_302/jre2022-02-23 21:44:53,824 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/classes:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../build/classes:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../build/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-jute-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/snappy-java-1.1.7.7.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-log4j12-1.7.30.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-api-1.7.30.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_servlet-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_hotspot-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_common-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-resolver-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-handler-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-common-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-codec-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-buffer-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/metrics-core-4.1.12.1.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/log4j-1.2.17.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jline-2.14.6.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-server-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-security-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-io-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-http-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-databind-2.10.5.1.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-core-2.10.5.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-annotations-2.10.5.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/commons-cli-1.4.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/audience-annotations-0.12.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../conf:.:/home/trimps/software/bisheng-jdk1.8.0_302/lib/dt.jar:/home/trimps/software/bisheng-jdk1.8.0_302/lib/tools.jar2022-02-23 21:44:53,824 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/aarch64:/lib:/usr/lib2022-02-23 21:44:53,824 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/tmp2022-02-23 21:44:53,824 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=
(3)192.168.37.86服务器
[root@0001 apache-zookeeper-3.7.0-bin]# bin/zkCli.sh -server 192.168.37.86:3292Connecting to 192.168.37.86:32922022-02-23 21:45:26,626 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC2022-02-23 21:45:26,629 [myid:] - INFO [main:Environment@98] - Client environment:host.name=localhost2022-02-23 21:45:26,630 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_3022022-02-23 21:45:26,632 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Bisheng2022-02-23 21:45:26,632 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/home/trimps/software/bisheng-jdk1.8.0_302/jre2022-02-23 21:45:26,632 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/classes:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../build/classes:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../build/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-jute-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-3.7.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/snappy-java-1.1.7.7.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-log4j12-1.7.30.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-api-1.7.30.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_servlet-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_hotspot-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_common-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient-0.9.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-resolver-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-handler-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-common-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-codec-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/netty-buffer-4.1.59.Final.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/metrics-core-4.1.12.1.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/log4j-1.2.17.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jline-2.14.6.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-server-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-security-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-io-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-http-9.4.38.v20210224.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-databind-2.10.5.1.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-core-2.10.5.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-annotations-2.10.5.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/commons-cli-1.4.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../lib/audience-annotations-0.12.0.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/home/trimps/software/apache-zookeeper-3.7.0-bin/bin/../conf:.:/home/trimps/software/bisheng-jdk1.8.0_302/lib/dt.jar:/home/trimps/software/bisheng-jdk1.8.0_302/lib/tools.jar2022-02-23 21:45:26,632 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/aarch64:/lib:/usr/lib2022-02-23 21:45:26,633 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/tmp2022-02-23 21:45:26,633 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=