本文最后更新于 320 天前,其中的信息可能已经过时,如有错误请发送邮件到wuxianglongblog@163.com
zookeeper集群环境部署
一.实验环境准备
1.zookeeper集群搭建概述
单机环境下,zookeeper安装完毕,我们可以基于一台虚拟机,进行zookeeper的伪分布式集群搭建,zookeeper集群中包含3个节点,例如节点对外提供服务端口号分别为2181,2182和2183。
但在实际生产环境中,伪分布式并不使用,因此我们还是搭建一个完全分布式集群,这样更贴近生产环境。
2.测试环境说明
[root@elk101.oldboyedu.com ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# free -h
total used free shared buff/cache available
Mem: 3.7G 311M 3.2G 11M 198M 3.2G
Swap: 0B 0B 0B
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# uname -r
3.10.0-1160.el7.x86_64
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# uname -m
x86_64
[root@elk101.oldboyedu.com ~]#
3.添加zookeeper集群的映射信息
[root@elk101.oldboyedu.com ~]# grep oldboyedu /etc/hosts
172.200.1.101 elk101.oldboyedu.com elk101.oldboyedu.com
172.200.1.102 elk102.oldboyedu.com elk102.oldboyedu.com
172.200.1.103 elk103.oldboyedu.com elk103.oldboyedu.com
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ping elk103.oldboyedu.com -c 3
PING elk103.oldboyedu.com (172.200.1.103) 56(84) bytes of data.
64 bytes from elk103.oldboyedu.com (172.200.1.103): icmp_seq=1 ttl=64 time=0.246 ms
64 bytes from elk103.oldboyedu.com (172.200.1.103): icmp_seq=2 ttl=64 time=0.343 ms
64 bytes from elk103.oldboyedu.com (172.200.1.103): icmp_seq=3 ttl=64 time=0.377 ms
--- elk103.oldboyedu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.246/0.322/0.377/0.055 ms
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ping elk102.oldboyedu.com -c 3
PING elk102.oldboyedu.com (172.200.1.102) 56(84) bytes of data.
64 bytes from elk102.oldboyedu.com (172.200.1.102): icmp_seq=1 ttl=64 time=0.575 ms
64 bytes from elk102.oldboyedu.com (172.200.1.102): icmp_seq=2 ttl=64 time=0.443 ms
64 bytes from elk102.oldboyedu.com (172.200.1.102): icmp_seq=3 ttl=64 time=0.363 ms
--- elk102.oldboyedu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.363/0.460/0.575/0.089 ms
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ping elk101.oldboyedu.com -c 3
PING elk101.oldboyedu.com (172.200.1.101) 56(84) bytes of data.
64 bytes from elk101.oldboyedu.com (172.200.1.101): icmp_seq=1 ttl=64 time=0.011 ms
64 bytes from elk101.oldboyedu.com (172.200.1.101): icmp_seq=2 ttl=64 time=0.019 ms
64 bytes from elk101.oldboyedu.com (172.200.1.101): icmp_seq=3 ttl=64 time=0.021 ms
--- elk101.oldboyedu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.011/0.017/0.021/0.004 ms
[root@elk101.oldboyedu.com ~]#
4.拷贝"/etc/hosts"文件到集群的其它节点上
[root@elk101.oldboyedu.com ~]# scp /etc/hosts elk102.oldboyedu.com:/etc/hosts
The authenticity of host 'elk102.oldboyedu.com (172.200.1.102)' can't be established.
ECDSA key fingerprint is SHA256:rOEM9ZBK1HJkhTVdewL0mkRWObE3ZprBZnaIabP2lZY.
ECDSA key fingerprint is MD5:ff:b3:df:b3:6d:41:87:55:65:8c:e8:87:00:10:46:14.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'elk102.oldboyedu.com' (ECDSA) to the list of known hosts.
root@elk102.oldboyedu.com's password:
hosts 100% 342 247.7KB/s 00:00
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# scp /etc/hosts elk103.oldboyedu.com:/etc/hosts
The authenticity of host 'elk103.oldboyedu.com (172.200.1.103)' can't be established.
ECDSA key fingerprint is SHA256:rOEM9ZBK1HJkhTVdewL0mkRWObE3ZprBZnaIabP2lZY.
ECDSA key fingerprint is MD5:ff:b3:df:b3:6d:41:87:55:65:8c:e8:87:00:10:46:14.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'elk103.oldboyedu.com,172.200.1.103' (ECDSA) to the list of known hosts.
root@elk103.oldboyedu.com's password:
hosts 100% 342 251.5KB/s 00:00
[root@elk101.oldboyedu.com ~]#
5.将已经部署好的zookeeper环境拷贝到其它节点
推荐使用"data_rsync.sh"脚本实现。
6.部署集群的时间同步服务器
推荐使用"chrony"服务部署集群时间同步。
参考地址:
https://www.cnblogs.com/yinzhengjie/p/12292549.html
温馨提示:
为了省事情,直接使用阿里云的时间服务器即可"ntpdate ntp.aliyun.com"
7.配置免密登录
(1)配置免密登录:
[root@elk101.oldboyedu.com ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
Generating public/private rsa key pair.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:KbetpYPVazG+hycM7Gz20DR/FUYW3A0W919sYI466Y8 root@elk101.oldboyedu.com
The key's randomart image is:
+---[RSA 2048]----+
| B*=|
| =o=+|
| . .o=|
| . o ..+|
| ..S.* o|
| o+*++ . |
| =o+==. . |
| . *=Boo. |
| oo+E=. |
+----[SHA256]-----+
[root@elk101.oldboyedu.com ~]#
(2)"elk101.oldboyedu.com"节点拷贝密钥
[root@elk101.oldboyedu.com ~]# ssh-copy-id root@elk101.oldboyedu.com
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'elk101.oldboyedu.com (172.200.1.101)' can't be established.
ECDSA key fingerprint is SHA256:rOEM9ZBK1HJkhTVdewL0mkRWObE3ZprBZnaIabP2lZY.
ECDSA key fingerprint is MD5:ff:b3:df:b3:6d:41:87:55:65:8c:e8:87:00:10:46:14.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@elk101.oldboyedu.com's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@elk101.oldboyedu.com'"
and check to make sure that only the key(s) you wanted were added.
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# who
root pts/0 2021-04-27 17:54 (172.200.1.19)
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ssh root@elk101.oldboyedu.com
Last login: Tue Apr 27 17:54:09 2021 from 172.200.1.19
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# who
root pts/0 2021-04-27 17:54 (172.200.1.19)
root pts/1 2021-04-27 21:56 (172.200.1.101)
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# exit
登出
Connection to elk101.oldboyedu.com closed.
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# who
root pts/0 2021-04-27 17:54 (172.200.1.19)
[root@elk101.oldboyedu.com ~]#
(3)"elk102.oldboyedu.com"节点拷贝密钥
[root@elk101.oldboyedu.com ~]# ssh-copy-id root@elk102.oldboyedu.com
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@elk102.oldboyedu.com's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@elk102.oldboyedu.com'"
and check to make sure that only the key(s) you wanted were added.
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# who
root pts/0 2021-04-27 17:54 (172.200.1.19)
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ssh root@elk102.oldboyedu.com
Last login: Tue Apr 27 20:44:44 2021 from 172.200.1.19
[root@elk102.oldboyedu.com ~]#
[root@elk102.oldboyedu.com ~]# who
root pts/0 2021-04-27 20:44 (172.200.1.19)
root pts/1 2021-04-27 21:58 (172.200.1.101)
[root@elk102.oldboyedu.com ~]#
[root@elk102.oldboyedu.com ~]# exit
登出
Connection to elk102.oldboyedu.com closed.
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# who
root pts/0 2021-04-27 17:54 (172.200.1.19)
[root@elk101.oldboyedu.com ~]#
(4)"elk103.oldboyedu.com"节点拷贝密钥
[root@elk101.oldboyedu.com ~]# ssh-copy-id root@elk103.oldboyedu.com
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@elk103.oldboyedu.com's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@elk103.oldboyedu.com'"
and check to make sure that only the key(s) you wanted were added.
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ssh root@elk103.oldboyedu.com
Last login: Tue Apr 27 20:44:46 2021 from 172.200.1.19
[root@elk103.oldboyedu.com ~]#
[root@elk103.oldboyedu.com ~]# who
root pts/0 2021-04-27 20:44 (172.200.1.19)
root pts/1 2021-04-27 21:59 (172.200.1.101)
[root@elk103.oldboyedu.com ~]#
[root@elk103.oldboyedu.com ~]# exit
登出
Connection to elk103.oldboyedu.com closed.
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# who
root pts/0 2021-04-27 17:54 (172.200.1.19)
[root@elk101.oldboyedu.com ~]#
8.部署ansible管理工具并使用该工具批量创建zookeeper的数据目录
[root@elk101.oldboyedu.com ~]# yum -y install epel-release
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# yum -y install ansible
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# vim /etc/ansible/hosts
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# tail -3 /etc/ansible/hosts
# Add by yinzhengjie for zk cluster.
[zk]
kafka[101:103].yinzhengjie.com
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'mkdir -pv /yinzhengjie/data/zookeeper'
elk103.oldboyedu.com | CHANGED | rc=0 >>
elk101.oldboyedu.com | CHANGED | rc=0 >>
elk102.oldboyedu.com | CHANGED | rc=0 >>
[root@elk101.oldboyedu.com ~]#
温馨提示:
如果在执行上述ansible命令出现"[WARNING]: ... or set 'command_warnings=False' in ansible.cfg to get rid of this message."的消息,我们可以手动禁用该消息。
编辑"/etc/ansible/ansible.cfg"配置文件,将"command_warnings = False"的注释消息取消掉即可。
9.禁用SELINUX服务
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'grep SELINUX= /etc/selinux/config | grep -v ^#'
elk102.oldboyedu.com | CHANGED | rc=0 >>
SELINUX=enforcing
elk101.oldboyedu.com | CHANGED | rc=0 >>
SELINUX=enforcing
elk103.oldboyedu.com | CHANGED | rc=0 >>
SELINUX=enforcing
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config'
elk102.oldboyedu.com | CHANGED | rc=0 >>
elk101.oldboyedu.com | CHANGED | rc=0 >>
elk103.oldboyedu.com | CHANGED | rc=0 >>
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'grep SELINUX= /etc/selinux/config | grep -v ^#'
elk101.oldboyedu.com | CHANGED | rc=0 >>
SELINUX=disabled
elk102.oldboyedu.com | CHANGED | rc=0 >>
SELINUX=disabled
elk103.oldboyedu.com | CHANGED | rc=0 >>
SELINUX=disabled
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'getenforce'
elk103.oldboyedu.com | CHANGED | rc=0 >>
Enforcing
elk101.oldboyedu.com | CHANGED | rc=0 >>
Enforcing
elk102.oldboyedu.com | CHANGED | rc=0 >>
Enforcing
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'setenforce 0'
elk102.oldboyedu.com | CHANGED | rc=0 >>
elk103.oldboyedu.com | CHANGED | rc=0 >>
elk101.oldboyedu.com | CHANGED | rc=0 >>
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'getenforce'
elk101.oldboyedu.com | CHANGED | rc=0 >>
Permissive
elk102.oldboyedu.com | CHANGED | rc=0 >>
Permissive
elk103.oldboyedu.com | CHANGED | rc=0 >>
Permissive
[root@elk101.oldboyedu.com ~]#
10.禁用firewalld服务
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'systemctl status firewalld'
elk101.oldboyedu.com | FAILED | rc=3 >>
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)non-zero return code
elk102.oldboyedu.com | CHANGED | rc=0 >>
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2021-04-27 20:42:35 CST; 1h 30min ago
Docs: man:firewalld(1)
Main PID: 608 (firewalld)
CGroup: /system.slice/firewalld.service
└─608 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
4月 27 20:42:34 elk102.oldboyedu.com systemd[1]: Starting firewalld - dynamic firewall daemon...
4月 27 20:42:35 elk102.oldboyedu.com systemd[1]: Started firewalld - dynamic firewall daemon.
4月 27 20:42:35 elk102.oldboyedu.com firewalld[608]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release.
Please consider disabling it now.elk103.oldboyedu.com | CHANGED | rc=0 >>
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2021-04-27 20:42:38 CST; 1h 29min ago
Docs: man:firewalld(1)
Main PID: 601 (firewalld)
CGroup: /system.slice/firewalld.service
└─601 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
4月 27 20:42:38 elk103.oldboyedu.com systemd[1]: Starting firewalld - dynamic firewall daemon...
4月 27 20:42:38 elk103.oldboyedu.com systemd[1]: Started firewalld - dynamic firewall daemon.
4月 27 20:42:39 elk103.oldboyedu.com firewalld[601]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release.
Please consider disabling it now.[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'systemctl stop firewalld'
elk101.oldboyedu.com | CHANGED | rc=0 >>
elk103.oldboyedu.com | CHANGED | rc=0 >>
elk102.oldboyedu.com | CHANGED | rc=0 >>
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'systemctl disable firewalld'
elk103.oldboyedu.com | CHANGED | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
elk101.oldboyedu.com | CHANGED | rc=0 >>
elk102.oldboyedu.com | CHANGED | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'systemctl status firewalld'
elk101.oldboyedu.com | FAILED | rc=3 >>
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)non-zero return code
elk102.oldboyedu.com | FAILED | rc=3 >>
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
4月 27 20:42:34 elk102.oldboyedu.com systemd[1]: Starting firewalld - dynamic firewall daemon...
4月 27 20:42:35 elk102.oldboyedu.com systemd[1]: Started firewalld - dynamic firewall daemon.
4月 27 20:42:35 elk102.oldboyedu.com firewalld[608]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release.
Please consider disabling it now.4月 27 22:12:46 elk102.oldboyedu.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
4月 27 22:12:46 elk102.oldboyedu.com systemd[1]: Stopped firewalld - dynamic firewall daemon.non-zero return code
elk103.oldboyedu.com | FAILED | rc=3 >>
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
4月 27 20:42:38 elk103.oldboyedu.com systemd[1]: Starting firewalld - dynamic firewall daemon...
4月 27 20:42:38 elk103.oldboyedu.com systemd[1]: Started firewalld - dynamic firewall daemon.
4月 27 20:42:39 elk103.oldboyedu.com firewalld[601]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release.
Please consider disabling it now.4月 27 22:12:46 elk103.oldboyedu.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
4月 27 22:12:46 elk103.oldboyedu.com systemd[1]: Stopped firewalld - dynamic firewall daemon.non-zero return code
[root@elk101.oldboyedu.com ~]#
二.zookeeper集群构建实战案例
1.验证各节点环境搭建
(1)验证"elk102.oldboyedu.com"节点
[root@elk102.oldboyedu.com ~]# source /etc/profile.d/zookeeper.sh
[root@elk102.oldboyedu.com ~]#
[root@elk102.oldboyedu.com ~]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
[root@elk102.oldboyedu.com ~]#
(2)验证"elk102.oldboyedu.com"节点
[root@elk103.oldboyedu.com ~]# source /etc/profile.d/zookeeper.sh
[root@elk103.oldboyedu.com ~]#
[root@elk103.oldboyedu.com ~]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
[root@elk103.oldboyedu.com ~]#
2.修改zookeeper的配置文件
(1)修改"elk101.oldboyedu.com"节点的配置文件
[root@elk101.oldboyedu.com ~]# vim /oldboy/softwares/zookeeper/conf/zoo.cfg
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# egrep -v "^#|^$" /oldboy/softwares/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/yinzhengjie/data/zookeeper
clientPort=2181
clientPortAddress=172.200.1.101
server.101=elk101.oldboyedu.com:2888:3888
server.102=elk102.oldboyedu.com:2888:3888
server.103=elk103.oldboyedu.com:2888:3888
[root@elk101.oldboyedu.com ~]#
(2)修改"elk102.oldboyedu.com"节点的配置文件
[root@elk102.oldboyedu.com ~]# vim /oldboy/softwares/zookeeper/conf/zoo.cfg
[root@elk102.oldboyedu.com ~]#
[root@elk102.oldboyedu.com ~]# egrep -v "^#|^$" /oldboy/softwares/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/yinzhengjie/data/zookeeper
clientPort=2181
clientPortAddress=172.200.1.102
server.101=elk101.oldboyedu.com:2888:3888
server.102=elk102.oldboyedu.com:2888:3888
server.103=elk103.oldboyedu.com:2888:3888
[root@elk102.oldboyedu.com ~]#
(3)修改"elk103.oldboyedu.com"节点的配置文件
[root@elk103.oldboyedu.com ~]# vim /oldboy/softwares/zookeeper/conf/zoo.cfg
[root@elk103.oldboyedu.com ~]#
[root@elk103.oldboyedu.com ~]# egrep -v "^#|^$" /oldboy/softwares/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/yinzhengjie/data/zookeeper
clientPort=2181
clientPortAddress=172.200.1.103
server.101=elk101.oldboyedu.com:2888:3888
server.102=elk102.oldboyedu.com:2888:3888
server.103=elk103.oldboyedu.com:2888:3888
[root@elk103.oldboyedu.com ~]#
3.创建配置zookeeper的堆内存配置文件
(1)修改"elk101.oldboyedu.com"节点的配置文件
[root@elk101.oldboyedu.com ~]# vim /oldboy/softwares/zookeeper/conf/java.env
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# cat /oldboy/softwares/zookeeper/conf/java.env
#!/bin/bash
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie
#EMAIL:y1053419035@qq.com
#指定JDK的安装路径
export JAVA_HOME=/oldboy/softwares/jdk
#指定zookeeper的heap内存大小
export JVMFLAGS="-Xms256m -Xmx256m $JVMFLAGS"
[root@elk101.oldboyedu.com ~]#
(2)修改"elk102.oldboyedu.com"节点的配置文件
[root@elk102.oldboyedu.com ~]# vim /oldboy/softwares/zookeeper/conf/java.env
[root@elk102.oldboyedu.com ~]#
[root@elk102.oldboyedu.com ~]# cat /oldboy/softwares/zookeeper/conf/java.env
#!/bin/bash
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie
#EMAIL:y1053419035@qq.com
#指定JDK的安装路径
export JAVA_HOME=/oldboy/softwares/jdk
#指定zookeeper的heap内存大小
export JVMFLAGS="-Xms256m -Xmx256m $JVMFLAGS"
[root@elk102.oldboyedu.com ~]#
(3)修改"elk103.oldboyedu.com"节点的配置文件
[root@elk103.oldboyedu.com ~]# vim /oldboy/softwares/zookeeper/conf/java.env
[root@elk103.oldboyedu.com ~]#
[root@elk103.oldboyedu.com ~]# cat /oldboy/softwares/zookeeper/conf/java.env
#!/bin/bash
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie
#EMAIL:y1053419035@qq.com
#指定JDK的安装路径
export JAVA_HOME=/oldboy/softwares/jdk
#指定zookeeper的heap内存大小
export JVMFLAGS="-Xms256m -Xmx256m $JVMFLAGS"
[root@elk103.oldboyedu.com ~]#
查看JDK的堆内存大小:
jmap -heap `java进程的PID`
温馨提示:
由于我们时测试环境,将堆内存设置为256MB足以,默认为1GB,生产环境中建议最低配置2GB,当然,可以根据JVM的使用情况也可以适当调大。
4.编写zookeeper的启动脚本
[root@elk101.oldboyedu.com ~]# vim /oldboy/softwares/zookeeper/bin/manager-zk.sh
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# cat /oldboy/softwares/zookeeper/bin/manager-zk.sh
#!/bin/bash
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie
#EMAIL:y1053419035@qq.com
#判断用户是否传参
if [ $# -ne 1 ];then
echo "无效参数,用法为: $0 {start|stop|restart|status}"
exit
fi
#获取用户输入的命令
cmd=$1
#定义函数功能
function zookeeperManger(){
case $cmd in
start)
echo "启动服务"
remoteExecution start
;;
stop)
echo "停止服务"
remoteExecution stop
;;
restart)
echo "重启服务"
remoteExecution restart
;;
status)
echo "查看状态"
remoteExecution status
;;
*)
echo "无效参数,用法为: $0 {start|stop|restart|status}"
;;
esac
}
#定义执行的命令
function remoteExecution(){
for (( i=101 ; i<=103 ; i++ )) ; do
tput setaf 2
echo ========== zk${i}.yinzhengjie.com zkServer.sh $1 ================
tput setaf 9
ssh kafka${i}.yinzhengjie.com "source /etc/profile.d/zookeeper.sh; zkServer.sh $1"
done
}
#调用函数
zookeeperManger
[root@elk101.oldboyedu.com ~]#
温馨提示:
该脚本为串行的脚本,建议改为并行执行的脚本,生产环境中建议改为并行的脚本,或者直接使用ansible来实现管理也可以哟~
5.创建myid文件并写入服务器编号
[root@elk101.oldboyedu.com ~]# for (( i=101;i<=103;i++ )) do ssh elk${i}.oldboyedu.com "echo -n $i > /oldboy/data/zookeeper/myid" ;done
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# ansible zk -m shell -a 'cat /yinzhengjie/data/zookeeper/myid'
elk101.oldboyedu.com | CHANGED | rc=0 >>
101
elk102.oldboyedu.com | CHANGED | rc=0 >>
102
elk103.oldboyedu.com | CHANGED | rc=0 >>
103
[root@elk101.oldboyedu.com ~]#
6.查看zookeeper服务
[root@elk101.oldboyedu.com ~]# manager-zk.sh status
查看状态
========== elk101.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.101. Client SSL: false.
Error contacting service. It is probably not running.
========== elk102.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.102. Client SSL: false.
Error contacting service. It is probably not running.
========== elk103.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.103. Client SSL: false.
Error contacting service. It is probably not running.
[root@elk101.oldboyedu.com ~]#
7.启动zookeeper服务
[root@elk101.oldboyedu.com ~]# manager-zk.sh start
启动服务
========== elk101.oldboyedu.com zkServer.sh start ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
========== elk102.oldboyedu.com zkServer.sh start ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
========== elk103.oldboyedu.com zkServer.sh start ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# manager-zk.sh status
查看状态
========== elk101.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.101. Client SSL: false.
Mode: follower
========== elk102.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.102. Client SSL: false.
Mode: leader
========== elk103.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.103. Client SSL: false.
Mode: follower
[root@elk101.oldboyedu.com ~]#
8.连接zookeeper集群
[root@elk103.oldboyedu.com ~]# zkCli.sh -server 172.200.1.101:2181,172.200.1.102:2181,172.200.1.103:2181
Connecting to 172.200.1.101:2181,172.200.1.102:2181,172.200.1.103:2181
2021-04-28 09:44:05,885 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
2021-04-28 09:44:05,887 [myid:] - INFO [main:Environment@98] - Client environment:host.name=elk103.oldboyedu.com
2021-04-28 09:44:05,887 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_201
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/oldboy/softwares/jdk/jre
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/oldboy/softwares/zookeeper/bin/../zookeeper-server/target/classes:/yinzhengjie/softw
ares/zookeeper/bin/../build/classes:/oldboy/softwares/zookeeper/bin/../zookeeper-server/target/lib/*.jar:/oldboy/softwares/zookeeper/bin/../build/lib/*.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-jute-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/snappy-java-1.1.7.7.jar:/oldboy/softwares/zookeeper/bin/../lib/slf4j-log4j12-1.7.30.jar:/oldboy/softwares/zookeeper/bin/../lib/slf4j-api-1.7.30.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_servlet-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_hotspot-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_common-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-resolver-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-handler-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-common-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-codec-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-buffer-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/metrics-core-4.1.12.1.jar:/oldboy/softwares/zookeeper/bin/../lib/log4j-1.2.17.jar:/oldboy/softwares/zookeeper/bin/../lib/jline-2.14.6.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-util-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-server-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-security-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-io-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-http-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/javax.servlet-api-3.1.0.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-databind-2.10.5.1.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-core-2.10.5.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-annotations-2.10.5.jar:/oldboy/softwares/zookeeper/bin/../lib/commons-cli-1.4.jar:/oldboy/softwares/zookeeper/bin/../lib/audience-annotations-0.12.0.jar:/oldboy/softwares/zookeeper/bin/../zookeeper-*.jar:/oldboy/softwares/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/oldboy/softwares/zookeeper/bin/../conf:2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=<NA>
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:os.name=Linux
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:os.arch=amd64
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:os.version=3.10.0-1160.el7.x86_64
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:user.name=root
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:user.home=/root
2021-04-28 09:44:05,889 [myid:] - INFO [main:Environment@98] - Client environment:user.dir=/root
2021-04-28 09:44:05,890 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.free=236MB
2021-04-28 09:44:05,890 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.max=245MB
2021-04-28 09:44:05,890 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.total=245MB
2021-04-28 09:44:05,894 [myid:] - INFO [main:ZooKeeper@637] - Initiating client connection, connectString=172.200.1.101:2181,172.200.1.102:2181,172.200.1.103:2181 sessionTimeout=30000 watc
her=org.apache.zookeeper.ZooKeeperMain$MyWatcher@b065c632021-04-28 09:44:05,899 [myid:] - INFO [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2021-04-28 09:44:05,914 [myid:] - INFO [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2021-04-28 09:44:05,921 [myid:] - INFO [main:ClientCnxn@1726] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2021-04-28 09:44:05,925 [myid:172.200.1.102:2181] - INFO [main-SendThread(172.200.1.102:2181):ClientCnxn$SendThread@1171] - Opening socket connection to server elk102.oldboyedu.com/172
.200.1.102:2181.2021-04-28 09:44:05,925 [myid:172.200.1.102:2181] - INFO [main-SendThread(172.200.1.102:2181):ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL
(unknown error)JLine support is enabled
2021-04-28 09:44:05,944 [myid:172.200.1.102:2181] - INFO [main-SendThread(172.200.1.102:2181):ClientCnxn$SendThread@1005] - Socket connection established, initiating session, client: /172.
200.1.103:38914, server: elk102.oldboyedu.com/172.200.1.102:21812021-04-28 09:44:05,973 [myid:172.200.1.102:2181] - INFO [main-SendThread(172.200.1.102:2181):ClientCnxn$SendThread@1438] - Session establishment complete on server kafka102.yinzhengjie.co
m/172.200.1.102:2181, session id = 0x660002c62ba80000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 172.200.1.101:2181,172.200.1.102:2181,172.200.1.103:2181(CONNECTED) 0]
[zk: 172.200.1.101:2181,172.200.1.102:2181,172.200.1.103:2181(CONNECTED) 0] ls /
[hadoop, hive, k8s0000000001, kafka, kudu, mysql, oldboy, zookeeper]
[zk: 172.200.1.101:2181,172.200.1.102:2181,172.200.1.103:2181(CONNECTED) 1]
[zk: 172.200.1.101:2181,172.200.1.102:2181,172.200.1.103:2181(CONNECTED) 1] quit
2021-04-28 09:44:25,139 [myid:172.200.1.102:2181] - WARN [main-SendThread(172.200.1.102:2181):ClientCnxn$SendThread@1284] - An exception was thrown while closing send thread for session 0x
660002c62ba80000.EndOfStreamException: Unable to read additional data from server sessionid 0x660002c62ba80000, likely server has closed socket
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:77)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1280)
WATCHER::
WatchedEvent state:Closed type:None path:null
2021-04-28 09:44:25,242 [myid:] - INFO [main:ZooKeeper@1232] - Session: 0x660002c62ba80000 closed
2021-04-28 09:44:25,242 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@570] - EventThread shut down for session: 0x660002c62ba80000
2021-04-28 09:44:25,243 [myid:] - ERROR [main:ServiceUtils@42] - Exiting JVM with code 0
[root@elk103.oldboyedu.com ~]#
三.observer角色及其配置
1.observer角色特点
observer角色特点如下所示:
(1)不参与集群的leader选举;
(2)不参与集群中写数据时的ack反馈;
2.修改配置文件
[root@elk101.oldboyedu.com ~]# vim /oldboy/softwares/zookeeper/conf/zoo.cfg
[root@elk101.oldboyedu.com ~]#
[root@elk101.oldboyedu.com ~]# egrep -v "^#|^$" /oldboy/softwares/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/yinzhengjie/data/zookeeper
clientPort=2181
clientPortAddress=172.200.1.101
peerType=observer
server.101=elk101.oldboyedu.com:2888:3888:observer
server.102=elk102.oldboyedu.com:2888:3888
server.103=elk103.oldboyedu.com:2888:3888
[root@elk101.oldboyedu.com ~]#
温馨提示:
如果我们将某个节点(本案例为kafka101节点)的配置文件中存在"peerType=observer"时,请将"server.101"哪行配置追加":observer"哟~
3.重启集群
[root@elk101.oldboyedu.com ~]# manager-zk.sh restart
重启服务
========== elk101.oldboyedu.com zkServer.sh restart ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
========== elk102.oldboyedu.com zkServer.sh restart ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
========== elk103.oldboyedu.com zkServer.sh restart ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@elk101.oldboyedu.com ~]#
4.查看集群状态
[root@elk101.oldboyedu.com ~]# manager-zk.sh status
查看状态
========== elk101.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.101. Client SSL: false.
Mode: observer
========== elk102.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.102. Client SSL: false.
Mode: leader
========== elk103.oldboyedu.com zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 172.200.1.103. Client SSL: false.
Mode: follower
[root@elk101.oldboyedu.com ~]#
5.连接observer节点
[root@elk103.oldboyedu.com ~]# zkCli.sh -server 172.200.1.101:2181
Connecting to 172.200.1.101:2181
2021-04-28 12:01:15,622 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
2021-04-28 12:01:15,624 [myid:] - INFO [main:Environment@98] - Client environment:host.name=elk103.oldboyedu.com
2021-04-28 12:01:15,624 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_201
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/oldboy/softwares/jdk/jre
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/oldboy/softwares/zookeeper/bin/../zookeeper-server/target/classes:/yinzhengjie/softw
ares/zookeeper/bin/../build/classes:/oldboy/softwares/zookeeper/bin/../zookeeper-server/target/lib/*.jar:/oldboy/softwares/zookeeper/bin/../build/lib/*.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-jute-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/snappy-java-1.1.7.7.jar:/oldboy/softwares/zookeeper/bin/../lib/slf4j-log4j12-1.7.30.jar:/oldboy/softwares/zookeeper/bin/../lib/slf4j-api-1.7.30.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_servlet-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_hotspot-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_common-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-resolver-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-handler-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-common-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-codec-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-buffer-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/metrics-core-4.1.12.1.jar:/oldboy/softwares/zookeeper/bin/../lib/log4j-1.2.17.jar:/oldboy/softwares/zookeeper/bin/../lib/jline-2.14.6.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-util-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-server-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-security-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-io-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-http-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/javax.servlet-api-3.1.0.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-databind-2.10.5.1.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-core-2.10.5.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-annotations-2.10.5.jar:/oldboy/softwares/zookeeper/bin/../lib/commons-cli-1.4.jar:/oldboy/softwares/zookeeper/bin/../lib/audience-annotations-0.12.0.jar:/oldboy/softwares/zookeeper/bin/../zookeeper-*.jar:/oldboy/softwares/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/oldboy/softwares/zookeeper/bin/../conf:2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=<NA>
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:os.name=Linux
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:os.arch=amd64
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:os.version=3.10.0-1160.el7.x86_64
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:user.name=root
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:user.home=/root
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:user.dir=/root
2021-04-28 12:01:15,626 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.free=236MB
2021-04-28 12:01:15,627 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.max=245MB
2021-04-28 12:01:15,627 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.total=245MB
2021-04-28 12:01:15,630 [myid:] - INFO [main:ZooKeeper@637] - Initiating client connection, connectString=172.200.1.101:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain
$MyWatcher@b065c632021-04-28 12:01:15,634 [myid:] - INFO [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2021-04-28 12:01:15,639 [myid:] - INFO [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2021-04-28 12:01:15,646 [myid:] - INFO [main:ClientCnxn@1726] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2021-04-28 12:01:15,662 [myid:172.200.1.101:2181] - INFO [main-SendThread(172.200.1.101:2181):ClientCnxn$SendThread@1171] - Opening socket connection to server elk101.oldboyedu.com/172
.200.1.101:2181.2021-04-28 12:01:15,663 [myid:172.200.1.101:2181] - INFO [main-SendThread(172.200.1.101:2181):ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL
(unknown error)2021-04-28 12:01:15,672 [myid:172.200.1.101:2181] - INFO [main-SendThread(172.200.1.101:2181):ClientCnxn$SendThread@1005] - Socket connection established, initiating session, client: /172.
200.1.103:43972, server: elk101.oldboyedu.com/172.200.1.101:2181JLine support is enabled
2021-04-28 12:01:15,716 [myid:172.200.1.101:2181] - INFO [main-SendThread(172.200.1.101:2181):ClientCnxn$SendThread@1438] - Session establishment complete on server kafka101.yinzhengjie.co
m/172.200.1.101:2181, session id = 0x650004a20e370000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 172.200.1.101:2181(CONNECTED) 0]
[zk: 172.200.1.101:2181(CONNECTED) 0] ls /
[hadoop, hive, k8s0000000001, kafka, kudu, mysql, oldboy, zookeeper]
[zk: 172.200.1.101:2181(CONNECTED) 1]
[zk: 172.200.1.101:2181(CONNECTED) 1] create /spark "Spark"
Created /spark
[zk: 172.200.1.101:2181(CONNECTED) 2]
[zk: 172.200.1.101:2181(CONNECTED) 2] ls /
[hadoop, hive, k8s0000000001, kafka, kudu, mysql, oldboy, spark, zookeeper]
[zk: 172.200.1.101:2181(CONNECTED) 3]
[zk: 172.200.1.101:2181(CONNECTED) 3]
温馨提示:
如上所示,我们可以连接观察者(observer)节点并写入数据,但我们要知道真正负责写入的是leader节点,写请求被observer转发给leader节点啦!