yum安装zookeeper

时间:2025-02-13 08:21:32

文章目录

    • centos安装zookeeper
    • 下载安装
    • 修改配置文件
    • 启动和停止
    • 启动报错
    • 查看日志
    • 重新启动
    • 停止和重启
    • 验证
    • 单机zk集群

centos安装zookeeper

安装路径/usr/local/src/project

下载安装

zookeeper.3.6.3

以zookeeper.3.6.2版本为例

wget /apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.

修改配置文件

[root@centos-linux1 apache-zookeeper-3.6.2]# tar -zxvf apache-zookeeper-3.6.
[root@centos-linux1 apache-zookeeper-3.6.2]# cd conf/
[root@centos-linux1 conf]# cp zoo_sample.cfg 
[root@centos-linux1 conf]# ll
total 16
-rw-rw-r--. 1 cancanliu cancanliu  535 Sep  4 20:43 
-rw-rw-r--. 1 cancanliu cancanliu 3435 Sep  4 20:43 
-rw-r--r--. 1 root      root      1148 Feb  5 11:25 
-rw-rw-r--. 1 cancanliu cancanliu 1148 Sep  4 20:43 zoo_sample.cfg
[root@centos-linux1 conf]# ll
dataDir=/usr/local/src/program/apache-zookeeper-3.6.2-bin/data
dataLogDir=/usr/local/src/program/apache-zookeeper-3.6.2-bin/logs

启动和停止

bin/ start

启动报错

ZooKeeper JMX enabled by default
Using config: /usr/local/src/program/apache-zookeeper-3.6.2/bin/../conf/
Starting zookeeper ... FAILED TO START

查看日志

Error: Could not find or load main class 

原因是需要安装编译好的二进制文件包,重新下载apache-zookeeper-3.6.包安装

重新启动

[root@centos-linux1 apache-zookeeper-3.6.2-bin]# bin/ start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../conf/
Starting zookeeper ... STARTED

停止和重启

bin/ stop

bin/ restart

验证

[root@centos-linux1 apache-zookeeper-3.6.2-bin]# bin/ -server localhost:2181
/usr/bin/java
Connecting to localhost:2181
2021-02-05 13:44:30,756 [myid:] - INFO  [main:Environment@98] - Client environment:=3.6.2--803c7f1a12f85978cb049af5e4ef23bd8b688715, built on 09/04/2020 12:44 GMT
2021-02-05 13:44:30,758 [myid:] - INFO  [main:Environment@98] - Client environment:=
2021-02-05 13:44:30,758 [myid:] - INFO  [main:Environment@98] - Client environment:=1.8.0_242
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=Oracle Corporation
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-1.el7.x86_64/jre
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/target/classes:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../build/classes:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/target/lib/*.jar:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../build/lib/*.jar:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-prometheus-metrics-3.6.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-jute-3.6.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-3.6.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/snappy-java-1.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/slf4j-log4j12-1.7.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/slf4j-api-1.7.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_servlet-0.6.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_hotspot-0.6.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_common-0.6.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient-0.6.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-native-unix-common-4.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-native-epoll-4.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-4.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/netty-resolver-4.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/netty-handler-4.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/netty-common-4.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/netty-codec-4.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/netty-buffer-4.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/metrics-core-3.2.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/log4j-1.2.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/json-simple-1.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jline-2.14.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-util-9.4.24.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-servlet-9.4.24.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-server-9.4.24.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-security-9.4.24.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-io-9.4.24.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-http-9.4.24.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/-api-3.1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-databind-2.10.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-core-2.10.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-annotations-2.10.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/commons-lang-2.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/commons-cli-1.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../lib/audience-annotations-0.5.:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../zookeeper-*.jar:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/usr/local/src/program/apache-zookeeper-3.6.2-bin/bin/../conf:
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=/tmp
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=<NA>
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=Linux
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=amd64
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=3.10.0-1127.el7.x86_64
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=root
2021-02-05 13:44:30,760 [myid:] - INFO  [main:Environment@98] - Client environment:=/root
2021-02-05 13:44:30,761 [myid:] - INFO  [main:Environment@98] - Client environment:=/usr/local/src/program/apache-zookeeper-3.6.2-bin
2021-02-05 13:44:30,761 [myid:] - INFO  [main:Environment@98] - Client environment:=22MB
2021-02-05 13:44:30,761 [myid:] - INFO  [main:Environment@98] - Client environment:=228MB
2021-02-05 13:44:30,761 [myid:] - INFO  [main:Environment@98] - Client environment:=29MB
2021-02-05 13:44:30,764 [myid:] - INFO  [main:ZooKeeper@1006] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=$MyWatcher@379619aa
2021-02-05 13:44:30,766 [myid:] - INFO  [main:X509Util@77] - Setting -D =true to disable client-initiated TLS renegotiation
2021-02-05 13:44:30,770 [myid:] - INFO  [main:ClientCnxnSocket@239] -  value is 1048575 Bytes
2021-02-05 13:44:30,775 [myid:] - INFO  [main:ClientCnxn@1716] -  value is 0. feature enabled=false
2021-02-05 13:44:30,779 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1167] - Opening socket connection to server localhost/127.0.0.1:2181.
2021-02-05 13:44:30,779 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1169] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
JLine support is enabled
2021-02-05 13:44:30,848 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@999] - Socket connection established, initiating session, client: /127.0.0.1:39740, server: localhost/127.0.0.1:2181
2021-02-05 13:44:30,876 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1433] - Session establishment complete on server localhost/127.0.0.1:2181, session id = 0x1000079c0270000, negotiated timeout = 30000

WATCHER::

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

单机zk集群

1.复制zookeeper根目录,创建zookeeper1,zookeeper2,zookeeper3

2.修改对应的文件

dataDir=/usr/local/src/program/zookeeper3/data
dataLogDir=/usr/local/src/program/zookeeper3/logs
# the port at which the clients will connect
# 端口号修改
clientPort=2183
# 每个节点的文件中都要添加节点server地址
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883

3.分别启动每个节点