前言
本文适用于 Centos/Debian/Ubuntu 等 Linux 发行版系统。
安装 Oracle JDK
安装 Oracle JDK 不是必需的,如果不想安装可以使用 Open-JDK 替代,而且大多数 Linux 发行版自带 Open-JDK。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| # wget -P /usr/local --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3a%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk8-downloads-2133151.html; oraclelicense=accept-securebackup-cookie;" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk1.8.0_201-linux-x64.tar.gz"
# tar -xvf /usr/local/jdk1.8.0_201-linux-x64.tar.gz
# rm /usr/local/jdk1.8.0_201-linux-x64.tar.gz
# ln -s -f /usr/local/jdk1.8.0_201/bin/java /usr/bin/java # ln -s -f /usr/local/jdk1.8.0_201/bin/javac /usr/bin/javac
# vim /etc/profile JAVA_HOME=/usr/local/jdk1.8.0_201 JRE_HOME=/usr/local/jdk1.8.0_201/jre CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin export JAVA_HOME JRE_HOME CLASSPATH PATH
# source /etc/profile
# javac -version javac 1.8.0_201
# java -version java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
|
下载 ZooKeeper 压缩包
安装 ZooKeeper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| # mv zookeeper-3.4.13.tar.gz /usr/local
# cd /usr/local # tar -xvf zookeeper-3.4.13.tar.gz
# rm -rf zookeeper-3.4.13.tar.gz
# mkdir -p /usr/local/zookeeper-3.4.13/data # mkdir -p /usr/local/zookeeper-3.4.13/log
# cd /usr/local/zookeeper-3.4.13/conf # cp zoo_sample.cfg zoo.cfg
# vim zoo.cfg
tickTime=2000
clientPort=2181
dataDir=/usr/local/zookeeper-3.4.13/data
# vim log4j.properties
zookeeper.log.dir=/usr/local/zookeeper-3.4.13/log
# vim /etc/profile ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.13 PATH=$PATH:ZOOKEEPER_HOME/bin export ZOOKEEPER_HOME PATH
# source /etc/profile
|
ZooKeeper 服务管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # cd /usr/local/zookeeper-3.4.13/bin
|
客户端连接 ZooKeeper 服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| $ cd /usr/local/zookeeper-3.4.13/bin
$ ./zkCli.sh -server 127.0.0.1:2181
[zk: 127.0.0.1:2181(CONNECTED) 1] create -e /test-node 123456
[zk: 127.0.0.1:2181(CONNECTED) 2] ls / [test-node, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 3] get /test-node 123456 cZxid = 0x4 ctime = Fri Feb 22 02:27:43 UTC 2019 mZxid = 0x4 mtime = Fri Feb 22 02:27:43 UTC 2019 pZxid = 0x4 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x1000a766c5e0001 dataLength = 6 numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 4] quit
|