Linux下搭建Zookeeper
程序员文章站
2022-03-03 14:46:48
...
ZooKeeper是一种分布式协调服务,用于管理大型主机。在分布式环境中协调和管理服务是一个复杂的过程。ZooKeeper通过其简单的架构和API解决了这个问题。ZooKeeper允许开发人员专注于核心应用程序逻辑,而不必担心应用程序的分布式特性。
- 下载资源并解压缩
使用wget下载zookeeper到指定的目录下。
wget -P /usr/local https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
其中的-P 后面携带的是路径。
查看zookeeper的镜像
接着进行解压
tar -zxvf zookeeper-3.4.14.tar.gz
- 创建data目录
在zookeeper目录下创建一个data文件夹,用来存放输出日志
mkdir data
[root@VM_0_15_centos zookeeper-3.4.14]# ll
total 1720
drwxr-xr-x 2 2002 2002 4096 Mar 7 2019 bin
-rw-rw-r-- 1 2002 2002 97426 Mar 7 2019 build.xml
drwxr-xr-x 2 2002 2002 4096 Mar 7 2019 conf
drwxrwxr-x 2 root root 4096 Mar 18 22:42 data
drwxr-xr-x 2 2002 2002 4096 Mar 7 2019 dist-maven
-rw-rw-r-- 1 2002 2002 1709 Mar 7 2019 ivysettings.xml
-rw-rw-r-- 1 2002 2002 10742 Mar 7 2019 ivy.xml
drwxr-xr-x 4 2002 2002 4096 Mar 7 2019 lib
-rw-rw-r-- 1 2002 2002 11970 Mar 7 2019 LICENSE.txt
-rw-rw-r-- 1 2002 2002 3132 Mar 7 2019 NOTICE.txt
-rw-rw-r-- 1 2002 2002 31622 Mar 7 2019 pom.xml
-rw-rw-r-- 1 2002 2002 1765 Mar 7 2019 README.md
-rw-rw-r-- 1 2002 2002 1770 Mar 7 2019 README_packaging.txt
drwxr-xr-x 3 2002 2002 4096 Mar 7 2019 src
-rw-rw-r-- 1 2002 2002 1515359 Mar 7 2019 zookeeper-3.4.14.jar
-rw-rw-r-- 1 2002 2002 836 Mar 7 2019 zookeeper-3.4.14.jar.asc
-rw-rw-r-- 1 2002 2002 33 Mar 7 2019 zookeeper-3.4.14.jar.md5
-rw-rw-r-- 1 2002 2002 41 Mar 7 2019 zookeeper-3.4.14.jar.sha1
drwxr-xr-x 3 2002 2002 4096 Mar 7 2019 zookeeper-client
drwxr-xr-x 12 2002 2002 4096 Mar 7 2019 zookeeper-contrib
drwxr-xr-x 7 2002 2002 4096 Mar 7 2019 zookeeper-docs
drwxr-xr-x 3 2002 2002 4096 Mar 7 2019 zookeeper-it
drwxr-xr-x 4 2002 2002 4096 Mar 7 2019 zookeeper-jute
drwxr-xr-x 5 2002 2002 4096 Mar 7 2019 zookeeper-recipes
drwxr-xr-x 3 2002 2002 4096 Mar 7 2019 zookeeper-server
- 修改zoo.cfg配置文件
进入到conf目录下,拷贝zoo_sample.cfg重命名未zoo.cfg
cp zoo_sample.cfg zoo.cfg
接着用vim命令修改其中的dataDir参数,对应上述新建的data目录。
如果想修改对应的端口号,也可以通过修改clientPort。
dataDir=/usr/local/zookeeper-3.4.14/data
clientPort=2181
- 常用的命令
进入到zookeeper的目录下,操作bin/zkServer.sh。
(1)启动
[root@VM_0_15_centos zookeeper-3.4.14]# bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
(2)重启
[root@VM_0_15_centos zookeeper-3.4.14]# bin/zkServer.sh restart
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
(3)查看状态
[root@VM_0_15_centos zookeeper-3.4.14]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: standalone
(4)停止
[[email protected]_0_15_centos zookeeper-3.4.14]# bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
(5)客户端登录
[root@VM_0_15_centos zookeeper-3.4.14]# bin/zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2020-03-18 23:09:00,106 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
2020-03-18 23:09:00,110 [myid:] - INFO [main:Environment@100] - Client environment:host.name=VM_0_15_centos
2020-03-18 23:09:00,111 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_201
2020-03-18 23:09:00,113 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2020-03-18 23:09:00,113 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/java/jdk1.8.0_201/jre
2020-03-18 23:09:00,113 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper-3.4.14/bin/../zookeeper-server/target/classes:/usr/local/zookeeper-3.4.14/bin/../build/classes:/usr/local/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/*.jar:/usr/local/zookeeper-3.4.14/bin/../build/lib/*.jar:/usr/local/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/usr/local/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/usr/local/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/usr/local/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/usr/local/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/usr/local/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/usr/local/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/usr/local/zookeeper-3.4.14/bin/../conf:
2020-03-18 23:09:00,113 [myid:] - INFO [main:[email protected]] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2020-03-18 23:09:00,113 [myid:] - INFO [main:[email protected]] - Client environment:java.io.tmpdir=/tmp
2020-03-18 23:09:00,113 [myid:] - INFO [main:[email protected]] - Client environment:java.compiler=<NA>
2020-03-18 23:09:00,113 [myid:] - INFO [main:[email protected]] - Client environment:os.name=Linux
2020-03-18 23:09:00,113 [myid:] - INFO [main:[email protected]] - Client environment:os.arch=amd64
2020-03-18 23:09:00,114 [myid:] - INFO [main:[email protected]] - Client environment:os.version=3.10.0-514.26.2.el7.x86_64
2020-03-18 23:09:00,114 [myid:] - INFO [main:[email protected]] - Client environment:user.name=root
2020-03-18 23:09:00,114 [myid:] - INFO [main:[email protected]] - Client environment:user.home=/root
2020-03-18 23:09:00,114 [myid:] - INFO [main:[email protected]] - Client environment:user.dir=/usr/local/zookeeper-3.4.14
2020-03-18 23:09:00,115 [myid:] - INFO [main:[email protected]] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 [email protected]
2020-03-18 23:09:00,146 [myid:] - INFO [main-SendThread(VM_0_15_centos:2181):[email protected]] - Opening socket connection to server VM_0_15_centos/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
JLine support is enabled
2020-03-18 23:09:00,305 [myid:] - INFO [main-SendThread(VM_0_15_centos:2181):[email protected]] - Socket connection established to VM_0_15_centos/127.0.0.1:2181, initiating session
2020-03-18 23:09:00,377 [myid:] - INFO [main-SendThread(VM_0_15_centos:2181):[email protected]] - Session establishment complete on server VM_0_15_centos/127.0.0.1:2181, sessionid = 0x1076e6657eb0000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0]
上一篇: centos7离线安装nginx
下一篇: Linux安装Kafka(单机版)
推荐阅读
-
Linux下Docker CE使用从包中安装的方式详解
-
Windows下搭建python开发环境详细步骤
-
Win7下搭建python开发环境图文教程(安装Python、pip、解释器)
-
Windows系统下使用flup搭建Nginx和Python环境的方法
-
Linux下将Python的Django项目部署到Apache服务器
-
Linux下python与C++使用dlib实现人脸检测
-
windows下zendframework项目环境搭建(通过命令行配置)
-
linux下mysql 5.7.16 免安装版本图文教程
-
linux下安装tomcat安装及配置教程(在linux中怎么安装tomcat)
-
Python获取Linux系统下的本机IP地址代码分享