Zookeeper安装及使用

Windows下安装

下载并安装

  • zookeeper官网找到最新的稳定版本tar.gz
    在这里插入图片描述
  • 解压到本地,并在根目录创建一个data文件夹
    在这里插入图片描述

修改配置

  • 进入conf目录中,将zoo_sample.cfg修改为zoo.cfgzoo.cfg是zookeeper的配置文件。
  • 修改配置,将用于存储内存数据库快照文件dataDir指定到刚才创建的data目录,注意windows下的路径分隔符为/,修改后的zoo.cfg如下
    # 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=F:/DevResource/apache-zookeeper-3.7.1-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
    
    ## Metrics Providers
    #
    # https://prometheus.io Metrics Exporter
    #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
    #metricsProvider.httpPort=7000
    #metricsProvider.exportJvmInfo=true
    

    启动服务器(单机版)

    • bin目录下执行zkServer.cmd
      在这里插入图片描述
      启动成功!

启动异常

问题1:端口占用
2022-08-30 17:29:44,107 [myid:] - INFO [main:Environment@98] - Server environment:java.io.tmpdir=C:\Users\hucong\AppData\Local\Temp\ 2022-08-30 17:29:44,107 [myid:] - INFO [main:Environment@98] - Server environment:java.compiler=<NA> 2022-08-30 17:29:44,108 [myid:] - INFO [main:Environment@98] - Server environment:os.name=Windows 10 2022-08-30 17:29:44,108 [myid:] - INFO [main:Environment@98] - Server environment:os.arch=amd64 2022-08-30 17:29:44,109 [myid:] - INFO [main:Environment@98] - Server environment:os.version=10.0 2022-08-30 17:29:44,109 [myid:] - INFO [main:Environment@98] - Server environment:user.name=hucong 2022-08-30 17:29:44,109 [myid:] - INFO [main:Environment@98] - Server environment:user.home=C:\Users\hucong 2022-08-30 17:29:44,110 [myid:] - INFO [main:Environment@98] - Server environment:user.dir=F:\DevResource\apache-zookeeper-3.7.1-bin\bin 2022-08-30 17:29:44,110 [myid:] - INFO [main:Environment@98] - Server environment:os.memory.free=196MB 2022-08-30 17:29:44,110 [myid:] - INFO [main:Environment@98] - Server environment:os.memory.max=3156MB 2022-08-30 17:29:44,111 [myid:] - INFO [main:Environment@98] - Server environment:os.memory.total=213MB 2022-08-30 17:29:44,111 [myid:] - INFO [main:ZooKeeperServer@138] - zookeeper.enableEagerACLCheck = false 2022-08-30 17:29:44,112 [myid:] - INFO [main:ZooKeeperServer@151] - zookeeper.digest.enabled = true 2022-08-30 17:29:44,112 [myid:] - INFO [main:ZooKeeperServer@155] - zookeeper.closeSessionTxn.enabled = true 2022-08-30 17:29:44,113 [myid:] - INFO [main:ZooKeeperServer@1505] - zookeeper.flushDelay=0 2022-08-30 17:29:44,113 [myid:] - INFO [main:ZooKeeperServer@1514] - zookeeper.maxWriteQueuePollTime=0 2022-08-30 17:29:44,113 [myid:] - INFO [main:ZooKeeperServer@1523] - zookeeper.maxBatchSize=1000 2022-08-30 17:29:44,114 [myid:] - INFO [main:ZooKeeperServer@260] - zookeeper.intBufferStartingSizeBytes = 1024 2022-08-30 17:29:44,115 [myid:] - INFO [main:BlueThrottle@141] - Weighed connection throttling is disabled 2022-08-30 17:29:44,116 [myid:] - INFO [main:ZooKeeperServer@1306] - minSessionTimeout set to 4000 2022-08-30 17:29:44,121 [myid:] - INFO [main:ZooKeeperServer@1315] - maxSessionTimeout set to 40000 2022-08-30 17:29:44,122 [myid:] - INFO [main:ResponseCache@45] - getData response cache size is initialized with value 400. 2022-08-30 17:29:44,122 [myid:] - INFO [main:ResponseCache@45] - getChildren response cache size is initialized with value 400. 2022-08-30 17:29:44,123 [myid:] - INFO [main:RequestPathMetricsCollector@109] - zookeeper.pathStats.slotCapacity = 60 2022-08-30 17:29:44,123 [myid:] - INFO [main:RequestPathMetricsCollector@110] - zookeeper.pathStats.slotDuration = 15 2022-08-30 17:29:44,124 [myid:] - INFO [main:RequestPathMetricsCollector@111] - zookeeper.pathStats.maxDepth = 6 2022-08-30 17:29:44,124 [myid:] - INFO [main:RequestPathMetricsCollector@112] - zookeeper.pathStats.initialDelay = 5 2022-08-30 17:29:44,125 [myid:] - INFO [main:RequestPathMetricsCollector@113] - zookeeper.pathStats.delay = 5 2022-08-30 17:29:44,125 [myid:] - INFO [main:RequestPathMetricsCollector@114] - zookeeper.pathStats.enabled = false 2022-08-30 17:29:44,128 [myid:] - INFO [main:ZooKeeperServer@1542] - The max bytes for all large requests are set to 104857600 2022-08-30 17:29:44,129 [myid:] - INFO [main:ZooKeeperServer@1556] - The large request threshold is set to -1 2022-08-30 17:29:44,129 [myid:] - INFO [main:AuthenticationHelper@66] - zookeeper.enforce.auth.enabled = false 2022-08-30 17:29:44,130 [myid:] - INFO [main:AuthenticationHelper@67] - zookeeper.enforce.auth.schemes = [] 2022-08-30 17:29:44,130 [myid:] - INFO [main:ZooKeeperServer@361] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 clientPortListenBacklog -1 datadir F:\DevResource\apache-zookeeper-3.7.1-bin\data\version-2 snapdir F:\DevResource\apache-zookeeper-3.7.1-bin\data\version-2 2022-08-30 17:29:44,162 [myid:] - INFO [main:Log@170] - Logging initialized @321ms to org.eclipse.jetty.util.log.Slf4jLog 2022-08-30 17:29:44,219 [myid:] - WARN [main:ContextHandler@1656] - o.e.j.s.ServletContextHandler@56ac3a89{/,null,STOPPED} contextPath ends with /* 2022-08-30 17:29:44,219 [myid:] - WARN [main:ContextHandler@1667] - Empty contextPath 2022-08-30 17:29:44,233 [myid:] - INFO [main:Server@375] - jetty-9.4.43.v20210629; built: 2021-06-30T11:07:22.254Z; git: 526006ecfa3af7f1a27ef3a288e2bef7ea9dd7e8; jvm 1.8.0_181-b13 2022-08-30 17:29:44,256 [myid:] - INFO [main:DefaultSessionIdManager@334] - DefaultSessionIdManager workerName=node0 2022-08-30 17:29:44,257 [myid:] - INFO [main:DefaultSessionIdManager@339] - No SessionScavenger set, using defaults 2022-08-30 17:29:44,258 [myid:] - INFO [main:HouseKeeper@132] - node0 Scavenging every 660000ms 2022-08-30 17:29:44,261 [myid:] - WARN [main:ConstraintSecurityHandler@759] - ServletContext@o.e.j.s.ServletContextHandler@56ac3a89{/,null,STARTING} has uncovered http methods for path: /* 2022-08-30 17:29:44,269 [myid:] - INFO [main:ContextHandler@915] - Started o.e.j.s.ServletContextHandler@56ac3a89{/,null,AVAILABLE} 2022-08-30 17:29:44,274 [myid:] - ERROR [main:ZooKeeperServerMain@86] - Unable to start AdminServer, exiting abnormally org.apache.zookeeper.server.admin.AdminServer$AdminServerException: Problem starting AdminServer on address 0.0.0.0, port 8080 and command URL /commands at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:188) at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:155) at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:113) at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:68) at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:141) at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:91) Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8080 at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:310) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:234) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73) at org.eclipse.jetty.server.Server.doStart(Server.java:401) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73) at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:179) ... 5 more Caused by: java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:433) at sun.nio.ch.Net.bind(Net.java:425) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344) ... 12 more Unable to start AdminServer, exiting abnormally 2022-08-30 17:29:44,282 [myid:] - INFO [main:ZKAuditProvider@42] - ZooKeeper audit is disabled. 2022-08-30 17:29:44,283 [myid:] - ERROR [main:ServiceUtils@48] - Exiting JVM with code 4
参考:Windows下启动Zookeeper闪退 解决方案

参考
1.在Windows系统上安装zookeeper
2.dubbo-admin安装以及dubbo-admin简单使用

Linux下安装zookeeper

1.配置jdk环境

2.下载安装zookeeper

  • zookeeper官网找到最新的稳定版本tar.gz
    在这里插入图片描述

  • 拷贝至到/usr/local/下,并解压tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz
    ![在这里插入图片描述](https://img-blog.csdnimg.cn/c8527d91d73540ed99263df741ca61da.pn

    • 修改配置,进入conf文件夹,将zoo.sample.cfg复制并保存未zoo.cfg,执行cp zoo_sample.cfg zoo.cfg,将数据目录改到应用的data目录下,vim zoo.cfg在这里插入图片描述

启动

  • 进入zk的bin目录下,执行./zkServer.sh start
    在这里插入图片描述

(可选)运维

  1. 查看状态./zkServer.sh status
  • 在这里插入图片描述
  1. 查看进程ps -ef|grep zookeeper
    在这里插入图片描述
  2. 配置环境变量vim /etc/profile,增加以下配置,home以实际目录为准
#zookeeper 配置
ZOOKEEPER_HOME=/usr/local/apache-zookeeper-3.7.1-bin
PATH=$PATH:$ZOOKEEPER_HOME/bin
export PATH ZOOKEEPER_HOME PATH

在这里插入图片描述
配置生效source /etc/profile

  1. 配置开机自启
    编写service文件vi /usr/lib/systemd/system/zookeeper.service ,增加一下内容(以实际目录为准):
    [Unit]
    Description=zookeeper
    After=network.target remote-fs.target nss-lookup.target
    [Service]
    Type=forking
    ExecStart=/usr/local/apache-zookeeper-3.7.1-bin/bin/zkServer.sh start
    ExecReload=/usr/local/apache-zookeeper-3.7.1-bin/bin/zkServer.sh restart
    ExecStop=/usr/local/apache-zookeeper-3.7.1-bin/bin/zkServer.sh stop
    [Install]
    WantedBy=multi-user.target
    
    增加权限chmod 777 /usr/lib/systemd/system/zookeeper.service
    设置开启自启:
    # 设置自启
    systemctl enable zookeeper.service
    systemctl daemon-reload
    
    # 查看是否自启
    systemctl is-enabled zookeeper.service
    
    # 取消自启
    systemctl disable zookeeper.service
    systemctl daemon-reload
    

(可选)启动异常

1. 执行start报错

在这里插入图片描述

查看logs目录下的日志输出vim logs/zookeeper-root-server-xxxx.out
在这里插入图片描述
显示端口占用,修改zoo.cfg的zk端口即可,vim conf/zoo.cfg,增加admin.serverPort=8090指定端口号
在这里插入图片描述
![在这里插入图片描述](https://img-blog.csdnimg.cn/e284b33e9c6b43fe8341d22673eff11f.png
再次启动,启动成功!
在这里插入图片描述

  1. 其他异常
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值