
安装包下载地址:https://zookeeper.apache.org/releases.html
以centos7 linux环境安装为例;
首先准备好linux 机器,可以使用虚拟机搭建,可参考 https://blog.csdn.net/weixin_45847167/article/details/121160467
我机器的ip:192.168.3.60
安装zookeeper 之前需要安装jdk,参考此篇文章 https://blog.csdn.net/weixin_45847167/article/details/121176936
以 apache-zookeeper-3.5.7-bin.tar.gz 安装包为例
解压安装包:tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz修改配置文件
[vagrant@localhost ~]$ cd apache-zookeeper-3.5.7-bin/conf/ [vagrant@localhost conf]$ ll total 12 -rw-r--r--. 1 vagrant vagrant 535 May 4 2018 configuration.xsl -rw-r--r--. 1 vagrant vagrant 2712 Feb 7 2020 log4j.properties -rw-r--r--. 1 vagrant vagrant 922 Feb 7 2020 zoo_sample.cfg
zoo_sample.cfg 文件是示例文件,我们复制一份,并修改名称:
[vagrant@localhost conf]$ cp zoo_sample.cfg zoo.cfg [vagrant@localhost conf]$ ll total 16 -rw-r--r--. 1 vagrant vagrant 535 May 4 2018 configuration.xsl -rw-r--r--. 1 vagrant vagrant 2712 Feb 7 2020 log4j.properties -rw-r--r--. 1 vagrant vagrant 922 Jan 8 08:19 zoo.cfg -rw-r--r--. 1 vagrant vagrant 922 Feb 7 2020 zoo_sample.cfg
修改配置文件:
vi zoo.cfg
只需修改 dataDir 的路径,默认/tmp 是临时路径,内容会被定时清理,比如我修改为/home/vagrant/apache-zookeeper-3.5.7-bin/data
可事先创建出来目录:
mkdir /home/vagrant/apache-zookeeper-3.5.7-bin/data
修改之后配置文件是这样的:
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/home/vagrant/apache-zookeeper-3.5.7-bin/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=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1配置参数解读
tickTime = 2000:通信心跳时间,Zookeeper服务器与客户端心跳时间,单位毫秒
initLimit = 10:LF初始通信时限
Leader和Follower初始连接时能容忍的最多心跳数(tickTime的数量)
syncLimit = 5:LF同步通信时限
Leader和Follower之间通信时间如果超过syncLimit * tickTime,Leader认为Follwer死掉,从服务器列表中删除Follwer。
dataDir:保存Zookeeper中的数据
注意:默认的tmp目录,容易被Linux系统定期删除,所以一般不用默认的tmp目录。
clientPort = 2181:客户端连接端口,通常不做修改。
启动zookeeper[vagrant@localhost ~]$ cd apache-zookeeper-3.5.7-bin/bin [vagrant@localhost bin]$ ll total 56 -rwxr-xr-x. 1 vagrant vagrant 232 May 4 2018 README.txt -rwxr-xr-x. 1 vagrant vagrant 2067 Feb 7 2020 zkCleanup.sh -rwxr-xr-x. 1 vagrant vagrant 1158 Feb 10 2020 zkCli.cmd -rwxr-xr-x. 1 vagrant vagrant 1621 Feb 7 2020 zkCli.sh -rwxr-xr-x. 1 vagrant vagrant 1766 Feb 7 2020 zkEnv.cmd -rwxr-xr-x. 1 vagrant vagrant 3690 Jan 31 2020 zkEnv.sh -rwxr-xr-x. 1 vagrant vagrant 1286 Jan 31 2020 zkServer.cmd -rwxr-xr-x. 1 vagrant vagrant 4573 Feb 7 2020 zkServer-initialize.sh -rwxr-xr-x. 1 vagrant vagrant 9386 Feb 7 2020 zkServer.sh -rwxr-xr-x. 1 vagrant vagrant 996 Oct 3 2019 zkTxnLogToolkit.cmd -rwxr-xr-x. 1 vagrant vagrant 1385 Feb 7 2020 zkTxnLogToolkit.sh [vagrant@localhost bin]$ ./zkServer.sh start ZooKeeper JMX enabled by default Using config: /home/vagrant/apache-zookeeper-3.5.7-bin/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [vagrant@localhost bin]$ ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /home/vagrant/apache-zookeeper-3.5.7-bin/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: standalone客户端连接
使用命令连接:
[vagrant@localhost bin]$ ./zkCli.sh Connecting to localhost:2181 2022-01-08 08:28:57,696 [myid:] - INFO [main:Environment@109] - Client environment:zookeeper.version=3.5.7-f0fdd52973d373ffd9c86b81d99842dc2c7f660e, built on 02/10/2020 11:30 GMT 2022-01-08 08:28:57,702 [myid:] - INFO [main:Environment@109] - Client environment:host.name=localhost 2022-01-08 08:28:57,702 [myid:] - INFO [main:Environment@109] - Client environment:java.version=11 2022-01-08 08:28:57,704 [myid:] - INFO [main:Environment@109] - Client environment:java.vendor=Oracle Corporation 2022-01-08 08:28:57,704 [myid:] - INFO [main:Environment@109] - Client environment:java.home=/home/vagrant/jdk-11 2022-01-08 08:28:57,704 [myid:] - INFO [main:Environment@109] - Client environment:java.class.path=/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../zookeeper-server/target/classes:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../build/classes:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../zookeeper-server/target/lib/*.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../build/lib/*.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/zookeeper-jute-3.5.7.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/zookeeper-3.5.7.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/slf4j-log4j12-1.7.25.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/slf4j-api-1.7.25.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/netty-transport-native-unix-common-4.1.45.Final.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/netty-transport-native-epoll-4.1.45.Final.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/netty-transport-4.1.45.Final.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/netty-resolver-4.1.45.Final.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/netty-handler-4.1.45.Final.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/netty-common-4.1.45.Final.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/netty-codec-4.1.45.Final.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/netty-buffer-4.1.45.Final.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/log4j-1.2.17.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/json-simple-1.1.1.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jline-2.11.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jetty-util-9.4.24.v20191120.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jetty-servlet-9.4.24.v20191120.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jetty-server-9.4.24.v20191120.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jetty-security-9.4.24.v20191120.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jetty-io-9.4.24.v20191120.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jetty-http-9.4.24.v20191120.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jackson-databind-2.9.10.2.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jackson-core-2.9.10.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/jackson-annotations-2.9.10.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/commons-cli-1.2.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../lib/audience-annotations-0.5.0.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../zookeeper-*.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/home/vagrant/apache-zookeeper-3.5.7-bin/bin/../conf:/home/vagrant/jdk-11/lib: 2022-01-08 08:28:57,705 [myid:] - INFO [main:Environment@109] - Client environment:java.library.path=/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib 2022-01-08 08:28:57,705 [myid:] - INFO [main:Environment@109] - Client environment:java.io.tmpdir=/tmp 2022-01-08 08:28:57,705 [myid:] - INFO [main:Environment@109] - Client environment:java.compiler=2022-01-08 08:28:57,705 [myid:] - INFO [main:Environment@109] - Client environment:os.name=Linux 2022-01-08 08:28:57,705 [myid:] - INFO [main:Environment@109] - Client environment:os.arch=amd64 2022-01-08 08:28:57,705 [myid:] - INFO [main:Environment@109] - Client environment:os.version=3.10.0-1127.el7.x86_64 2022-01-08 08:28:57,705 [myid:] - INFO [main:Environment@109] - Client environment:user.name=vagrant 2022-01-08 08:28:57,705 [myid:] - INFO [main:Environment@109] - Client environment:user.home=/home/vagrant 2022-01-08 08:28:57,706 [myid:] - INFO [main:Environment@109] - Client environment:user.dir=/home/vagrant/apache-zookeeper-3.5.7-bin/bin 2022-01-08 08:28:57,706 [myid:] - INFO [main:Environment@109] - Client environment:os.memory.free=5MB 2022-01-08 08:28:57,708 [myid:] - INFO [main:Environment@109] - Client environment:os.memory.max=247MB 2022-01-08 08:28:57,708 [myid:] - INFO [main:Environment@109] - Client environment:os.memory.total=7MB 2022-01-08 08:28:57,716 [myid:] - INFO [main:ZooKeeper@868] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@76329302 2022-01-08 08:28:57,721 [myid:] - INFO [main:X509Util@79] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation 2022-01-08 08:28:57,737 [myid:] - INFO [main:ClientCnxnSocket@237] - jute.maxbuffer value is 4194304 Bytes 2022-01-08 08:28:57,746 [myid:] - INFO [main:ClientCnxn@1653] - zookeeper.request.timeout value is 0. feature enabled= Welcome to ZooKeeper! JLine support is enabled 2022-01-08 08:28:57,828 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1112] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error) 2022-01-08 08:28:57,840 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@959] - Socket connection established, initiating session, client: /0:0:0:0:0:0:0:1:46530, server: localhost/0:0:0:0:0:0:0:1:2181 2022-01-08 08:28:57,903 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1394] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x100001149e10000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] ls / [zookeeper]
获取使用客户端工具连接:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)