Linux安装zookeeper-3.6.1

  1. 安装jdk,如果已经安装过,跳过此步骤
  1. 下载zookeeper安装包
  • 下载地址:https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1.tar.gz
    在这里插入图片描述
  1. 解压
 [root@rpp local]# tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz
  1. 编辑配置文件
  1. 进入conf目录:cd apache-zookeeper-3.6.1/conf/
  2. 将zoo_sample.cfg这个文件复制为zoo.cfg (必须是这个文件名)
[root@rpp conf]# cp zoo_sample.cfg  zoo.cfg
  1. 编辑zoo.cfg,并修改如下内容
[root@rpp conf]# vim zoo.cfg
dataDir=/tmp/zookeeper/data
dataLogDir=/tmp/zookeeper/log
  • 注意:如果想配置集群的话,请在clientPort下面添加服务器的ip。如下,ip1,ip2,ip3请换成自己的真实ip
server.1=ip1:2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888
  • 如果就一台机器,zookeeper还可以设置成伪集群。也就是全部服务器采用同一个ip,但是使用不同的端口。
  1. 在tmp目录创建目录
[root@rpp conf]# mkdir /tmp/zookeeper
[root@rpp conf]# mkdir /tmp/zookeeper/data
[root@rpp conf]# mkdir /tmp/zookeeper/log
  1. 如果是配置集群,还需要在前面配置过的dataDir路径下新增myid文件
  • 在data目录下创建文件,文件名为“myid”, 编辑该“myid”文件,并在对应的IP的机器上输入对应的编号。
    如在192.168.180.132上,“myid”文件内容就是1。在192.168.180.133上,内容就是2。在192.168.180.134上,内容就是3。
[root@rpp conf]# cd /tmp/zookeeper/data
[root@rpp data]# touch myid
[root@rpp data]# vim myid
  1. 配置环境变量
  • 上面的操作都完事之后,我们需要配置一下环境变量,
[root@rpp data]# export ZOOKEEPER_INSTALL=/usr/local/apache-zookeeper-3.6.1/
[root@rpp data]# export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
  1. 启动zookeeper服务端,启动脚本在bin目录,启动效果如下
[root@rpp bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.6.1/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
  1. 启动zookeeper客户端
[root@rpp bin]# ./zkCli.sh
  • 启动成功效果如下
2020-07-26 20:12:24,919 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.6.1--104dcb3e3fb464b30c5186d229e00af9f332524b, built on 04/21/2020 15:01 GMT
2020-07-26 20:12:24,922 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=rpp
2020-07-26 20:12:24,922 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_101
2020-07-26 20:12:24,923 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2020-07-26 20:12:24,923 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/local/jdk1.8.0_101/jre
2020-07-26 20:12:24,923 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=/usr/local/apache-zookeeper-3.6.1/bin/../zookeeper-server/target/classes:/usr/local/apache-zookeeper-3.6.1/bin/../build/classes:/usr/local/apache-zookeeper-3.6.1/bin/../
......中间过程省略
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=3.10.0-957.21.3.el7.x86_64
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/usr/local/apache-zookeeper-3.6.1/bin
2020-07-26 20:12:24,924 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=50MB
2020-07-26 20:12:24,925 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=228MB
2020-07-26 20:12:24,925 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=56MB
2020-07-26 20:12:24,929 [myid:] - INFO  [main:ZooKeeper@1005] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@762efe5d
2020-07-26 20:12:24,932 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2020-07-26 20:12:24,937 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2020-07-26 20:12:24,943 [myid:] - INFO  [main:ClientCnxn@1703] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
JLine support is enabled
2020-07-26 20:12:24,964 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1154] - Opening socket connection to server localhost/127.0.0.1:2181.
2020-07-26 20:12:24,964 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1156] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2020-07-26 20:12:25,011 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@986] - Socket connection established, initiating session, client: /127.0.0.1:53610, server: localhost/127.0.0.1:2181
2020-07-26 20:12:25,039 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1420] - Session establishment complete on server localhost/127.0.0.1:2181, session id = 0x105b34ea78c0000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
  • 如果是连接多个不同的主机节点,可以使用如下命令:
[root@rpp bin]# ./zkCli.sh -server ipxxx:2888
  1. 查看服务端状态:
[root@rpp bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.6.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值