zookeeper学习(一) Standalone模式(单机模式)安装

安装准备

  • centos7环境
  • jdk1.8环境
  • zookeeper安装包

安装jdk

  • 上传jdk安装包
  • 解压安装包到目录中
tar -zxvf jdk-8u361-linux-x64.tar.gz

如果需要指定目录可以在后面加上 -C,如

tar -zxvf jdk-8u361-linux-x64.tar.gz -C  目录

配置jdk环境变量

vim /etc/profile

打开这个文件之后,按 i 进入到编辑模式,然后找到

 export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTRO 

这句话,之后另起一行,根据刚刚下载的的 JDK 版本添加以下内容:

export JAVA_HOME=/usr/java/jdk1.8.0_361
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH

保存退出后,刷新配置文件,执行命令

source /etc/profile

使用java -version 判断是否安装成功

[root@VM-16-11-centos jdk1.8.0_361]# java -version
java version "1.8.0_361"
Java(TM) SE Runtime Environment (build 1.8.0_361-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)

安装zookeeper

  • 解压zookeeper压缩包
  • 进入解压后的目录,类似于这样
[root@VM-16-11-centos zookeeper-3.4.6]# pwd
/opt/soft/zookeeper-3.4.6
[root@VM-16-11-centos zookeeper-3.4.6]# ll
total 1556
drwxr-xr-x  2 lighthouse lighthouse    4096 Jul 24 10:28 bin
-rw-rw-r--  1 lighthouse lighthouse   82446 Feb 20  2014 build.xml
-rw-rw-r--  1 lighthouse lighthouse   80776 Feb 20  2014 CHANGES.txt
drwxr-xr-x  2 lighthouse lighthouse    4096 Jul 24 10:27 conf
drwxr-xr-x 10 lighthouse lighthouse    4096 Feb 20  2014 contrib
drwxr-xr-x  2 lighthouse lighthouse    4096 Feb 20  2014 dist-maven
drwxr-xr-x  6 lighthouse lighthouse    4096 Feb 20  2014 docs
-rw-rw-r--  1 lighthouse lighthouse    1953 Feb 20  2014 ivysettings.xml
-rw-rw-r--  1 lighthouse lighthouse    3375 Feb 20  2014 ivy.xml
drwxr-xr-x  4 lighthouse lighthouse    4096 Feb 20  2014 lib
-rw-rw-r--  1 lighthouse lighthouse   11358 Feb 20  2014 LICENSE.txt
-rw-rw-r--  1 lighthouse lighthouse     170 Feb 20  2014 NOTICE.txt
-rw-rw-r--  1 lighthouse lighthouse    1770 Feb 20  2014 README_packaging.txt
-rw-rw-r--  1 lighthouse lighthouse    1585 Feb 20  2014 README.txt
drwxr-xr-x  5 lighthouse lighthouse    4096 Feb 20  2014 recipes
drwxr-xr-x  8 lighthouse lighthouse    4096 Feb 20  2014 src
drwxr-xr-x  3 root       root          4096 Jul 24 10:39 zkData
-rw-rw-r--  1 lighthouse lighthouse 1340305 Feb 20  2014 zookeeper-3.4.6.jar
-rw-rw-r--  1 lighthouse lighthouse     836 Feb 20  2014 zookeeper-3.4.6.jar.asc
-rw-rw-r--  1 lighthouse lighthouse      33 Feb 20  2014 zookeeper-3.4.6.jar.md5
-rw-rw-r--  1 lighthouse lighthouse      41 Feb 20  2014 zookeeper-3.4.6.jar.sha1
  • 新建zkData目录
mkdir zkData
  • 进入conf目录
 cp zoo_sample.cfg ./zoo.cfg
  • 修改zoo.cfg中的dataDir的路径为刚刚建立的zkData路径
[root@VM-16-11-centos conf]# cat 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=/opt/soft/zookeeper-3.4.6/zkData
# 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

启动zookeeper

  • 进入bin目录
./zkServer.sh start
  • 查看状态
./zkServer.sh status
[root@VM-16-11-centos bin]# ./zkServer.sh status
JMX enabled by default
Using config: /opt/soft/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
  • 单机模式安装成功

连接zookeeper服务

  • ./zkCli.sh -server localhost:2181

[root@VM-16-11-centos bin]# ./zkCli.sh -server localhost:2181
Connecting to localhost:2181 2023-07-24 11:09:18,759 [myid:] - INFO
[main:Environment@100] - Client
environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09
GMT 2023-07-24 11:09:18,763 [myid:] - INFO [main:Environment@100] -
Client environment:host.name=VM-16-11-centos 2023-07-24 11:09:18,763
[myid:] - INFO [main:Environment@100] - Client
environment:java.version=1.8.0_361 2023-07-24 11:09:18,765 [myid:] -
INFO [main:Environment@100] - Client environment:java.vendor=Oracle
Corporation 2023-07-24 11:09:18,765 [myid:] - INFO
[main:Environment@100] - Client
environment:java.home=/opt/soft/java/jdk1.8.0_361/jre 2023-07-24
11:09:18,765 [myid:] - INFO [main:Environment@100] - Client
environment:java.class.path=/opt/soft/zookeeper-3.4.6/bin/…/build/classes:/opt/soft/zookeeper-3.4.6/bin/…/build/lib/.jar:/opt/soft/zookeeper-3.4.6/bin/…/lib/slf4j-log4j12-1.6.1.jar:/opt/soft/zookeeper-3.4.6/bin/…/lib/slf4j-api-1.6.1.jar:/opt/soft/zookeeper-3.4.6/bin/…/lib/netty-3.7.0.Final.jar:/opt/soft/zookeeper-3.4.6/bin/…/lib/log4j-1.2.16.jar:/opt/soft/zookeeper-3.4.6/bin/…/lib/jline-0.9.94.jar:/opt/soft/zookeeper-3.4.6/bin/…/zookeeper-3.4.6.jar:/opt/soft/zookeeper-3.4.6/bin/…/src/java/lib/.jar:/opt/soft/zookeeper-3.4.6/bin/…/conf:/opt/soft/java/jdk1.8.0_361/lib/tools.jar:/opt/soft/java/jdk1.8.0_361/lib/dt.jar:/opt/soft/java/jdk1.8.0_361/lib
2023-07-24 11:09:18,765 [myid:] - INFO [main:Environment@100] -
Client
environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2023-07-24 11:09:18,765 [myid:] - INFO [main:Environment@100] -
Client environment:java.io.tmpdir=/tmp 2023-07-24 11:09:18,765 [myid:]

  • INFO [main:Environment@100] - Client environment:java.compiler= 2023-07-24 11:09:18,765 [myid:] - INFO [main:Environment@100] -
    Client environment:os.name=Linux 2023-07-24 11:09:18,765 [myid:] -
    INFO [main:Environment@100] - Client environment:os.arch=amd64
    2023-07-24 11:09:18,765 [myid:] - INFO [main:Environment@100] -
    Client environment:os.version=3.10.0-1160.71.1.el7.x86_64 2023-07-24
    11:09:18,765 [myid:] - INFO [main:Environment@100] - Client
    environment:user.name=root 2023-07-24 11:09:18,765 [myid:] - INFO
    [main:Environment@100] - Client environment:user.home=/root 2023-07-24
    11:09:18,765 [myid:] - INFO [main:Environment@100] - Client
    environment:user.dir=/opt/soft/zookeeper-3.4.6/bin 2023-07-24
    11:09:18,767 [myid:] - INFO [main:ZooKeeper@438] - Initiating client
    connection, connectString=localhost:2181 sessionTimeout=30000
    watcher=org.apache.zookeeper.ZooKeeperMain M y W a t c h e r @ 421 f a a b 12023 − 07 − 2411 : 09 : 18 , 790 [ m y i d : ] − I N F O [ m a i n − S e n d T h r e a d ( V M − 16 − 11 − c e n t o s : 2181 ) : C l i e n t C n x n MyWatcher@421faab1 2023-07-24 11:09:18,790 [myid:] - INFO [main-SendThread(VM-16-11-centos:2181):ClientCnxn MyWatcher@421faab12023072411:09:18,790[myid:]INFO[mainSendThread(VM1611centos:2181):ClientCnxnSendThread@975] -
    Opening socket connection to server
    VM-16-11-centos/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate
    using SASL (unknown error) Welcome to ZooKeeper! 2023-07-24
    11:09:18,799 [myid:] - INFO
    [main-SendThread(VM-16-11-centos:2181):ClientCnxn S e n d T h r e a d @ 852 ] − S o c k e t c o n n e c t i o n e s t a b l i s h e d t o V M − 16 − 11 − c e n t o s / 0 : 0 : 0 : 0 : 0 : 0 : 0 : 1 : 2181 , i n i t i a t i n g s e s s i o n J L i n e s u p p o r t i s e n a b l e d 2023 − 07 − 2411 : 09 : 18 , 833 [ m y i d : ] − I N F O [ m a i n − S e n d T h r e a d ( V M − 16 − 11 − c e n t o s : 2181 ) : C l i e n t C n x n SendThread@852] - Socket connection established to VM-16-11-centos/0:0:0:0:0:0:0:1:2181, initiating session JLine support is enabled 2023-07-24 11:09:18,833 [myid:] - INFO [main-SendThread(VM-16-11-centos:2181):ClientCnxn SendThread@852]SocketconnectionestablishedtoVM1611centos/0:0:0:0:0:0:0:1:2181,initiatingsessionJLinesupportisenabled2023072411:09:18,833[myid:]INFO[mainSendThread(VM1611centos:2181):ClientCnxnSendThread@1235] -
    Session establishment complete on server
    VM-16-11-centos/0:0:0:0:0:0:0:1:2181, sessionid = 0x18985c433c10000,
    negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null [zk:

  • 查看根节点
[zk: localhost:2181(CONNECTED) 1] ls /
[zookeeper]

你可能感兴趣的:(zookeeper,学习,linux,centos)