检测是否安装 JDK
[root@localhost usr]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
若已安装 JDK 则继续,否则先按照 JDK,安装步骤参考:https://blog.csdn.net/qq_33189908/article/details/1001316
下载 zookeeper 安装包
地址路径:https://www.apache.org/dyn/closer.cgi/zookeeper/
目前以 zookeeper-3.4.14 为例
操作步骤
- 将下载的 jar 包放置 /opt 目录下
- 执行 tar zxvf jdk-8u221-linux-x64.tar.gz 命令解压文件
- 进入 zookeeper-3.4.14;
- 执行 mkdir data 创建一个名为data的文件夹
- 进入 zookeeper-3.4.14/conf 目录,执行 cp zoo_sample.cfg zoo.cfg;复制一份zoo_sample.cfg文件并重命名为zoo.cfg
- vi zoo.cfg 打开该文件并修改配置配置参数
-
dataDir=/opt/zookeeper-3.4.14/data
- 配置环境变量
- 执行 sudo vi /etc/profile 打开文本
- 添加以下代码
-
export ZOO_HOME=/opt/zookeeper-3.4.14 export PATH=$ZOO_HOME/bin:$JAVA_HOME/bin:$PATH
- 执行 :wq 保存退出编辑
- 执行 source /etc/profile 使环境变量设置立即生效
验证是否安装成功
- 进入 zookeeper-3.4.14/bin 目录;执行 zkServer.sh start ;启动zookeeper服务器
-
[root@localhost bin]# zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
-
-
执行 zkCli.sh ;启动zookeeper客户端
-
bash: zkServer.sh: command not found [root@localhost bin]# vi /etc/profile [root@localhost bin]# source /etc/profile [root@localhost bin]# zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@localhost bin]# zkCli.sh Connecting to localhost:2181 2019-08-28 05:26:00,532 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT 2019-08-28 05:26:00,539 [myid:] - INFO [main:Environment@100] - Client environment:host.name=localhost.localdomain 2019-08-28 05:26:00,539 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_221 2019-08-28 05:26:00,542 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2019-08-28 05:26:00,543 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/jdk1.8.0_221/jre 2019-08-28 05:26:00,543 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/zookeeper-3.4.14/bin/../zookeeper-server/target/classes:/opt/zookeeper-3.4.14/bin/../build/classes:/opt/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/*.jar:/opt/zookeeper-3.4.14/bin/../build/lib/*.jar:/opt/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/opt/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/opt/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/opt/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/opt/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/opt/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/zookeeper-3.4.14/bin/../conf:.:/usr/jdk1.8.0_221/lib/dt.jar:/usr/jdk1.8.0_221/lib/tools.jar 2019-08-28 05:26:00,543 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2019-08-28 05:26:00,544 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2019-08-28 05:26:00,544 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2019-08-28 05:26:00,544 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2019-08-28 05:26:00,544 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2019-08-28 05:26:00,544 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.18-194.el5 2019-08-28 05:26:00,544 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2019-08-28 05:26:00,544 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2019-08-28 05:26:00,545 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/zookeeper-3.4.14/bin 2019-08-28 05:26:00,546 [myid:] - INFO [main:ZooKeeper@442] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@3eb07fd3 2019-08-28 05:26:00,589 [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) Welcome to ZooKeeper! 2019-08-28 05:26:00,739 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@879] - Socket connection established to localhost/127.0.0.1:2181, initiating session JLine support is enabled 2019-08-28 05:26:00,893 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x100014705450000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null
若服务器与客户端都能启起来,则 zookeeper 安装成功;
-
常见安装失败原因
-
bash: zkServer.sh: command not found
-
zookeeper环境变量未配置
-