002、zookeeper单机环境部署
本文最后更新于 258 天前,其中的信息可能已经过时,如有错误请发送邮件到wuxianglongblog@163.com

zookeeper单机环境部署

一.部署zookeeper服务

1.测试环境介绍

[root@elk101.oldboyedu.com ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# uname -r
3.10.0-1160.el7.x86_64
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# uname -m
x86_64
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        274M        3.3G         11M        157M        3.2G
Swap:            0B          0B          0B
[root@elk101.oldboyedu.com ~]# 

2.安装JDK并配置环境变量

[root@elk101.oldboyedu.com ~]# ll
总用量 187324
-rw-r--r--. 1 root root 191817140 4月  22 20:31 jdk-8u201-linux-x64.tar.gz
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# mkdir -pv /oldboy/softwares/
mkdir: 已创建目录 "/yinzhengjie"
mkdir: 已创建目录 "/oldboy/softwares/"
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# tar xf jdk-8u201-linux-x64.tar.gz -C /oldboy/softwares/
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# ln -sv /oldboy/softwares/jdk1.8.0_201/ /oldboy/softwares/jdk
"/oldboy/softwares/jdk" -> "/oldboy/softwares/jdk1.8.0_201/"
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# ll /oldboy/softwares/
总用量 0
lrwxrwxrwx. 1 root root  36 4月  22 20:38 jdk -> /oldboy/softwares/jdk1.8.0_201/
drwxr-xr-x. 7   10  143 245 12月 16 2018 jdk1.8.0_201
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# vim /etc/profile.d/jdk.sh
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# cat /etc/profile.d/jdk.sh
#!/bin/bash

# Add by yinzhengjie for JDK
JAVA_HOME=/oldboy/softwares/jdk
PATH=$PATH:$JAVA_HOME/bin
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# chmod +x /etc/profile.d/jdk.sh
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# source /etc/profile.d/jdk.sh
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
[root@elk101.oldboyedu.com ~]# 

温馨提示:
    JDK官方的下载地址: "https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html"

3.安装zookeeper并配置环境变量

[root@elk101.oldboyedu.com ~]# vim /etc/profile.d/zookeeper.sh
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# cat /etc/profile.d/zookeeper.sh
#!/bin/bash

# Add by yinzhengjie for Kafka
ZK_HOME=/oldboy/softwares/zookeeper
PATH=$PATH:$ZK_HOME/bin
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# source /etc/profile.d/zookeeper.sh
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# zk
zkCleanup.sh            zkCli.sh                zkEnv.sh                zkServer-initialize.sh  zkSnapshotComparer.cmd  zkSnapShotToolkit.cmd   zkTxnLogToolkit.cmd
zkCli.cmd               zkEnv.cmd               zkServer.cmd            zkServer.sh             zkSnapshotComparer.sh   zkSnapShotToolkit.sh    zkTxnLogToolkit.sh
[root@elk101.oldboyedu.com ~]# zk

[root@elk101.oldboyedu.com ~]# useradd zookeeper

4.创建zookeeper用户并指定家目录

[root@elk101.oldboyedu.com ~]# mkdir -pv /oldboy/data
mkdir: 已创建目录 "/oldboy/data"
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# useradd -d /oldboy/data/zookeeper zookeeper
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# ll  /oldboy/data
总用量 0
drwx------. 2 zookeeper zookeeper 62 4月  22 21:49 zookeeper
[root@elk101.oldboyedu.com ~]# 

5.配置zookeeper服务

[root@elk101.oldboyedu.com ~]# cd /oldboy/softwares/zookeeper/conf/
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# ll
总用量 12
-rw-r--r--. 1 zookeeper zookeeper  535 3月  17 17:45 configuration.xsl
-rw-r--r--. 1 zookeeper zookeeper 3435 3月  17 17:45 log4j.properties
-rw-r--r--. 1 zookeeper zookeeper 1148 3月  17 17:45 zoo_sample.cfg
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# cp zoo_sample.cfg zoo.cfg 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# vim zoo.cfg 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# grep dataDir= zoo.cfg 
dataDir=/tmp/zookeeper
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# sed -ri 's#(dataDir=)/tmp/zookeeper#\1/oldboy/data/zookeeper#' zoo.cfg 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# 
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# grep dataDir= zoo.cfg 
dataDir=/oldboy/data/zookeeper
[root@elk101.oldboyedu.com /oldboy/softwares/zookeeper/conf]# 

二.管理zookeeper服务

1.启动zookeeper(温馨提示: 本案例使用的是root用户启动服务,这导致zk的数据文件均为root用户啦~生产环境中建议还是使用zookeeper用户来启动哟~)

[root@elk101.oldboyedu.com ~]# zkServer.sh start  # 启动zookeeper服务
/oldboy/softwares/jdk/bin/java
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# zkServer.sh status  # 查看zookeeper服务状态,启动zookeeper是需要耗时的,因为它会现启动JVM。
/oldboy/softwares/jdk/bin/java
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# zkServer.sh status  # 启动一段时间后,再次查看发现,其模式为:"standalone"
/oldboy/softwares/jdk/bin/java
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# ss -ntl  # 查看zookeeper服务监听的端口
State       Recv-Q Send-Q                                                 Local Address:Port                                                                Peer Address:Port              
LISTEN      0      128                                                                *:22                                                                             *:*                  
LISTEN      0      100                                                        127.0.0.1:25                                                                             *:*                  
LISTEN      0      50                                                              [::]:2181                                                                        [::]:*                  
LISTEN      0      50                                                              [::]:8080                                                                        [::]:*                  
LISTEN      0      50                                                              [::]:36148                                                                       [::]:*                  
LISTEN      0      128                                                             [::]:22                                                                          [::]:*                  
LISTEN      0      100                                                            [::1]:25                                                                          [::]:*                  
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# ll /oldboy/data/zookeeper/
总用量 4
drwxr-xr-x. 2 root root 24 4月  22 21:55 version-2
-rw-r--r--. 1 root root  5 4月  22 21:54 zookeeper_server.pid
[root@elk101.oldboyedu.com ~]# 

2.使用"zkCli.sh"工具连接zookeeper服务

[root@elk101.oldboyedu.com ~]# zkCli.sh 
/oldboy/softwares/jdk/bin/java
Connecting to localhost:2181
2021-04-22 22:00:36,758 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
2021-04-22 22:00:36,761 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=elk101.oldboyedu.com
2021-04-22 22:00:36,761 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_201
2021-04-22 22:00:36,762 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2021-04-22 22:00:36,762 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/oldboy/softwares/jdk1.8.0_201/jre
2021-04-22 22:00:36,762 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=/oldboy/softwares/zookeeper/bin/../zookeeper-server/target/classes:/yinzhengjie/softw
ares/zookeeper/bin/../build/classes:/oldboy/softwares/zookeeper/bin/../zookeeper-server/target/lib/*.jar:/oldboy/softwares/zookeeper/bin/../build/lib/*.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-jute-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/zookeeper-3.7.0.jar:/oldboy/softwares/zookeeper/bin/../lib/snappy-java-1.1.7.7.jar:/oldboy/softwares/zookeeper/bin/../lib/slf4j-log4j12-1.7.30.jar:/oldboy/softwares/zookeeper/bin/../lib/slf4j-api-1.7.30.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_servlet-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_hotspot-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient_common-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/simpleclient-0.9.0.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-transport-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-resolver-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-handler-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-common-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-codec-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/netty-buffer-4.1.59.Final.jar:/oldboy/softwares/zookeeper/bin/../lib/metrics-core-4.1.12.1.jar:/oldboy/softwares/zookeeper/bin/../lib/log4j-1.2.17.jar:/oldboy/softwares/zookeeper/bin/../lib/jline-2.14.6.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-util-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-server-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-security-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-io-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/jetty-http-9.4.38.v20210224.jar:/oldboy/softwares/zookeeper/bin/../lib/javax.servlet-api-3.1.0.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-databind-2.10.5.1.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-core-2.10.5.jar:/oldboy/softwares/zookeeper/bin/../lib/jackson-annotations-2.10.5.jar:/oldboy/softwares/zookeeper/bin/../lib/commons-cli-1.4.jar:/oldboy/softwares/zookeeper/bin/../lib/audience-annotations-0.12.0.jar:/oldboy/softwares/zookeeper/bin/../zookeeper-*.jar:/oldboy/softwares/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/oldboy/softwares/zookeeper/bin/../conf:2021-04-22 22:00:36,762 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2021-04-22 22:00:36,762 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2021-04-22 22:00:36,763 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2021-04-22 22:00:36,763 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2021-04-22 22:00:36,763 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2021-04-22 22:00:36,763 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=3.10.0-1160.el7.x86_64
2021-04-22 22:00:36,763 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2021-04-22 22:00:36,763 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2021-04-22 22:00:36,763 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/root
2021-04-22 22:00:36,763 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=49MB
2021-04-22 22:00:36,764 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=228MB
2021-04-22 22:00:36,764 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=57MB
2021-04-22 22:00:36,767 [myid:] - INFO  [main:ZooKeeper@637] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyW
atcher@b065c632021-04-22 22:00:36,770 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2021-04-22 22:00:36,775 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2021-04-22 22:00:36,783 [myid:] - INFO  [main:ClientCnxn@1726] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2021-04-22 22:00:36,798 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1171] - Opening socket connection to server localhost/127.0.0.1:2181.
2021-04-22 22:00:36,799 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL (unknown
 error)JLine support is enabled
2021-04-22 22:00:36,816 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1005] - Socket connection established, initiating session, client: /127.0.0.1:48
592, server: localhost/127.0.0.1:21812021-04-22 22:00:36,829 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1438] - Session establishment complete on server localhost/127.0.0.1:2181, sessi
on id = 0x100015ae77b0001, negotiated timeout = 30000
WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] 
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1] 
[zk: localhost:2181(CONNECTED) 1] quit 
2021-04-22 22:01:05,165 [myid:localhost:2181] - WARN  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1284] - An exception was thrown while closing send thread for session 0x100015ae
77b0001.EndOfStreamException: Unable to read additional data from server sessionid 0x100015ae77b0001, likely server has closed socket
    at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:77)
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1280)

WATCHER::

WatchedEvent state:Closed type:None path:null
2021-04-22 22:01:05,268 [myid:] - INFO  [main:ZooKeeper@1232] - Session: 0x100015ae77b0001 closed
2021-04-22 22:01:05,269 [myid:] - ERROR [main:ServiceUtils@42] - Exiting JVM with code 0
2021-04-22 22:01:05,269 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@570] - EventThread shut down for session: 0x100015ae77b0001
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# 

3.停止zookeeper

[root@elk101.oldboyedu.com ~]# ss -ntl
State       Recv-Q Send-Q                                                 Local Address:Port                                                                Peer Address:Port              
LISTEN      0      128                                                                *:22                                                                             *:*                  
LISTEN      0      100                                                        127.0.0.1:25                                                                             *:*                  
LISTEN      0      50                                                              [::]:2181                                                                        [::]:*                  
LISTEN      0      50                                                              [::]:8080                                                                        [::]:*                  
LISTEN      0      50                                                              [::]:36148                                                                       [::]:*                  
LISTEN      0      128                                                             [::]:22                                                                          [::]:*                  
LISTEN      0      100                                                            [::1]:25                                                                          [::]:*                  
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# zkServer.sh status
/oldboy/softwares/jdk/bin/java
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# zkServer.sh stop
/oldboy/softwares/jdk/bin/java
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# zkServer.sh status
/oldboy/softwares/jdk/bin/java
ZooKeeper JMX enabled by default
Using config: /oldboy/softwares/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Error contacting service. It is probably not running.
[root@elk101.oldboyedu.com ~]# 
[root@elk101.oldboyedu.com ~]# ss -ntl
State       Recv-Q Send-Q                                                 Local Address:Port                                                                Peer Address:Port              
LISTEN      0      128                                                                *:22                                                                             *:*                  
LISTEN      0      100                                                        127.0.0.1:25                                                                             *:*                  
LISTEN      0      128                                                             [::]:22                                                                          [::]:*                  
LISTEN      0      100                                                            [::1]:25                                                                          [::]:*                  
[root@elk101.oldboyedu.com ~]# 
谨此笔记,记录过往。凭君阅览,如能收益,莫大奢望。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇