您好,登錄后才能下訂單哦!
第一步 //用執行初始化模板 initialization.sh https://blog.51cto.com/12445535/2362407
[root@emm-kafka01-10--174 opt]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@emm-kafka01-10--174 opt]# free -m
total used free shared buff/cache available
Mem: 3790 109 3530 8 150 3474
Swap: 3967 0 3967
[root@emm-kafka01-10--174 opt]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 46G 2.2G 44G 5% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 161M 337M 33% /boot
tmpfs tmpfs 380M 0 380M 0% /run/user/0
####################################################
cpu物理個數 physical_id: 4
每個cpu中core的個數(即核數) cpu cores : 1
邏輯cpu的個數 processor: 4
####################################################
第二步
安裝jdk 現在都要是1.8版本以上
先檢查機器是否自帶jdk
[root@emm-kafka03-10--176 scripts]# java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
刪除已有的jdk
https://blog.csdn.net/cbcgkx123/article/details/80182584
[root@emm-kafka01-10--174 usr]# rm -rf /usr/java/
安裝自己的jdk
[root@emm-kafka01-10--174 ins]# ll
total 162156
-rwxr-xr-x 1 root root 166044032 Mar 13 15:58 jdk-8u102-linux-x64.rpm
[root@emm-kafka01-10--174 ins]# rpm -ivh jdk-8u102-linux-x64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:jdk1.8.0_102-2000:1.8.0_102-fcs ################################# [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
[root@emm-kafka01-10--174 ins]# java -version
-bash: /usr/java/jdk/bin/java: No such file or directory
[root@emm-kafka01-10--174 java]# vim /etc/profile
#export JAVA_HOME=/usr/java/jdk
#export CLASSPATH=$JAVA_HOME/jre/lib:$JAVA_HOME/lib
#export PATH=$PATH:$JAVA_HOME/bin
[root@emm-kafka01-10--174 java]# source /etc/profile
[root@emm-kafka01-10--174 java]# java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
其他2臺都是這樣執行
第三步 設置/etc/hosts
[root@emm-kafka01-10--174 conf]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.2.10.174 emm-kafka01-10--174
10.2.10.175 emm-kafka02-10--175
10.2.10.176 emm-kafka03-10--176
[root@emm-kafka01-10--174 conf]# scp /etc/hosts root@10.2.10.175:/etc/hosts
hosts 100% 254 139.6KB/s 00:00
[root@emm-kafka01-10--174 conf]# scp /etc/hosts root@10.2.10.176:/etc/hosts
hosts
第四步安裝zookeeper
先下載zookeeper的linux安裝包 //安裝zookeeper必須要先安裝jdk,現在都是1.8以上的版本
//注意版本的控制,現在線上版本 zookeeper3.4.8無明顯bug,生產上要控制版本
[root@emm-kafka01-10--174 ins]# ll
total 233044
-rwxr-xr-x 1 root root 166044032 Mar 13 15:58 jdk-8u102-linux-x64.rpm
-rw-r--r-- 1 root root 50326212 Mar 13 16:14 kafka_2.12-1.1.0.tgz
-rw-r--r-- 1 root root 22261552 Mar 13 16:14 zookeeper-3.4.8.tar.gz
[root@emm-kafka01-10--174 ins]# scp kafka_2.12-1.1.0.tgz zookeeper-3.4.8.tar.gz root@10.2.10.175:/opt/ins/
kafka_2.12-1.1.0.tgz 100% 48MB 48.0MB/s 00:01
zookeeper-3.4.8.tar.gz 100% 21MB 55.0MB/s 00:00
[root@emm-kafka01-10--174 ins]# scp kafka_2.12-1.1.0.tgz zookeeper-3.4.8.tar.gz root@10.2.10.176:/opt/ins/
kafka_2.12-1.1.0.tgz 100% 48MB 53.4MB/s 00:00
zookeeper-3.4.8.tar.gz 100% 21MB 56.4MB/s 00:00
[root@emm-kafka01-10--174 ins]# tar -zxvf zookeeper-3.4.8.tar.gz -C /usr/local/
[root@emm-kafka01-10--174 ins]# chown -R root:root zookeeper-3.4.8/
[root@emm-kafka01-10--174 local]# ln -s zookeeper-3.4.8/ zookeeper
[root@emm-kafka01-10--174 zookeeper]# pwd
/usr/local/zookeeper
[root@emm-kafka01-10--174 zookeeper]# cd conf/
[root@emm-kafka01-10--174 conf]# ll
total 12
-rw-rw-r-- 1 root root 535 Feb 6 2016 configuration.xsl
-rw-rw-r-- 1 root root 2161 Feb 6 2016 log4j.properties
-rw-rw-r-- 1 root root 922 Feb 6 2016 zoo_sample.cfg
[root@emm-kafka01-10--174 conf]# mv zoo_sample.cfg zoo.cfg
[root@emm-kafka01-10--174 conf]# pwd
/usr/local/zookeeper/conf
[root@emm-kafka01-10--174 conf]# cat zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=10.2.10.174:2888:3888
server.2=10.2.10.175:2888:3888
server.3=10.2.10.176:2888:3888
[root@emm-kafka01-10--174 conf]# mkdir -p /usr/local/zookeeper/data/
**提示:
tickTime:這個時間是作為 Zookeeper 服務器之間或客戶端與服務器之間維持心跳的時間間隔,也就是每個 tickTime 時間就會發送一個心跳。
dataDir:顧名思義就是 Zookeeper 保存數據的目錄,默認情況下,Zookeeper 將寫數據的日志文件也保存在這個目錄里。
clientPort:這個端口就是客戶端連接 Zookeeper 服務器的端口(2181),Zookeeper 會監聽這個端口,接受客戶端的訪問請求。
注意點:
這里有一個坑,就是
server.1=10.2.10.174:2888:3888 //這里要寫IP 不要寫成server.1=emm-kafka01-10--174:2888:3888
為什么呢?
寫主機名,zk能起來,kafka也能起來,但是kafka他去解析ZK的時候,他不通過etc/hosts 以后會出問題
這里面,我們就下IP,這里注意下
(其中2181代表:客戶端與服務器連接所用的端口)
(其中2888代表:leader與follower之間的通信用的端口)
(其中3888代表:follower之間選舉投票用的端口)**
要在data這里面創建一個文件,里面寫一個這臺服務器在zookeeper里面的編號
echo 1 > myid(必須叫myid不能用別的名字)
[root@emm-kafka01-10--174 data]# pwd
/usr/local/zookeeper/data
[root@emm-kafka01-10--174 data]# echo 1 > myid
[root@emm-kafka01-10--174 data]# ll
total 4
-rw-r--r-- 1 root root 4 Mar 13 17:23 myid
[root@emm-kafka01-10--174 data]# cat myid
1
其他2個節點同上,只不過,需要在/usr/local/zookeeper/data/ 目錄下 的myid不一樣
[root@emm-kafka01-10--174 conf]# pwd
/usr/local/zookeeper/conf
[root@emm-kafka01-10--174 conf]# scp zoo.cfg root@10.2.10.175:/usr/local/zookeeper/conf/
zoo.cfg 100% 1026 531.1KB/s 00:00
[root@emm-kafka01-10--174 conf]# scp zoo.cfg root@10.2.10.176:/usr/local/zookeeper/conf/
zoo.cfg 100% 1026 531.1KB/s 00:00
[root@emm-kafka02-10--175 data]# pwd
/usr/local/zookeeper/data
[root@emm-kafka02-10--175 data]# echo 2 > myid
[root@emm-kafka03-10--176 data]# echo 3 > myid
以上就是安裝配置好了zookeeper
修改zookeeper的啟動內存大小
進入zk的bin目錄下
vim /app/zpy/zookeeper/bin/zkServer.sh (修改zk的啟動腳本)
添加:JVMPARAM="-Xms1G -Xmx4G -Xmn2G" //這個是8G 物理內存的標準
參數解釋說明:
java?-Xmx3550m?-Xms3550m?-Xmn2g?-Xss128k
-Xmx3550m:設置JVM最大可用內存為3550M。
-Xms3550m:設置JVM初始內存為3550m。此值可以設置與-Xmx相同,以避免每次垃圾回收完成后JVM重新分配內存。
-Xmn2g:設置年輕代大小為2G。整個JVM內存大小=年輕代大小?+?年老代大小?+?持久代大小。持久代一般固定大小為64m,所以增大年輕代后,將會減小年老代大小。此值對系統性能影響較大,Sun官方推薦配置為整個堆的3/8。
-Xss128k:設置每個線程的堆棧大小。JDK5.0以后每個線程堆棧大小為1M,以前每個線程堆棧大小為256K。更具應用的線程所需內存大小進行調整。在相同物理內存下,減小這個值能生成更多的線程。但是操作系統對一個進程內的線程數還是有限制的,不能無限生成,經驗值在3000~5000左右。
我們是4G的物理內存
JVMPARAM="-Xms512M -Xmx2G -Xmn1G"
設置成如下:
[root@emm-kafka01-10--174 bin]# pwd
/usr/local/zookeeper/bin
[root@emm-kafka01-10--174 bin]# vim zkServer.sh
ZOOBIN="${BASH_SOURCE-$0}"
ZOOBIN="$(dirname "${ZOOBIN}")"
ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
JVMPARAM="-Xms512M -Xmx2G -Xmn1G" //添加這個
改動的第二處為:
nohup "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \
-cp "$CLASSPATH" $JVMFLAGS $JVMPARAM $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null &
[root@emm-kafka01-10--174 bin]# ll
total 36
-rwxr-xr-x 1 root root 232 Feb 6 2016 README.txt
-rwxr-xr-x 1 root root 1937 Feb 6 2016 zkCleanup.sh
-rwxr-xr-x 1 root root 1056 Feb 6 2016 zkCli.cmd
-rwxr-xr-x 1 root root 1534 Feb 6 2016 zkCli.sh
-rwxr-xr-x 1 root root 1628 Feb 6 2016 zkEnv.cmd
-rwxr-xr-x 1 root root 2696 Feb 6 2016 zkEnv.sh
-rwxr-xr-x 1 root root 1089 Feb 6 2016 zkServer.cmd
-rwxr-xr-x 1 root root 6817 Mar 13 18:36 zkServer.sh
-rw-r--r-- 1 root root 10195 Mar 13 18:36 zookeeper.out
[root@emm-kafka01-10--174 bin]# scp zkServer.sh root@10.2.10.175:/usr/local/zookeeper/bin/
zkServer.sh 100% 6807 2.9MB/s 00:00
[root@emm-kafka01-10--174 bin]# scp zkServer.sh root@10.2.10.176:/usr/local/zookeeper/bin/
zkServer.sh 100% 6807 2.6MB/s 00:00
同時啟動3臺zookeeper
[root@emm-kafka03-10--176 data]# cd /usr/local/zookeeper/bin
[root@emm-kafka03-10--176 bin]# ll
total 36
-rwxr-xr-x 1 root root 232 Feb 6 2016 README.txt
-rwxr-xr-x 1 root root 1937 Feb 6 2016 zkCleanup.sh
-rwxr-xr-x 1 root root 1056 Feb 6 2016 zkCli.cmd
-rwxr-xr-x 1 root root 1534 Feb 6 2016 zkCli.sh
-rwxr-xr-x 1 root root 1628 Feb 6 2016 zkEnv.cmd
-rwxr-xr-x 1 root root 2696 Feb 6 2016 zkEnv.sh
-rwxr-xr-x 1 root root 1089 Feb 6 2016 zkServer.cmd
-rwxr-xr-x 1 root root 6817 Mar 13 18:36 zkServer.sh
-rw-r--r-- 1 root root 10195 Mar 13 18:36 zookeeper.out
[root@emm-kafka01-10--174 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@emm-kafka01-10--174 bin]# jps
7849 Jps
[root@emm-kafka01-10--174 bin]# cat zookeeper.out //報錯信息
nohup: failed to run command ‘/usr/java/jdk/bin/java’: No such file or directory
[root@emm-kafka01-10--174 local]# cd /usr/java/
[root@emm-kafka01-10--174 java]# ll
total 4
lrwxrwxrwx 1 root root 16 Mar 13 15:58 default -> /usr/java/latest
drwxr-xr-x 9 root root 4096 Mar 13 15:58 jdk1.8.0_102
lrwxrwxrwx 1 root root 22 Mar 13 15:58 latest -> /usr/java/jdk1.8.0_102
[root@emm-kafka01-10--174 java]# ln -s jdk1.8.0_102/ jdk
[root@emm-kafka01-10--174 java]# ll
total 4
lrwxrwxrwx 1 root root 16 Mar 13 15:58 default -> /usr/java/latest
lrwxrwxrwx 1 root root 13 Mar 13 17:48 jdk -> jdk1.8.0_102/
drwxr-xr-x 9 root root 4096 Mar 13 15:58 jdk1.8.0_102
lrwxrwxrwx 1 root root 22 Mar 13 15:58 latest -> /usr/java/jdk1.8.0_102
再起起來之后,出現報錯,原因是174這樣設置是不行的myid 所以我們要改成 1 2 3 這樣的myid
[root@emm-kafka01-10--174 bin]# vim zookeeper.out
2019-03-13 17:49:41,175 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 10.2.10.176 to
address: /10.2.10.176
2019-03-13 17:49:41,176 [myid:] - INFO [main:QuorumPeer$QuorumServer@149] - Resolved hostname: 10.2.10.175 to
address: /10.2.10.175
2019-03-13 17:49:41,176 [myid:] - INFO [main:QuorumPeerConfig@331] - Defaulting to majority quorums
2019-03-13 17:49:41,179 [myid:174] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2019-03-13 17:49:41,180 [myid:174] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2019-03-13 17:49:41,180 [myid:174] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2019-03-13 17:49:41,193 [myid:174] - INFO [main:QuorumPeerMain@127] - Starting quorum peer
2019-03-13 17:49:41,206 [myid:174] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:218
1
2019-03-13 17:49:41,215 [myid:174] - INFO [main:QuorumPeer@1019] - tickTime set to 2000
2019-03-13 17:49:41,215 [myid:174] - INFO [main:QuorumPeer@1039] - minSessionTimeout set to -1
2019-03-13 17:49:41,215 [myid:174] - INFO [main:QuorumPeer@1050] - maxSessionTimeout set to -1
2019-03-13 17:49:41,215 [myid:174] - INFO [main:QuorumPeer@1065] - initLimit set to 10
2019-03-13 17:49:41,224 [myid:174] - **ERROR** [main:QuorumPeer@231] - Setting LearnerType to PARTICIPANT but 174 n
ot in QuorumPeers.
2019-03-13 17:49:41,228 [myid:174] - INFO [main:QuorumPeer@533] - currentEpoch not found! Creating with a reas
onable default of 0. This should only happen when you are upgrading your installation
2019-03-13 17:49:41,234 [myid:174] - INFO [main:QuorumPeer@548] - acceptedEpoch not found! Creating with a rea
sonable default of 0. This should only happen when you are upgrading your installation
**2019-03-13 17:49:41,237 [myid:174] - ERROR [main:QuorumPeerMain@89] - Unexpected exception, exiting abnormally**
java.lang.RuntimeException: My id 174 not in the peer list
at org.apache.zookeeper.server.quorum.QuorumPeer.startLeaderElection(QuorumPeer.java:583)
at org.apache.zookeeper.server.quorum.QuorumPeer.start(QuorumPeer.java:502)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:153)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:111)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
[root@emm-kafka01-10--174 bin]# jps //啟動成功
8292 Jps
8159 QuorumPeerMain
[root@emm-kafka01-10--174 bin]# ./zkServer.sh stop
驗證
[root@emm-kafka01-10--174 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@emm-kafka02-10--175 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@emm-kafka03-10--176 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@emm-kafka01-10--174 bin]# ps -ef |grep zookeeper|grep 512
root 8892 1 1 18:02 pts/0 00:00:01 /usr/java/jdk/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/bin/../zookeeper-3.4.8.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/zookeeper/bin/../conf:/usr/java/jdk/jre/lib:/usr/java/jdk/lib -Xms512M -Xmx2G -Xmn1G -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /usr/local/zookeeper/bin/../conf/zoo.cfg
會看到-Xms512M -Xmx2G -Xmn1G
[root@emm-kafka01-10--174 bin]# ps -ef|grep zookeeper|grep 512
root 11417 1 8 18:36 pts/0 00:00:01 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/bin/../zookeeper-3.4.8.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/zookeeper/bin/../conf: -Xms512M -Xmx2G -Xmn1G -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /usr/local/zookeeper/bin/../conf/zoo.cfg
報錯
[root@emm-kafka01-10--174 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
[root@emm-kafka01-10--174 bin]# vim zookeeper.out
2019-03-13 18:25:13,593 [myid:1] - WARN [WorkerSender[myid=1]:QuorumCnxManager@400] - Cannot open channel to 2
at election address /10.2.10.175:3888
zookeeper之間沒有相關關聯,這個是防火墻阻擋了。
是因為iptables沒有關閉
service iptables stop
chkconfig iptables off
執行
/bin/systemctl stop iptables.service
systemctl disable iptables.service**
配置環境變量
echo 'export PATH=/usr/local/zookeeper/bin:$PATH' >> /etc/profile
source /etc/profile
[root@emm-kafka01-10--174 bin]# echo 'export PATH=/usr/local/zookeeper/bin:$PATH' >> /etc/profile
[root@emm-kafka01-10--174 bin]# tail -1 /etc/profile
export PATH=/usr/local/zookeeper/bin:$PATH
[root@emm-kafka01-10--174 bin]# source /etc/profile
[root@emm-kafka01-10--174 bin]# which zkServer.sh
/usr/local/zookeeper/bin/zkServer.sh
[root@emm-kafka01-10--174 bin]# cd ~
[root@emm-kafka01-10--174 ~]# zkServer.sh restart
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@emm-kafka01-10--174 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: followe
[root@emm-kafka01-10--174 bin]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1316/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1102/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1316/master
tcp6 0 0 :::2181 :::* LISTEN 11417/java
tcp6 0 0 10.2.10.174:3888 :::* LISTEN 11417/java
tcp6 0 0 :::40466 :::* LISTEN 11417/java
tcp6 0 0 :::22 :::* LISTEN 1102/sshd
[root@emm-kafka02-10--175 bin]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1313/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1102/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1313/master
tcp6 0 0 :::41921 :::* LISTEN 10182/java
tcp6 0 0 :::2181 :::* LISTEN 10182/java
tcp6 0 0 10.2.10.175:2888 :::* LISTEN 10182/java
tcp6 0 0 10.2.10.175:3888 :::* LISTEN 10182/java
tcp6 0 0 :::22 :::* LISTEN 1102/sshd
root@emm-kafka03-10--176 bin]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1316/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1104/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1316/master
tcp6 0 0 :::42047 :::* LISTEN 11520/java
tcp6 0 0 :::2181 :::* LISTEN 11520/java
tcp6 0 0 10.2.10.176:3888 :::* LISTEN 11520/java
tcp6 0 0 :::22 :::* LISTEN 1104/sshd
[root@emm-kafka03-10--176 bin]#
我們發現只有leader才有2888端口,3888每個上面都有 2181 是沒有zookeeper監聽端口,每個都有
zookeeper安裝完成
zookeeper命令行客戶端何用以及功能測試
[root@emm-kafka01-10--174 ~]# zkCli.sh -server 10.2.10.174
Connecting to 10.2.10.174
2019-03-13 19:40:04,797 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT
2019-03-13 19:40:04,806 [myid:] - INFO [main:Environment@100] - Client environment:host.name=emm-kafka01-10--174
2019-03-13 19:40:04,807 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_102
2019-03-13 19:40:04,812 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2019-03-13 19:40:04,813 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/java/jdk1.8.0_102/jre
2019-03-13 19:40:04,813 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/bin/../zookeeper-3.4.8.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/zookeeper/bin/../conf:
2019-03-13 19:40:04,814 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2019-03-13 19:40:04,814 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2019-03-13 19:40:04,814 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2019-03-13 19:40:04,814 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2019-03-13 19:40:04,815 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2019-03-13 19:40:04,815 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-862.14.4.el7.x86_64
2019-03-13 19:40:04,815 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2019-03-13 19:40:04,816 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2019-03-13 19:40:04,816 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/root
2019-03-13 19:40:04,819 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=10.2.10.174 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@506c589e
Welcome to ZooKeeper!
2019-03-13 19:40:04,883 [myid:] - INFO [main-SendThread(10.2.10.174:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 10.2.10.174/10.2.10.174:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2019-03-13 19:40:05,038 [myid:] - INFO [main-SendThread(10.2.10.174:2181):ClientCnxn$SendThread@876] - Socket connection established to 10.2.10.174/10.2.10.174:2181, initiating session
2019-03-13 19:40:05,055 [myid:] - INFO [main-SendThread(10.2.10.174:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 10.2.10.174/10.2.10.174:2181, sessionid = 0x16976d0bd810001, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 10.2.10.174(CONNECTED) 0] ls /
[zookeeper]
[zk: 10.2.10.174(CONNECTED) 1] ls /zookeeper
[quota]
[zk: 10.2.10.174(CONNECTED) 2] ls /zookeeper/quota
[]
[zk: 10.2.10.174(CONNECTED) 3] get /zookeeper/quota
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 0
[zk: 10.2.10.174(CONNECTED) 4] get /zookeeper
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
zookeeper的啟動腳本
[root@emm-kafka03-10--176 scripts]# cat zkstart.sh
#!/bin/bash
source /etc/profile
zkServer.sh restart
sleep 1
zkServer.sh status
sleep 3
[root@emm-kafka01-10--174 scripts]# sh /opt/scripts/zkstart.sh
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... no zookeeper to stop (could not find file /usr/local/zookeeper/data/zookeeper_server.pid)
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@emm-kafka01-10--174 scripts]# jps
7974 QuorumPeerMain
9998 Jps
可以設置開機自啟動
chmod +x /etc/rc.d/rc.local
echo "/usr/bin/sh /opt/scripts/zkstart.sh" >> /etc/rc.d/rc.local
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。