分布式协调服务Zookeeper集群搭建

              分布式协调服务Zookeeper集群搭建

                                           作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

 

一.安装jdk环境

1>.操作环境

[root@node101.yinzhengjie.org.cn ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# uname -r
3.10.0-957.el7.x86_64
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# uname -m
x86_64
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/hosts | grep yinzhengjie            #注意,本片博客只有3台测试机,每台测试机器必须得配置jdk环境!
172.30.1.101 node101.yinzhengjie.org.cn
172.30.1.102 node102.yinzhengjie.org.cn
172.30.1.103 node103.yinzhengjie.org.cn
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        331M        2.9G        9.4M        570M        3.3G
Swap:          2.0G          0B        2.0G
[root@node101.yinzhengjie.org.cn ~]# 

2>.打开Oracle官方网站下载相应的平台的安装包(https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

3>.卸载平台中已经存在的JDK版本 

[root@node101.yinzhengjie.org.cn ~]# java -version
openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# rpm -qa *openjdk*
java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.5.el7.x86_64
java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64
java-11-openjdk-headless-11.0.ea.28-7.el7.x86_64
java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64
java-11-openjdk-11.0.ea.28-7.el7.x86_64
java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.5.el7.x86_64          #卸载JDK版本!
[root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64
[root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64
[root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-11-openjdk-headless-11.0.ea.28-7.el7.x86_64
[root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64
[root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-11-openjdk-11.0.ea.28-7.el7.x86_64
[root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# rpm -qa *openjdk*
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# java -version
-bash: /usr/bin/java: No such file or directory
[root@node101.yinzhengjie.org.cn ~]#

4>.将下载的jdk版本进行解压安装并配置环境变量(如果你下载的是rpm包的oracle jdk的话就无需配置环境变量啦!)

[root@node101.yinzhengjie.org.cn ~]# mkdir /yinzhengjie/softwares -p
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# tar -zxf jdk-8u201-linux-x64.tar.gz -C /yinzhengjie/softwares/
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/jdk1.8.0_201/
total 383856
drwxr-xr-x. 2   10  143      4096 Dec 16 03:45 bin
-r--r--r--. 1   10  143      3244 Dec 16 03:45 COPYRIGHT
-rw-r--r--. 1 root root 366447449 Apr  9 15:27 hadoop-2.9.2.tar.gz
drwxr-xr-x. 3   10  143      4096 Dec 16 03:45 include
-rw-r--r--. 1   10  143   5207434 Dec 12 17:07 javafx-src.zip
drwxr-xr-x. 5   10  143      4096 Dec 16 03:45 jre
drwxr-xr-x. 5   10  143      4096 Dec 16 03:45 lib
-r--r--r--. 1   10  143        40 Dec 16 03:45 LICENSE
drwxr-xr-x. 4   10  143      4096 Dec 16 03:45 man
-r--r--r--. 1   10  143       159 Dec 16 03:45 README.html
-rw-r--r--. 1   10  143       424 Dec 16 03:45 release
-rw-r--r--. 1   10  143  21103945 Dec 16 03:45 src.zip
-rw-r--r--. 1   10  143    108109 Dec 12 17:07 THIRDPARTYLICENSEREADME-JAVAFX.txt
-r--r--r--. 1   10  143    155002 Dec 16 03:45 THIRDPARTYLICENSEREADME.txt
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# tail -3 /etc/profile
#Add by yinzhengjie
JAVA_HOME=/yinzhengjie/softwares/jdk1.8.0_201
PATH=$PATH:$JAVA_HOME/bin
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# source /etc/profile
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 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@node101.yinzhengjie.org.cn ~]#

5>.将环境同步到其他节点 

[root@node101.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
Generating public/private rsa key pair.
Created directory '/root/.ssh'.
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:Ytkk9uzXOlYJPLDRaUAyqDzYv1n3CRk6NjN/nuhDbDo root@node101.yinzhengjie.org.cn
The key's randomart image is:
+---[RSA 2048]----+
|     .o.oo .     |
|    .  oo +      |
| + .  o .*       |
|. =  . Bo +      |
|   o  +oSo o .   |
|    ..OoB  .o    |
|     = @.o.o.    |
|    o E oo*o     |
|       oo=+.     |
+----[SHA256]-----+
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
[root@node101.yinzhengjie.org.cn ~]# ssh-copy-id root@node102.yinzhengjie.org.cn
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node102.yinzhengjie.org.cn (172.30.1.102)' can't be established.
ECDSA key fingerprint is SHA256:rDA5nSO2LcozxK76hXrtZ1xiXXZTXqQWu+wkBdpMDQA.
ECDSA key fingerprint is MD5:fd:75:9d:2b:28:ef:a2:0c:e2:c5:fc:fb:e9:5f:ee:c1.
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@node102.yinzhengjie.org.cn's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@node102.yinzhengjie.org.cn'"
and check to make sure that only the key(s) you wanted were added.

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ssh-copy-id root@node102.yinzhengjie.org.cn
[root@node101.yinzhengjie.org.cn ~]# ssh-copy-id root@node103.yinzhengjie.org.cn
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node103.yinzhengjie.org.cn (172.30.1.103)' can't be established.
ECDSA key fingerprint is SHA256:5ucWsWQo98ucT5KLfpkXT9DtxurZgMQEMAtynmncvvE.
ECDSA key fingerprint is MD5:6b:fd:ed:8e:83:33:86:97:b0:4c:9f:23:87:50:85:4e.
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@node103.yinzhengjie.org.cn's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@node103.yinzhengjie.org.cn'"
and check to make sure that only the key(s) you wanted were added.

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ssh-copy-id root@node103.yinzhengjie.org.cn
[root@node101.yinzhengjie.org.cn ~]# scp -r /yinzhengjie/ root@node102.yinzhengjie.org.cn:/ 
......
org.eclipse.equinox.p2.ql_2.0.100.v20131211-1531.jar                                                                                                                             100% 8979    17.5MB/s   00:00    
org.eclipse.e4.ui.workbench.addons.swt.nl_zh_4.4.0.v20140623020002.jar                                                                                                           100% 2738     6.2MB/s   00:00    
com.jrockit.mc.flightrecorder.configuration_5.5.2.174165.jar                                                                                                                     100% 3397     7.7MB/s   00:00    
org.eclipse.equinox.p2.engine.nl_zh_4.4.0.v20140623020002.jar                                                                                                                    100% 2592     5.6MB/s   00:00    
org.eclipse.osgi.services_3.4.0.v20140312-2051.jar                                                                                                                               100%   88KB  66.5MB/s   00:00    
com.jrockit.mc.greychartplugin_5.5.2.174165.jar                                                                                                                                  100%  131KB  72.1MB/s   00:00    
org.eclipse.equinox.p2.touchpoint.natives_1.1.100.v20140523-0116.jar                                                                                                             100%   52KB  55.8MB/s   00:00    
org.eclipse.ui.net.nl_zh_4.4.0.v20140623020002.jar                                                                                                                               100% 2868     7.8MB/s   00:00    
org.eclipse.equinox.p2.ui.nl_zh_4.4.0.v20140623020002.jar                                                                                                                        100% 4529    10.3MB/s   00:00    
org.eclipse.core.filesystem_1.4.100.v20140514-1614.jar                                                                                                                           100%   57KB  47.0MB/s   00:00    
org.eclipse.equinox.p2.director.app.nl_zh_4.4.0.v20140623020002.jar                                                                                                              100% 2613     3.7MB/s   00:00    
org.eclipse.e4.core.contexts_1.3.100.v20140407-1019.jar                                                                                                                          100%   48KB  22.5MB/s   00:00    
com.jrockit.mc.rjmx.ui.ja_5.5.2.174165.jar                                                                                                                                       100% 9550    14.1MB/s   00:00    
org.eclipse.equinox.simpleconfigurator.manipulator_2.0.0.v20131217-1203.jar                                                                                                      100%   25KB  35.9MB/s   00:00    
org.eclipse.equinox.p2.engine.nl_ja_4.4.0.v20140623020002.jar                                                                                                                    100% 4522    11.0MB/s   00:00    
org.eclipse.jface.databinding_1.6.200.v20140528-1422.jar                                                                                                                         100%  271KB  89.7MB/s   00:00    
org.eclipse.core.resources_3.9.1.v20140825-1431.jar                                                                                                                              100%  814KB  90.9MB/s   00:00    
com.jrockit.mc.common_5.5.2.174165.jar                                                                                                                                           100%  240KB  86.9MB/s   00:00    
artifacts.xml                                                                                                                                                                    100% 1388     3.2MB/s   00:00    
com.oracle.jmc.executable.gtk.linux.x86_64_5.5.2                                                                                                                                 100%   43KB  45.9MB/s   00:00    
com.jrockit.mc.rcp.product_root_5.5.2.174165                                                                                                                                     100% 3816KB 101.7MB/s   00:00    
org.eclipse.rcp_root_4.4.0.v20141007-2301                                                                                                                                        100%   36KB  42.6MB/s   00:00    
org.eclipse.equinox.p2.metadata.repository.prefs                                                                                                                                 100% 3405     5.4MB/s   00:00    
org.eclipse.equinox.p2.artifact.repository.prefs                                                                                                                                 100% 8028    10.3MB/s   00:00    
1512678761228.profile.gz                                                                                                                                                         100%  105KB  65.7MB/s   00:00    
.lock                                                                                                                                                                            100%    0     0.0KB/s   00:00    
1512678763613.profile.gz                                                                                                                                                         100%  105KB  75.2MB/s   00:00    
1512678749009.profile.gz                                                                                                                                                         100%  364   982.8KB/s   00:00    
1512678748591.profile.gz                                                                                                                                                         100%  360   972.2KB/s   00:00    
ct.sym                                                                                                                                                                           100%   17MB 115.5MB/s   00:00    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# scp -r /yinzhengjie/ root@node102.yinzhengjie.org.cn:/
[root@node101.yinzhengjie.org.cn ~]# scp -r /yinzhengjie/ root@node103.yinzhengjie.org.cn:/
......
org.eclipse.equinox.p2.ql_2.0.100.v20131211-1531.jar                                                                                                                             100% 8979    15.9MB/s   00:00    
org.eclipse.e4.ui.workbench.addons.swt.nl_zh_4.4.0.v20140623020002.jar                                                                                                           100% 2738     6.2MB/s   00:00    
com.jrockit.mc.flightrecorder.configuration_5.5.2.174165.jar                                                                                                                     100% 3397     6.4MB/s   00:00    
org.eclipse.equinox.p2.engine.nl_zh_4.4.0.v20140623020002.jar                                                                                                                    100% 2592     5.2MB/s   00:00    
org.eclipse.osgi.services_3.4.0.v20140312-2051.jar                                                                                                                               100%   88KB  58.9MB/s   00:00    
com.jrockit.mc.greychartplugin_5.5.2.174165.jar                                                                                                                                  100%  131KB  74.8MB/s   00:00    
org.eclipse.equinox.p2.touchpoint.natives_1.1.100.v20140523-0116.jar                                                                                                             100%   52KB  59.2MB/s   00:00    
org.eclipse.ui.net.nl_zh_4.4.0.v20140623020002.jar                                                                                                                               100% 2868     7.9MB/s   00:00    
org.eclipse.equinox.p2.ui.nl_zh_4.4.0.v20140623020002.jar                                                                                                                        100% 4529    10.3MB/s   00:00    
org.eclipse.core.filesystem_1.4.100.v20140514-1614.jar                                                                                                                           100%   57KB  55.4MB/s   00:00    
org.eclipse.equinox.p2.director.app.nl_zh_4.4.0.v20140623020002.jar                                                                                                              100% 2613     6.7MB/s   00:00    
org.eclipse.e4.core.contexts_1.3.100.v20140407-1019.jar                                                                                                                          100%   48KB  56.7MB/s   00:00    
com.jrockit.mc.rjmx.ui.ja_5.5.2.174165.jar                                                                                                                                       100% 9550    15.2MB/s   00:00    
org.eclipse.equinox.simpleconfigurator.manipulator_2.0.0.v20131217-1203.jar                                                                                                      100%   25KB  29.7MB/s   00:00    
org.eclipse.equinox.p2.engine.nl_ja_4.4.0.v20140623020002.jar                                                                                                                    100% 4522     8.3MB/s   00:00    
org.eclipse.jface.databinding_1.6.200.v20140528-1422.jar                                                                                                                         100%  271KB  77.4MB/s   00:00    
org.eclipse.core.resources_3.9.1.v20140825-1431.jar                                                                                                                              100%  814KB 100.5MB/s   00:00    
com.jrockit.mc.common_5.5.2.174165.jar                                                                                                                                           100%  240KB  85.6MB/s   00:00    
artifacts.xml                                                                                                                                                                    100% 1388     3.2MB/s   00:00    
com.oracle.jmc.executable.gtk.linux.x86_64_5.5.2                                                                                                                                 100%   43KB  40.6MB/s   00:00    
com.jrockit.mc.rcp.product_root_5.5.2.174165                                                                                                                                     100% 3816KB 101.1MB/s   00:00    
org.eclipse.rcp_root_4.4.0.v20141007-2301                                                                                                                                        100%   36KB  34.7MB/s   00:00    
org.eclipse.equinox.p2.metadata.repository.prefs                                                                                                                                 100% 3405     6.9MB/s   00:00    
org.eclipse.equinox.p2.artifact.repository.prefs                                                                                                                                 100% 8028    16.2MB/s   00:00    
1512678761228.profile.gz                                                                                                                                                         100%  105KB  40.2MB/s   00:00    
.lock                                                                                                                                                                            100%    0     0.0KB/s   00:00    
1512678763613.profile.gz                                                                                                                                                         100%  105KB  68.5MB/s   00:00    
1512678749009.profile.gz                                                                                                                                                         100%  364     1.1MB/s   00:00    
1512678748591.profile.gz                                                                                                                                                         100%  360   905.7KB/s   00:00    
ct.sym                                                                                                                                                                           100%   17MB 115.2MB/s   00:00    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# scp -r /yinzhengjie/ root@node103.yinzhengjie.org.cn:/ 
[root@node101.yinzhengjie.org.cn ~]# scp /etc/profile root@node102.yinzhengjie.org.cn:/etc/
profile                                                                                                                                                                          100% 1912     2.6MB/s   00:00    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# scp /etc/profile root@node102.yinzhengjie.org.cn:/etc/
[root@node101.yinzhengjie.org.cn ~]# scp /etc/profile root@node103.yinzhengjie.org.cn:/etc/
profile                                                                                                                                                                          100% 1912     2.5MB/s   00:00    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# scp /etc/profile root@node103.yinzhengjie.org.cn:/etc/

6>.安装ansible软件

[root@node101.yinzhengjie.org.cn ~/Downloads]# yum -y install ansible
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                                                               | 3.6 kB  00:00:00     
extras                                                                                                                                                                                                             | 3.4 kB  00:00:00     
updates                                                                                                                                                                                                            | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                                                                                                                                  | 187 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                                                                                                                                 | 3.4 MB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.4.2.0-2.el7 will be installed
--> Processing Dependency: sshpass for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python2-jmespath for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-passlib for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-paramiko for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-jinja2 for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-httplib2 for package: ansible-2.4.2.0-2.el7.noarch
--> Running transaction check
---> Package python-httplib2.noarch 0:0.9.2-1.el7 will be installed
---> Package python-jinja2.noarch 0:2.7.2-2.el7 will be installed
--> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-2.el7.noarch
--> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-2.el7.noarch
---> Package python-paramiko.noarch 0:2.1.1-9.el7 will be installed
---> Package python-passlib.noarch 0:1.6.5-2.el7 will be installed
---> Package python2-jmespath.noarch 0:0.9.0-3.el7 will be installed
---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
--> Running transaction check
---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed
---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================================================================================
 Package                                                        Arch                                                Version                                                    Repository                                            Size
==========================================================================================================================================================================================================================================
Installing:
 ansible                                                        noarch                                              2.4.2.0-2.el7                                              extras                                               7.6 M
Installing for dependencies:
 python-babel                                                   noarch                                              0.9.6-8.el7                                                base                                                 1.4 M
 python-httplib2                                                noarch                                              0.9.2-1.el7                                                extras                                               115 k
 python-jinja2                                                  noarch                                              2.7.2-2.el7                                                base                                                 515 k
 python-markupsafe                                              x86_64                                              0.11-10.el7                                                base                                                  25 k
 python-paramiko                                                noarch                                              2.1.1-9.el7                                                updates                                              269 k
 python-passlib                                                 noarch                                              1.6.5-2.el7                                                extras                                               488 k
 python2-jmespath                                               noarch                                              0.9.0-3.el7                                                extras                                                39 k
 sshpass                                                        x86_64                                              1.06-2.el7                                                 extras                                                21 k

Transaction Summary
==========================================================================================================================================================================================================================================
Install  1 Package (+8 Dependent packages)

Total download size: 10 M
Installed size: 51 M
Downloading packages:
python-httplib2-0.9.2-1.el7.no FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/Packages/python-httplib2-0.9.2-1.el7.noarch.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"       ]  0.0 B/s |    0 B  --:--:-- ETA 
Trying other mirror.
python-jinja2-2.7.2-2.el7.noar FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/python-jinja2-2.7.2-2.el7.noarch.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"             ]  0.0 B/s |    0 B  --:--:-- ETA 
Trying other mirror.
(1/9): python-markupsafe-0.11-10.el7.x86_64.rpm                                                                                                                                                                    |  25 kB  00:00:00     
(2/9): python-babel-0.9.6-8.el7.noarch.rpm                                                                                                                                                                         | 1.4 MB  00:00:00     
(3/9): python-paramiko-2.1.1-9.el7.noarch.rpm                                                                                                                                                                      | 269 kB  00:00:01     
(4/9): ansible-2.4.2.0-2.el7.noarch.rpm                                                                                                                                                                            | 7.6 MB  00:00:04     
(5/9): python2-jmespath-0.9.0-3.el7.noarch.rpm                                                                                                                                                                     |  39 kB  00:00:00     
(6/9): sshpass-1.06-2.el7.x86_64.rpm                                                                                                                                                                               |  21 kB  00:00:00     
(7/9): python-httplib2-0.9.2-1.el7.noarch.rpm                                                                                                                                                                      | 115 kB  00:00:00     
(8/9): python-jinja2-2.7.2-2.el7.noarch.rpm                                                                                                                                                                        | 515 kB  00:00:00     
(9/9): python-passlib-1.6.5-2.el7.noarch.rpm                                                                                                                                                                       | 488 kB  00:00:05     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                     1.7 MB/s |  10 MB  00:00:06     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python-httplib2-0.9.2-1.el7.noarch                                                                                                                                                                                     1/9 
  Installing : sshpass-1.06-2.el7.x86_64                                                                                                                                                                                              2/9 
  Installing : python-babel-0.9.6-8.el7.noarch                                                                                                                                                                                        3/9 
  Installing : python-paramiko-2.1.1-9.el7.noarch                                                                                                                                                                                     4/9 
  Installing : python2-jmespath-0.9.0-3.el7.noarch                                                                                                                                                                                    5/9 
  Installing : python-passlib-1.6.5-2.el7.noarch                                                                                                                                                                                      6/9 
  Installing : python-markupsafe-0.11-10.el7.x86_64                                                                                                                                                                                   7/9 
  Installing : python-jinja2-2.7.2-2.el7.noarch                                                                                                                                                                                       8/9 
  Installing : ansible-2.4.2.0-2.el7.noarch                                                                                                                                                                                           9/9 
  Verifying  : python-markupsafe-0.11-10.el7.x86_64                                                                                                                                                                                   1/9 
  Verifying  : python-jinja2-2.7.2-2.el7.noarch                                                                                                                                                                                       2/9 
  Verifying  : python-passlib-1.6.5-2.el7.noarch                                                                                                                                                                                      3/9 
  Verifying  : python2-jmespath-0.9.0-3.el7.noarch                                                                                                                                                                                    4/9 
  Verifying  : python-paramiko-2.1.1-9.el7.noarch                                                                                                                                                                                     5/9 
  Verifying  : python-babel-0.9.6-8.el7.noarch                                                                                                                                                                                        6/9 
  Verifying  : ansible-2.4.2.0-2.el7.noarch                                                                                                                                                                                           7/9 
  Verifying  : sshpass-1.06-2.el7.x86_64                                                                                                                                                                                              8/9 
  Verifying  : python-httplib2-0.9.2-1.el7.noarch                                                                                                                                                                                     9/9 

Installed:
  ansible.noarch 0:2.4.2.0-2.el7                                                                                                                                                                                                          

Dependency Installed:
  python-babel.noarch 0:0.9.6-8.el7      python-httplib2.noarch 0:0.9.2-1.el7  python-jinja2.noarch 0:2.7.2-2.el7  python-markupsafe.x86_64 0:0.11-10.el7  python-paramiko.noarch 0:2.1.1-9.el7  python-passlib.noarch 0:1.6.5-2.el7 
  python2-jmespath.noarch 0:0.9.0-3.el7  sshpass.x86_64 0:1.06-2.el7          

Complete!
[root@node101.yinzhengjie.org.cn ~/Downloads]# 
[root@node101.yinzhengjie.org.cn ~/Downloads]# yum -y install ansible
[root@node101.yinzhengjie.org.cn ~]# tail -5 /etc/ansible/hosts                                 #编辑ansible的主机配置文件
[namenode]
node101.yinzhengjie.org.cn

[datanode]
node[101:103].yinzhengjie.org.cn
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# tail -5 /etc/ansible/hosts                                             #编辑ansible的主机配置文件
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'ln -s /yinzhengjie/softwares/jdk1.8.0_201/bin/jps /usr/local/bin/'
 [WARNING]: Consider using file module with state=link rather than running ln

node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>


[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'ln -s /yinzhengjie/softwares/jdk1.8.0_201/bin/jps /usr/local/bin/'      #测试ansible是否可用

 

二.搭建zookeeper集群

1>.下载zookeeper软件(下载地址:https://www.apache.org/dyn/closer.cgi/zookeeper/ 

[root@node101.yinzhengjie.org.cn ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
--2019-04-12 08:48:40--  https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 37676320 (36M) [application/x-gzip]
Saving to: ‘zookeeper-3.4.14.tar.gz’

100%[============================================================================================================================================>] 37,676,320  7.57MB/s   in 4.5s   

2019-04-12 08:48:45 (7.94 MB/s) - ‘zookeeper-3.4.14.tar.gz’ saved [37676320/37676320]

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz

2>.解压zookeeper并配置环境变量

[root@node101.yinzhengjie.org.cn ~]# tar -zxf zookeeper-3.4.14.tar.gz -C /yinzhengjie/softwares/
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zookeeper-3.4.14/
total 1672
drwxr-xr-x  2 2002 2002     202 Mar  6 09:09 bin
-rw-rw-r--  1 2002 2002   97426 Mar  6 08:50 build.xml
drwxr-xr-x  2 2002 2002      77 Mar  6 09:09 conf
drwxr-xr-x  2 2002 2002    4096 Mar  6 09:10 dist-maven
-rw-rw-r--  1 2002 2002    1709 Mar  6 08:50 ivysettings.xml
-rw-rw-r--  1 2002 2002   10742 Mar  6 08:50 ivy.xml
drwxr-xr-x  4 2002 2002     308 Mar  6 09:09 lib
-rw-rw-r--  1 2002 2002   11970 Mar  6 08:50 LICENSE.txt
-rw-rw-r--  1 2002 2002    3132 Mar  6 08:50 NOTICE.txt
-rw-rw-r--  1 2002 2002   31622 Mar  6 08:50 pom.xml
-rw-rw-r--  1 2002 2002    1765 Mar  6 08:50 README.md
-rw-rw-r--  1 2002 2002    1770 Mar  6 08:50 README_packaging.txt
drwxr-xr-x  3 2002 2002      22 Mar  6 08:50 src
-rw-rw-r--  1 2002 2002 1515359 Mar  6 08:50 zookeeper-3.4.14.jar
-rw-rw-r--  1 2002 2002     836 Mar  6 09:10 zookeeper-3.4.14.jar.asc
-rw-rw-r--  1 2002 2002      33 Mar  6 08:50 zookeeper-3.4.14.jar.md5
-rw-rw-r--  1 2002 2002      41 Mar  6 08:50 zookeeper-3.4.14.jar.sha1
drwxr-xr-x  3 2002 2002      47 Mar  6 09:09 zookeeper-client
drwxr-xr-x 12 2002 2002    4096 Mar  6 09:09 zookeeper-contrib
drwxr-xr-x  7 2002 2002    4096 Mar  6 09:09 zookeeper-docs
drwxr-xr-x  3 2002 2002      35 Mar  6 09:09 zookeeper-it
drwxr-xr-x  4 2002 2002      46 Mar  6 09:09 zookeeper-jute
drwxr-xr-x  5 2002 2002     176 Mar  6 09:09 zookeeper-recipes
drwxr-xr-x  3 2002 2002      32 Mar  6 09:09 zookeeper-server
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# tar -zxf zookeeper-3.4.14.tar.gz -C /yinzhengjie/softwares/
[root@node101.yinzhengjie.org.cn ~]# tail -3 /etc/profile
#ADD ZOOKEEPER_HOME PATH
ZOOKEEPER_HOME=/yinzhengjie/softwares/zookeeper-3.4.14
PATH=$PATH:$ZOOKEEPER_HOME/bin
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# source /etc/profile
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# tail -3 /etc/profile

3>.配置zookeeper的配置文件

[root@node101.yinzhengjie.org.cn ~]# cp /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo_sample.cfg /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo.cfg 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zookeeper-3.4.14/conf/
total 16
-rw-rw-r-- 1 2002 2002  535 Mar  6 08:50 configuration.xsl
-rw-rw-r-- 1 2002 2002 2161 Mar  6 08:50 log4j.properties
-rw-r--r-- 1 root root  922 Apr 12 08:55 zoo.cfg
-rw-rw-r-- 1 2002 2002  922 Mar  6 08:50 zoo_sample.cfg
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cp /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo_sample.cfg /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo.cfg
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo.cfg 
# 滴答,计时的基本单位,默认是2000毫秒,即2秒。它是zookeeper最小的时间单位,用于丈量心跳时间和超时时间等,通常设置成默认2秒即可。
tickTime=2000

# 初始化限制是10滴答,默认是10个滴答,即默认是20秒。指定follower节点初始化是链接leader节点的最大tick次数。
initLimit=5

# 数据同步的时间限制,默认是5个滴答,即默认时间是10秒。设定了follower节点与leader节点进行同步的最大时间。与initLimit类似,它也是以tickTime为单位进行指定的。
syncLimit=2

# 指定zookeeper的工作目录,这是一个非常重要的参数,zookeeper会在内存中在内存只能中保存系统快照,并定期写入该路径指定的文件夹中。生产环境中需要注意该文件夹的磁盘占用情况。
dataDir=/home/yinzhengjie/zookeeper

# 监听zookeeper的默认端口。zookeeper监听客户端链接的端口,一般设置成默认2181即可。
clientPort=2181

# 这个操作将限制连接到 ZooKeeper 的客户端的数量,限制并发连接的数量,它通过 IP 来区分不同的客户端。此配置选项可以用来阻止某些类别的 Dos 攻击。将它设置为 0 或者忽略而不进行设置将会取消对并发连接的限制。
#maxClientCnxns=60
 
# 在上文中已经提到,3.4.0及之后版本,ZK提供了自动清理事务日志和快照文件的功能,这个参数指定了清理频率,单位是小时,需要配置一个1或更大的整数,默认是0,表示不开启自动清理功能。
#autopurge.purgeInterval=1

# 这个参数和上面的参数搭配使用,这个参数指定了需要保留的文件数目。默认是保留3个。
#autopurge.snapRetainCount=3

#server.x=[hostname]:nnnnn[:nnnnn],这里的x是一个数字,与myid文件中的id是一致的。右边可以配置两个端口,第一个端口用于F和L之间的数据同步和其它通信,第二个端口用于Leader选举过程中投票通信。  
server.101=node101.yinzhengjie.org.cn:2888:3888
server.102=node102.yinzhengjie.org.cn:2888:3888
server.103=node103.yinzhengjie.org.cn:2888:3888
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo.cfg
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/zookeeper-3.4.14/conf/java.env
#!/bin/bash
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie
#EMAIL:y1053419035@qq.com

#指定JDK的安装路径
export JAVA_HOME=/yinzhengjie/softwares/jdk1.8.0_201

#指定zookeeper的heap内存大小
export JVMFLAGS="-Xms256m -Xmx256m $JVMFLAGS"
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/zookeeper-3.4.14/conf/java.env          #创建配置zookeeper的堆内存配置文件

4>.编写zookeeper的启动脚本

[root@node101.yinzhengjie.org.cn ~]# vi /usr/local/bin/xzk.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /usr/local/bin/xzk.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 ========== node${i}.yinzhengjie.org.cn zkServer.sh  $1 ================
            tput setaf 9
            ssh node${i}.yinzhengjie.org.cn  "source /etc/profile ; zkServer.sh $1"
    done
}

#调用函数
zookeeperManger
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# vi /usr/local/bin/xzk.sh
[root@node101.yinzhengjie.org.cn ~]# ll /usr/local/bin/xzk.sh
-rw-r--r-- 1 root root 1125 Apr 12 09:03 /usr/local/bin/xzk.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# chmod +x /usr/local/bin/xzk.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /usr/local/bin/xzk.sh
-rwxr-xr-x 1 root root 1125 Apr 12 09:03 /usr/local/bin/xzk.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# chmod +x /usr/local/bin/xzk.sh

5>.创建myid文件并写入服务器编号

[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'mkdir /home/yinzhengjie/zookeeper/'
 [WARNING]: Consider using file module with state=directory rather than running mkdir

node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>


[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'mkdir /home/yinzhengjie/zookeeper/'
[root@node101.yinzhengjie.org.cn ~]# for (( i=101;i<=103;i++ )) do ssh node${i}.yinzhengjie.org.cn "echo -n $i > /home/yinzhengjie/zookeeper/myid" ;done
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'cat /home/yinzhengjie/zookeeper/myid'
node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
102

node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
103

node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
101

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# for (( i=101;i<=103;i++ )) do ssh node${i}.yinzhengjie.org.cn "echo -n $i > /home/yinzhengjie/zookeeper/myid" ;done

6>.分发配置文件

[root@node101.yinzhengjie.org.cn ~]# scp /etc/profile node102.yinzhengjie.org.cn:/etc/
profile                                                                                                                                             100% 2127     1.2MB/s   00:00    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# scp /etc/profile node102.yinzhengjie.org.cn:/etc/
[root@node101.yinzhengjie.org.cn ~]# scp /etc/profile node103.yinzhengjie.org.cn:/etc/
profile                                                                                                                                             100% 2127     1.4MB/s   00:00    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# scp /etc/profile node103.yinzhengjie.org.cn:/etc/
[root@node101.yinzhengjie.org.cn ~]# scp -r /yinzhengjie/softwares/zookeeper-3.4.14/ node102.yinzhengjie.org.cn:/yinzhengjie/softwares/
........
log.42                                                                                                                                              100%  184   128.3KB/s   00:00    
log.63b                                                                                                                                             100%   48KB  22.7MB/s   00:00    
snapshot.0                                                                                                                                          100%  296   277.6KB/s   00:00    
snapshot.272                                                                                                                                        100%   55KB  26.5MB/s   00:00    
snapshot.273                                                                                                                                        100%   55KB  24.3MB/s   00:00    
snapshot.639                                                                                                                                        100%  140KB  27.2MB/s   00:00    
snapshot.83f                                                                                                                                        100% 4824     3.5MB/s   00:00    
minikdc-krb5.conf                                                                                                                                   100% 1103     1.3MB/s   00:00    
minikdc.ldiff                                                                                                                                       100% 1630     2.2MB/s   00:00    
log.100000001                                                                                                                                       100% 2401KB  50.2MB/s   00:00    
log.100001bf0                                                                                                                                       100% 1001KB  59.6MB/s   00:00    
snapshot.100000000                                                                                                                                  100%   73    17.1KB/s   00:00    
snapshot.100001bec                                                                                                                                  100% 2507KB  61.6MB/s   00:00    
check_compatibility.py                                                                                                                              100% 7212     4.7MB/s   00:00    
checkstyle-noframes-sorted.xsl                                                                                                                      100% 5489     6.5MB/s   00:00    
checkstyle.xml                                                                                                                                      100% 7489     7.3MB/s   00:00    
findbugsExcludeFile.xml                                                                                                                             100% 5027     6.6MB/s   00:00    
log4j.properties                                                                                                                                    100% 2712     1.9MB/s   00:00    
test-patch.properties                                                                                                                               100%  855   930.7KB/s   00:00    
test-github-pr.sh                                                                                                                                   100%   24KB   9.7MB/s   00:00    
test-patch.sh                                                                                                                                       100%   24KB  19.4MB/s   00:00    
pom.xml                                                                                                                                             100%   10KB   7.6MB/s   00:00    
LICENSE.txt                                                                                                                                         100%   12KB   5.9MB/s   00:00    
NOTICE.txt                                                                                                                                          100% 3132     1.2MB/s   00:00    
README.md                                                                                                                                           100% 1765     1.4MB/s   00:00    
README_packaging.txt                                                                                                                                100% 1770     2.5MB/s   00:00    
build.xml                                                                                                                                           100%   95KB  39.5MB/s   00:00    
ivy.xml                                                                                                                                             100%   10KB   8.2MB/s   00:00    
ivysettings.xml                                                                                                                                     100% 1709     1.3MB/s   00:00    
pom.xml                                                                                                                                             100%   31KB   8.9MB/s   00:00    
zookeeper-3.4.14.jar                                                                                                                                100% 1480KB  41.5MB/s   00:00    
zookeeper-3.4.14.jar.md5                                                                                                                            100%   33    25.6KB/s   00:00    
zookeeper-3.4.14.jar.sha1                                                                                                                           100%   41    60.7KB/s   00:00    
zookeeper-3.4.14.jar.asc                                                                                                                            100%  836     1.2MB/s   00:00    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# scp -r /yinzhengjie/softwares/zookeeper-3.4.14/ node102.yinzhengjie.org.cn:/yinzhengjie/softwares/
[root@node101.yinzhengjie.org.cn ~]# scp -r /yinzhengjie/softwares/zookeeper-3.4.14/ node103.yinzhengjie.org.cn:/yinzhengjie/softwares/

......
snapshot.273                                                                                                                                        100%   55KB  14.8MB/s   00:00    
snapshot.639                                                                                                                                        100%  140KB  21.7MB/s   00:00    
snapshot.83f                                                                                                                                        100% 4824     4.4MB/s   00:00    
minikdc-krb5.conf                                                                                                                                   100% 1103     1.0MB/s   00:00    
minikdc.ldiff                                                                                                                                       100% 1630     1.4MB/s   00:00    
log.100000001                                                                                                                                       100% 2401KB  53.2MB/s   00:00    
log.100001bf0                                                                                                                                       100% 1001KB  46.5MB/s   00:00    
snapshot.100000000                                                                                                                                  100%   73    40.2KB/s   00:00    
snapshot.100001bec                                                                                                                                  100% 2507KB  57.4MB/s   00:00    
check_compatibility.py                                                                                                                              100% 7212     1.4MB/s   00:00    
checkstyle-noframes-sorted.xsl                                                                                                                      100% 5489     4.4MB/s   00:00    
checkstyle.xml                                                                                                                                      100% 7489     5.0MB/s   00:00    
findbugsExcludeFile.xml                                                                                                                             100% 5027     4.2MB/s   00:00    
log4j.properties                                                                                                                                    100% 2712     2.5MB/s   00:00    
test-patch.properties                                                                                                                               100%  855   376.7KB/s   00:00    
test-github-pr.sh                                                                                                                                   100%   24KB   6.3MB/s   00:00    
test-patch.sh                                                                                                                                       100%   24KB  13.5MB/s   00:00    
pom.xml                                                                                                                                             100%   10KB   6.5MB/s   00:00    
LICENSE.txt                                                                                                                                         100%   12KB   4.9MB/s   00:00    
NOTICE.txt                                                                                                                                          100% 3132     2.8MB/s   00:00    
README.md                                                                                                                                           100% 1765     1.9MB/s   00:00    
README_packaging.txt                                                                                                                                100% 1770     1.6MB/s   00:00    
build.xml                                                                                                                                           100%   95KB  27.3MB/s   00:00    
ivy.xml                                                                                                                                             100%   10KB  10.1MB/s   00:00    
ivysettings.xml                                                                                                                                     100% 1709     1.3MB/s   00:00    
pom.xml                                                                                                                                             100%   31KB  13.6MB/s   00:00    
zookeeper-3.4.14.jar                                                                                                                                100% 1480KB  42.5MB/s   00:00    
zookeeper-3.4.14.jar.md5                                                                                                                            100%   33    38.8KB/s   00:00    
zookeeper-3.4.14.jar.sha1                                                                                                                           100%   41    29.3KB/s   00:00    
zookeeper-3.4.14.jar.asc                                                                                                                            100%  836   690.2KB/s   00:00    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# scp -r /yinzhengjie/softwares/zookeeper-3.4.14/ node103.yinzhengjie.org.cn:/yinzhengjie/softwares/

7>.启动zookeeper集群

[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'grep SELINUX= /etc/selinux/config |  grep -v ^#'
node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
SELINUX=enforcing

node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
SELINUX=enforcing

node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
SELINUX=enforcing

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'grep SELINUX= /etc/selinux/config | grep -v ^#'
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config'
 [WARNING]: Consider using template or lineinfile module rather than running sed

node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>


[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config'
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'grep SELINUX= /etc/selinux/config |  grep -v ^#'                 
node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
SELINUX=disabled

node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
SELINUX=disabled

node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
SELINUX=disabled

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'grep SELINUX= /etc/selinux/config | grep -v ^#'
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'getenforce'                                                      
node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Enforcing

node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Enforcing

node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Enforcing

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'getenforce'
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'setenforce 0' 
node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>


[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'setenforce 0'
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'getenforce'
node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Permissive

node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Permissive

node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Permissive

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'getenforce'                            #以上操作是禁用selinux
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'systemctl status firewalld'
node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-04-23 11:22:42 CST; 2 days ago
     Docs: man:firewalld(1)
 Main PID: 3916 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─3916 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Apr 23 11:22:41 node103.yinzhengjie.org.cn systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 23 11:22:42 node103.yinzhengjie.org.cn systemd[1]: Started firewalld - dynamic firewall daemon.

node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-04-23 11:22:27 CST; 2 days ago
     Docs: man:firewalld(1)
 Main PID: 3929 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─3929 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Apr 23 11:22:26 node102.yinzhengjie.org.cn systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 23 11:22:27 node102.yinzhengjie.org.cn systemd[1]: Started firewalld - dynamic firewall daemon.

node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-04-23 11:22:10 CST; 2 days ago
     Docs: man:firewalld(1)
 Main PID: 4068 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─4068 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Apr 23 11:22:09 node101.yinzhengjie.org.cn systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 23 11:22:10 node101.yinzhengjie.org.cn systemd[1]: Started firewalld - dynamic firewall daemon.

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'systemctl status firewalld'
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'systemctl stop firewalld'  
node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>


node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>


[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'systemctl stop firewalld'
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'systemctl disable firewalld'
node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.

node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'systemctl disable firewalld'  
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'systemctl status firewalld'   
node103.yinzhengjie.org.cn | 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)

Apr 23 11:22:41 node103.yinzhengjie.org.cn systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 23 11:22:42 node103.yinzhengjie.org.cn systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 25 14:50:48 node103.yinzhengjie.org.cn systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 25 14:50:49 node103.yinzhengjie.org.cn systemd[1]: Stopped firewalld - dynamic firewall daemon.non-zero return code

node102.yinzhengjie.org.cn | 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)

Apr 23 11:22:26 node102.yinzhengjie.org.cn systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 23 11:22:27 node102.yinzhengjie.org.cn systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 25 14:50:48 node102.yinzhengjie.org.cn systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 25 14:50:49 node102.yinzhengjie.org.cn systemd[1]: Stopped firewalld - dynamic firewall daemon.non-zero return code

node101.yinzhengjie.org.cn | 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)

Apr 23 11:22:09 node101.yinzhengjie.org.cn systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 23 11:22:10 node101.yinzhengjie.org.cn systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 25 14:50:48 node101.yinzhengjie.org.cn systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 25 14:50:49 node101.yinzhengjie.org.cn systemd[1]: Stopped firewalld - dynamic firewall daemon.non-zero return code

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'systemctl status firewalld'                    #以上操作是禁用firewalld
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'jps'
node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Jps

node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Jps

node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
Jps

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'jps'
[root@node101.yinzhengjie.org.cn ~]# xzk.sh start
启动服务
========== node101.yinzhengjie.org.cn zkServer.sh start ================
ZooKeeper JMX enabled by default
Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
========== node102.yinzhengjie.org.cn zkServer.sh start ================
ZooKeeper JMX enabled by default
Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
========== node103.yinzhengjie.org.cn zkServer.sh start ================
ZooKeeper JMX enabled by default
Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# xzk.sh start
[root@node101.yinzhengjie.org.cn ~]# xzk.sh status
查看状态
========== node101.yinzhengjie.org.cn zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower
========== node102.yinzhengjie.org.cn zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: leader
========== node103.yinzhengjie.org.cn zkServer.sh status ================
ZooKeeper JMX enabled by default
Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# xzk.sh status
[root@node101.yinzhengjie.org.cn ~]#  ansible all -m shell -a 'jps'
node103.yinzhengjie.org.cn | SUCCESS | rc=0 >>
QuorumPeerMain
Jps

node102.yinzhengjie.org.cn | SUCCESS | rc=0 >>
QuorumPeerMain
Jps

node101.yinzhengjie.org.cn | SUCCESS | rc=0 >>
QuorumPeerMain
Jps

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ansible all -m shell -a 'jps'
[root@node101.yinzhengjie.org.cn ~]# zkCli.sh 
Connecting to localhost:2181
2019-04-12 09:23:04,270 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
2019-04-12 09:23:04,272 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=node101.yinzhengjie.org.cn
2019-04-12 09:23:04,273 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_201
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/yinzhengjie/softwares/jdk1.8.0_201/jre
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/target/classes:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../build/classes:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../build/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf:
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2019-04-12 09:23:04,275 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-957.el7.x86_64
2019-04-12 09:23:04,276 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2019-04-12 09:23:04,276 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2019-04-12 09:23:04,276 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/root
2019-04-12 09:23:04,277 [myid:] - INFO  [main:ZooKeeper@442] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5ce65a89
Welcome to ZooKeeper!
2019-04-12 09:23:04,303 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1025] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2019-04-12 09:23:04,365 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@879] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2019-04-12 09:23:04,395 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x6500007f14d00000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1] ls /zookeeper
[quota]
[zk: localhost:2181(CONNECTED) 2] ls /zookeeper/quota
[]
[zk: localhost:2181(CONNECTED) 3] quit
Quitting...
2019-04-12 09:23:13,101 [myid:] - INFO  [main:ZooKeeper@693] - Session: 0x6500007f14d00000 closed
2019-04-12 09:23:13,102 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@522] - EventThread shut down for session: 0x6500007f14d00000
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# zkCli.sh                                              #测试zookeeper是否可用

 

三.zookeeper客户端四字符指令

  ZooKeeper 支持某些特定的四字命令字母与其的交互。它们大多是查询命令,用来获取 ZooKeeper 服务的当前状态及相关信息。用户在客户端可以通过 telnet 或 nc 向 ZooKeeper 提交相应的命令,接下来我们一起体验一下吧。

[root@node101.yinzhengjie.org.cn ~]#  echo conf |  nc node101.yinzhengjie.org.cn 2181            #查看配置信息
clientPort=2181
dataDir=/home/yinzhengjie/zookeeper/version-2
dataLogDir=/home/yinzhengjie/zookeeper/version-2
tickTime=2000
maxClientCnxns=60
minSessionTimeout=4000
maxSessionTimeout=40000
serverId=101
initLimit=5
syncLimit=2
electionAlg=3
electionPort=3888
quorumPort=2888
peerType=0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo conf | nc node101.yinzhengjie.org.cn 2181              #查看配置信息,输出相关服务配置的详细信息
[root@node101.yinzhengjie.org.cn ~]# echo ruok |  nc node101.yinzhengjie.org.cn 2181           #注意,他会恢复一个字符串为“imok”,表示其为存活状态
imok[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo ruok |  nc node102.yinzhengjie.org.cn 2181           #注意,如果恢复的不是"imok",那就说明该节点挂掉啦!注意管擦好输出结果哟!
Ncat: Connection refused.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo ruok |  nc node103.yinzhengjie.org.cn 2181 
imok[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo ruok | nc node102.yinzhengjie.org.cn 2181               #注意,如果恢复的不是"imok",那就说明该节点挂掉啦!注意观察输出结果哟!
[root@node101.yinzhengjie.org.cn ~]# echo envi | nc node103.yinzhengjie.org.cn 2181              #查看指定zookeeper主机环境变量
Environment:
zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
host.name=node103.yinzhengjie.org.cn
java.version=1.8.0_201
java.vendor=Oracle Corporation
java.home=/yinzhengjie/softwares/jdk1.8.0_201/jre
java.class.path=/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/target/classes:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../build/classes:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../build/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf:
java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.io.tmpdir=/tmp
java.compiler=<NA>
os.name=Linux
os.arch=amd64
os.version=3.10.0-957.el7.x86_64
user.name=root
user.home=/root
user.dir=/root
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo envi | nc node103.yinzhengjie.org.cn 2181              #查看指定zookeeper主机环境变量,输出关于服务环境的详细信息
[root@node101.yinzhengjie.org.cn ~]# echo cons | nc node103.yinzhengjie.org.cn 2181 
 /172.30.1.102:57816[1](queued=0,recved=20,sent=20,sid=0x67000b2416210000,lop=PING,est=1556176886312,to=30000,lcxid=0x1,lzxid=0xffffffffffffffff,lresp=187317065,llat=0,minlat=0,avglat=0,maxlat=5)
 /172.30.1.101:57124[0](queued=0,recved=1,sent=0)
 /127.0.0.1:50638[1](queued=0,recved=17,sent=17,sid=0x67000b2416210001,lop=GETC,est=1556176940249,to=30000,lcxid=0x4,lzxid=0x400000005,lresp=187315052,llat=1,minlat=0,avglat=0,maxlat=4)

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo cons | nc node103.yinzhengjie.org.cn 2181              #查看终端链接信息
[root@node101.yinzhengjie.org.cn ~]# echo dump | nc node103.yinzhengjie.org.cn 2181                 #查看未处理会话的节点
SessionTracker dump:
org.apache.zookeeper.server.quorum.LearnerSessionTracker@515b070f
ephemeral nodes dump:
Sessions with Ephemerals (0):
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo dump | nc node103.yinzhengjie.org.cn 2181               #查看未处理会话的节点
[root@node101.yinzhengjie.org.cn ~]# echo stat | nc node103.yinzhengjie.org.cn 2181                 #查看统计信息
Zookeeper version: 3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
Clients:
 /172.30.1.102:57816[1](queued=0,recved=36,sent=36)
 /127.0.0.1:50638[1](queued=0,recved=33,sent=33)
 /172.30.1.101:57128[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/0/5
Received: 84
Sent: 83
Connections: 3
Outstanding: 0
Zxid: 0x400000005
Mode: follower
Node count: 4
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo stat | nc node103.yinzhengjie.org.cn 2181               #查看统计信息,一般用来查看哪个节点被选择作为follower或者leader
[root@node101.yinzhengjie.org.cn ~]# echo wchs | nc node103.yinzhengjie.org.cn 2181                 #查看链接的watch信息
0 connections watching 0 paths
Total watches:0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo wchs | nc node103.yinzhengjie.org.cn 2181                #查看服务器的watch的详细信息
[root@node101.yinzhengjie.org.cn ~]# echo wchc | nc node103.yinzhengjie.org.cn 2181                #通过 session 列出服务器 watch 的详细信息,它的输出是一个与 watch 相关的会话的列表。
wchc is not executed because it is not in the whitelist.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo wchc | nc node103.yinzhengjie.org.cn 2181               #通过 session 列出服务器 watch 的详细信息,它的输出是一个与 watch 相关的会话的列表。(需要进一步调研)
[root@node101.yinzhengjie.org.cn ~]# echo wchp | nc node103.yinzhengjie.org.cn 2181                #通过路径列出服务器 watch 的详细信息。它输出一个与 session 相关的路径。
wchp is not executed because it is not in the whitelist.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo wchp | nc node103.yinzhengjie.org.cn 2181               #通过路径列出服务器 watch 的详细信息。它输出一个与 session 相关的路径。(需要进一步调研)
[root@node101.yinzhengjie.org.cn ~]# echo reqs | nc node103.yinzhengjie.org.cn 2181                 #查看未经处理的请求。
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo reqs | nc node103.yinzhengjie.org.cn 2181               #查看未经处理的请求。 
[root@node101.yinzhengjie.org.cn ~]# echo crst | nc node101.yinzhengjie.org.cn 2181                   #重置所有的客户端连接
Connection stats reset.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo crst | nc node101.yinzhengjie.org.cn 2181               #重置所有的客户端连接
[root@node101.yinzhengjie.org.cn ~]# echo dump | nc node101.yinzhengjie.org.cn 2181                 #打印集群的所有会话信息,包括ID,以及临时节点等信息。用在Leader节点上才有效果。
SessionTracker dump:
Session Sets (7):
0 expire at Sat Jan 03 12:27:32 CST 1970:
0 expire at Sat Jan 03 12:27:40 CST 1970:
0 expire at Sat Jan 03 12:27:42 CST 1970:
0 expire at Sat Jan 03 12:27:50 CST 1970:
0 expire at Sat Jan 03 12:27:52 CST 1970:
1 expire at Sat Jan 03 12:28:00 CST 1970:
        0x67000b2416210001
2 expire at Sat Jan 03 12:28:02 CST 1970:
        0x65000b248f060000
        0x67000b2416210000
ephemeral nodes dump:
Sessions with Ephemerals (0):
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo dump | nc node101.yinzhengjie.org.cn 2181                #打印集群的所有会话信息,包括ID,以及临时节点等信息。用在Leader节点上才有效果。
[root@node101.yinzhengjie.org.cn ~]# echo srst | nc node101.yinzhengjie.org.cn 2181                  #重置服务器统计信息
Server stats reset.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo srst | nc node101.yinzhengjie.org.cn 2181               #重置服务器统计信息
[root@node101.yinzhengjie.org.cn ~]# echo srvr | nc node101.yinzhengjie.org.cn 2181                #和stat输出信息一样,只不过少了客户端连接信息。
Zookeeper version: 3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
Latency min/avg/max: 0/0/1
Received: 7
Sent: 7
Connections: 2
Outstanding: 0
Zxid: 0x400000006
Mode: leader
Node count: 4
Proposal sizes last/min/max: -1/-1/-1
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo srvr | nc node101.yinzhengjie.org.cn 2181               #和stat输出信息一样,只不过少了客户端连接信息。
[root@node101.yinzhengjie.org.cn ~]# echo mntr | nc node101.yinzhengjie.org.cn 2181                #输出比stat更为详细的服务器统计信息
zk_version      3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
zk_avg_latency  0
zk_max_latency  1
zk_min_latency  0
zk_packets_received     13
zk_packets_sent 13
zk_num_alive_connections        2
zk_outstanding_requests 0
zk_server_state leader
zk_znode_count  4
zk_watch_count  0
zk_ephemerals_count     0
zk_approximate_data_size        27
zk_open_file_descriptor_count   34
zk_max_file_descriptor_count    1048576
zk_fsync_threshold_exceed_count 0
zk_followers    2
zk_synced_followers     2
zk_pending_syncs        0
zk_last_proposal_size   -1
zk_max_proposal_size    -1
zk_min_proposal_size    -1
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# echo mntr | nc node101.yinzhengjie.org.cn 2181               #输出比stat更为详细的服务器统计信息 

 

 

参考链接1:https://www.cnblogs.com/yinzhengjie/p/10739218.html

参加链接2:https://www.cnblogs.com/yinzhengjie/articles/10698719.html

参考链接3:https://www.jianshu.com/p/4f11d7bfc9ce

参考链接4:https://blog.youkuaiyun.com/u013673976/article/details/47321067

参考链接5:https://blog.youkuaiyun.com/paincupid/article/details/78058087#Zookeeper_1782

 

转载于:https://www.cnblogs.com/yinzhengjie/p/10747747.html

Java 允许您玩在线游戏,与世界各地的人聊天,计算您的按揭利息,并以 3D 形式查看图像。这些以 Java 编程语言编写的应用程序和可从浏览中访问的应用程序称为小程序。公司还将 Java 小程序用于内部网应用程序和其他电子商务的解决方案。所有主要行业的公司都在使用 Java。无论是部署在手机、嵌入式设备、游戏机、笔记本电脑还是数据中心,Java 都提供了当今网络应用所需要的丰富的用户界面、性能、多功能性、可移植性和安全性。Java 平台标准版软件是快速开发和部署安全、便携式应用程序的首选平台,可跨大多数操作系统的服务器和桌面系统。 Java 平台标准版(Java SE)可让您在台式机和服务器以及当今苛刻的嵌入式环境中开发和部署 Java 应用程序。Java 提供了当今应用程序所需的丰富的用户界面、性能、通用性、可移植性和安全性。 Java SE Runtime Environment(运行时环境)包含了运行以 Java 编程语言编写的程序所必需的 Java 虚拟机、运行时类库和 Java 应用程序启动器。 Java 平台的安全性 一个由角色提供的安全信息的描述。适用于开发人员,系统管理员,家庭用户和安全专业人士。 主要特点: - 在一个平台上编写软件,并可在几乎任何其它平台上运行 - 创建的程序可在 Web 浏览器和 Web 服务中运行 - 可开发用于在线论坛、商店、投票、HTML 表单处理等服务器端应用程序 - 结合基于 Java 技术的应用程序或服务来创建高度可定制的应用程序或服务 - 为手机、远程处理器、低成本消费产品和几乎任何具有数字内核的设备编写功能强大且高效的应用程序 Java SE 8 现在可用 Java 平台标准版 8(Java SE 8)是一个主要的功能版本。它包含了很多功能领域的新功能和增强功能。Java SE 8 通过减少样板代码,改进了集合和注释,简单的并行编程模型和更有效地利用现代多核处理器,提高了开发人员的工作效率和显着的增强了应用程序的性能。 Java SE 8u172 版本更新:2018年4月17日
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值