Centos7部署Zookeeper单节点

1、安装准备好一个虚拟机(vmware、VirtualBox)。

Centos7部署Zookeeper单节点

2、使用连接工具进行连接(Xshell、electerm等工具,我使用的electerm工具)。

使用

ip address

或

ip addr

来查看虚拟机地址,如果使用的是局域网内的需要设置桥接网络,复制物理地址,如果是本机开的虚拟机则不需要。

Centos7部署Zookeeper单节点

使用连接工具进行连接(electerm)

Centos7部署Zookeeper单节点

如果你看到了,如下的界面就表示连接成功了。

Centos7部署Zookeeper单节点

3、下载zookeeper

zookeeper官方下载地址

我这里下载的zookeeper的3.6.3,连接如下

apache-zookeeper-3.6.3

4、构建环境

切换到opt目录

cd /opt

创建modules目录和software目录(父子关系,也可以不创建直接保存到opt中,我是做了个分类)。

mkdir -p /opt/modules/software

查看是否创建成功(如果未创建本步骤可以省略)

ls

Centos7部署Zookeeper单节点

5、上传zookeeper文件


Centos7部署Zookeeper单节点

 6、解压zookeeper压缩包

切换到software

cd ./modules/software

查看zookeeper压缩包是否存在

ls

Centos7部署Zookeeper单节点

如果不存在,可能是上传到别的路径或者是上传失败了。

解压zookeeper压缩文件到/opt/modules

tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz -C /opt/modules/

Centos7部署Zookeeper单节点

如果没有任何错误,则表示解压成功了。

7、部署与运行

切换到zookeeper的安装路径

cd /opt/modules

修改zookeeper文件的名称(名称太长了,不容易操作,可以不修改)

mv apache-zookeeper-3.6.3-bin/ zookeeper3.6.3

切换到zookeeper的配置目录中

cd zookeeper3.6.3/conf/

创建一个data文件夹

mkdir /opt/modules/zookeeper3.6.3/data

复制一份zoo_sample.cfg配置文件并且修改其名称为zoo_cfg

cp zoo_sample.cfg zoo.cfg

修改zoo_cfg配置

vi zoo.cfg

或

vim zoo.cfg

如果使用vim报centos vim command not found,可以尝试安装一下vim

yum install -y vim

再进行编辑

修改的配置(可选,也可以保持默认值)

tickTime = 2000
# zookeeper的数据保存位置(推荐修改)
dataDir = /opt/zookeeper3.6.3/data
clientPort = 2181
initLimit = 5
syncLimit = 2

如果当前目录就是zookeeper安装目录,则可以使用

pwd

获取后进行修改

Centos7部署Zookeeper单节点

按下ESC -> 在英文或者半角状态下按下Shift+:键,输入wq! 退出编辑。

运行zookeeper

/opt/modules/zookeeper3.6.3/bin/zkServer.sh start

如果看到如下的结果表示运行成功了

Centos7部署Zookeeper单节点

 通过zkCli来进行连接测试

/opt/modules/zookeeper3.6.3/bin/zkCli.sh

会有如下字符输出

/usr/bin/java
Connecting to localhost:2181
2021-09-29 09:41:25,479 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.6.3--6401e4ad2087061bc6b9f80dec2d69f2e3c8660a, built on 04/08/2021 16:35 GMT
2021-09-29 09:41:25,546 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=zookeeper-standlone
2021-09-29 09:41:25,546 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_302
2021-09-29 09:41:25,548 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Red Hat, Inc.
2021-09-29 09:41:25,548 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el7_9.x86_64/jre
2021-09-29 09:41:25,548 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=/opt/modules/zookeeper3.6.3/bin/../zookeeper-server/target/classes:/opt/modules/zookeeper3.6.3/bin/../build/classes:/opt/modules/zookeeper3.6.3/bin/../zookeeper-server/target/lib/*.jar:/opt/modules/zookeeper3.6.3/bin/../build/lib/*.jar:/opt/modules/zookeeper3.6.3/bin/../lib/zookeeper-prometheus-metrics-3.6.3.jar:/opt/modules/zookeeper3.6.3/bin/../lib/zookeeper-jute-3.6.3.jar:/opt/modules/zookeeper3.6.3/bin/../lib/zookeeper-3.6.3.jar:/opt/modules/zookeeper3.6.3/bin/../lib/snappy-java-1.1.7.jar:/opt/modules/zookeeper3.6.3/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/modules/zookeeper3.6.3/bin/../lib/slf4j-api-1.7.25.jar:/opt/modules/zookeeper3.6.3/bin/../lib/simpleclient_servlet-0.6.0.jar:/opt/modules/zookeeper3.6.3/bin/../lib/simpleclient_hotspot-0.6.0.jar:/opt/modules/zookeeper3.6.3/bin/../lib/simpleclient_common-0.6.0.jar:/opt/modules/zookeeper3.6.3/bin/../lib/simpleclient-0.6.0.jar:/opt/modules/zookeeper3.6.3/bin/../lib/netty-transport-native-unix-common-4.1.63.Final.jar:/opt/modules/zookeeper3.6.3/bin/../lib/netty-transport-native-epoll-4.1.63.Final.jar:/opt/modules/zookeeper3.6.3/bin/../lib/netty-transport-4.1.63.Final.jar:/opt/modules/zookeeper3.6.3/bin/../lib/netty-resolver-4.1.63.Final.jar:/opt/modules/zookeeper3.6.3/bin/../lib/netty-handler-4.1.63.Final.jar:/opt/modules/zookeeper3.6.3/bin/../lib/netty-common-4.1.63.Final.jar:/opt/modules/zookeeper3.6.3/bin/../lib/netty-codec-4.1.63.Final.jar:/opt/modules/zookeeper3.6.3/bin/../lib/netty-buffer-4.1.63.Final.jar:/opt/modules/zookeeper3.6.3/bin/../lib/metrics-core-3.2.5.jar:/opt/modules/zookeeper3.6.3/bin/../lib/log4j-1.2.17.jar:/opt/modules/zookeeper3.6.3/bin/../lib/json-simple-1.1.1.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jline-2.14.6.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jetty-util-ajax-9.4.39.v20210325.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jetty-util-9.4.39.v20210325.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jetty-servlet-9.4.39.v20210325.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jetty-server-9.4.39.v20210325.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jetty-security-9.4.39.v20210325.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jetty-io-9.4.39.v20210325.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jetty-http-9.4.39.v20210325.jar:/opt/modules/zookeeper3.6.3/bin/../lib/javax.servlet-api-3.1.0.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jackson-databind-2.10.5.1.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jackson-core-2.10.5.jar:/opt/modules/zookeeper3.6.3/bin/../lib/jackson-annotations-2.10.5.jar:/opt/modules/zookeeper3.6.3/bin/../lib/commons-cli-1.2.jar:/opt/modules/zookeeper3.6.3/bin/../lib/audience-annotations-0.5.0.jar:/opt/modules/zookeeper3.6.3/bin/../zookeeper-*.jar:/opt/modules/zookeeper3.6.3/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/modules/zookeeper3.6.3/bin/../conf:
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=3.10.0-1160.42.2.el7.x86_64
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/opt/modules/zookeeper3.6.3/conf
2021-09-29 09:41:25,549 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=23MB
2021-09-29 09:41:25,551 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=228MB
2021-09-29 09:41:25,551 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=29MB
2021-09-29 09:41:25,556 [myid:] - INFO  [main:ZooKeeper@1006] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@379619aa
2021-09-29 09:41:25,559 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2021-09-29 09:41:25,566 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2021-09-29 09:41:25,573 [myid:] - INFO  [main:ClientCnxn@1736] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2021-09-29 09:41:25,588 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1181] - Opening socket connection to server localhost/127.0.0.1:2181.
2021-09-29 09:41:25,588 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1183] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2021-09-29 09:41:25,662 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1013] - Socket connection established, initiating session, client: /127.0.0.1:52286, server: localhost/127.0.0.1:2181
2021-09-29 09:41:25,699 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1448] - Session establishment complete on server localhost/127.0.0.1:2181, session id = 0x100003ad51e0000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] 

恭喜你,zookeeper单节点部署成功了。

如何停止zookeeper单节点服务呢?

退出zkCli

quit

停止zookeeper服务

/opt/modules/zookeeper3.6.3/bin/zkServer.sh stop

如果看到了如下的结果表示停止成功了。

Centos7部署Zookeeper单节点

 至此,Centos7部署zookeeper单节点完成了,如果这个文章帮助到了你,那么请为我点一个赞,谢谢。

上一篇:node.js 报错 throw new TypeError(‘app.use() requires a middleware function‘)


下一篇:JavaScript--> JavaScript reference--> Statements and declarations--> import