第一步 //用执行初始化模板 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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。