在linux上部署apache-zookeeper-3.8.1集群

一、介绍zookeeper

ZooKeeper 是一个集中式服务,用于维护配置信息、命名、提供分布式同步和提供组服务。被分布式应用所使用。

二、下载zookeeper

https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.8.3/apache-zookeeper-3.8.3-bin.tar.gz

三、单机启动zookeeper

3.1、在apache-zookeeper-3.8.1/conf下,复制一份zoo_sample.cfg,改名为zoo.cfg

3.2、修改zoo.cfg文件内容

# example sakes.
dataDir=/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
maxClientCnxns=6000

修改完成后,保存。在zookeeper的/bin下面启动zookeeper

./zkServer.sh start

3.3、启动zookeeper之后,就可以通过 ./zkCli.sh 进入zookeeper管理台

[root@node1 bin]# ./zkCli.sh 
Connecting to localhost:2181
2023-11-09 19:08:59,905 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:zookeeper.version=3.8.1-74db005175a4ec545697012f9069cb9dcc8cdda7, built on 2023-01-25 16:31 UTC
2023-11-09 19:08:59,907 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:host.name=node1
2023-11-09 19:08:59,907 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.version=1.8.0_391
2023-11-09 19:08:59,907 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.vendor=Oracle Corporation
2023-11-09 19:08:59,907 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.home=/usr/local/jdk1.8.0_391/jre
2023-11-09 19:08:59,907 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.class.path=/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../zookeeper-server/target/classes:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../build/classes:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../zookeeper-server/target/lib/*.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../build/lib/*.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/zookeeper-prometheus-metrics-3.8.1.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/zookeeper-jute-3.8.1.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/zookeeper-3.8.1.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/snappy-java-1.1.7.7.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/slf4j-api-1.7.30.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/simpleclient_servlet-0.9.0.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/simpleclient_hotspot-0.9.0.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/simpleclient_common-0.9.0.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/simpleclient-0.9.0.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-transport-native-unix-common-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-transport-native-epoll-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-transport-classes-epoll-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-transport-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-resolver-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-handler-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-common-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-codec-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/netty-buffer-4.1.86.Final.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/metrics-core-4.1.12.1.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/logback-core-1.2.10.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/logback-classic-1.2.10.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jline-2.14.6.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jetty-util-ajax-9.4.49.v20220914.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jetty-util-9.4.49.v20220914.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jetty-servlet-9.4.49.v20220914.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jetty-server-9.4.49.v20220914.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jetty-security-9.4.49.v20220914.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jetty-io-9.4.49.v20220914.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jetty-http-9.4.49.v20220914.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/javax.servlet-api-3.1.0.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jackson-databind-2.13.4.2.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jackson-core-2.13.4.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/jackson-annotations-2.13.4.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/commons-io-2.11.0.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/commons-cli-1.5.0.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../lib/audience-annotations-0.12.0.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../zookeeper-*.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../zookeeper-server/src/main/resources/lib/*.jar:/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../conf:.:/usr/local/jdk1.8.0_391/lib/dt.jar:/usr/local/jdk1.8.0_391/lib/tools.jar:/lib
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.io.tmpdir=/tmp
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.compiler=
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.name=Linux
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.arch=amd64
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.version=3.10.0-1160.el7.x86_64
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.name=root
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.home=/root
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.dir=/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.memory.free=46MB
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.memory.max=228MB
2023-11-09 19:08:59,908 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.memory.total=57MB
2023-11-09 19:08:59,911 [myid:] - INFO  [main:o.a.z.ZooKeeper@637] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7823a2f9
2023-11-09 19:08:59,915 [myid:] - INFO  [main:o.a.z.c.X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2023-11-09 19:08:59,919 [myid:] - INFO  [main:o.a.z.ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2023-11-09 19:08:59,924 [myid:] - INFO  [main:o.a.z.ClientCnxn@1741] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2023-11-09 19:08:59,927 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1177] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181.
2023-11-09 19:08:59,927 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1179] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2023-11-09 19:08:59,931 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1011] - Socket connection established, initiating session, client: /0:0:0:0:0:0:0:1:60862, server: localhost/0:0:0:0:0:0:0:1:2181
JLine support is enabled
2023-11-09 19:08:59,942 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1452] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, session id = 0x100006b71940003, negotiated timeout = 30000

WATCHER::

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

这样就可以启动单机版的zookeeper。 

四、zookeeper集群配置

4.1、修改 zoo.cfg 配置

dataDir=/usr/local/pulsar-cluster/apache-zookeeper-3.8.1/data
metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
metricsProvider.httpHost=0.0.0.0
metricsProvider.httpPort=7000
metricsProvider.exportJvmInfo=true

admin.enableServer=false

server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888

修改完成zoo.cfg配置后保存。并且把zookeeper拷贝到其他2台服务器节点上。

在每台服务器上的zookeeper的data目录下都创建myid,并且输入编号1,2,3等数字。

4.2、启动在zookeeper/bin目录下启动zookeeper。其他服务器也是一样启动

 ./zkServer.sh start

4.3、启动完成后的效果

[root@node1 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@node2 bin]# /usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader

 

[root@node3 bin]#  /usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/pulsar-cluster/apache-zookeeper-3.8.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

这样有一个主节点,两个从节点,zookeeper启动成功了

你可能感兴趣的:(JAVA知识,大数据,linux,zookeeper,运维)