- 安装jdk,如果已经安装过,跳过此步骤
- 下载zookeeper安装包
- 下载地址:https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1.tar.gz
- 解压
[root@rpp local]# tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz
- 编辑配置文件
- 进入conf目录:cd apache-zookeeper-3.6.1/conf/
- 将zoo_sample.cfg这个文件复制为zoo.cfg (必须是这个文件名)
[root@rpp conf]# cp zoo_sample.cfg zoo.cfg
- 编辑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,但是使用不同的端口。
- 在tmp目录创建目录
[root@rpp conf]# mkdir /tmp/zookeeper
[root@rpp conf]# mkdir /tmp/zookeeper/data
[root@rpp conf]# mkdir /tmp/zookeeper/log
- 如果是配置集群,还需要在前面配置过的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
- 配置环境变量
[root@rpp data]# export ZOOKEEPER_INSTALL=/usr/local/apache-zookeeper-3.6.1/
[root@rpp data]# export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
- 启动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
- 启动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
- 查看服务端状态:
[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