安装zookeeper和kafka之前,先检查是否安装java。如果没有,可以在如下链接中下载对应版本的jdk。
一、安装java
我这里下载的是jdk-8u271-linux-x64.tar.gz,操作如下:
[root@lucas src]# ll | grep jdk
-rw-r--r-- 1 root root 143142634 Dec 30 10:23 jdk-8u271-linux-x64.tar.gz
[root@lucas src]# tar -zxvf jdk-8u271-linux-x64.tar.gz
...
[root@lucas src]# ll | grep jdk
drwxr-xr-x 8 root root 4096 Sep 17 01:14 jdk1.8.0_271
-rw-r--r-- 1 root root 143142634 Dec 30 10:23 jdk-8u271-linux-x64.tar.gz
[root@lucas src]# mv jdk1.8.0_271 /usr/local/java
[root@lucas src]# cd /usr/local/
[root@lucas local]# ll | grep java
drwxr-xr-x 8 root root 4096 Sep 17 01:14 java
经过以上操作,java已经装好,下面就是在/etc/bashrc设置环境变量:
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
保存退出后,执行以下命令即可。
source /etc/bashrc
此时可查看java版本:
[root@lucas local]# java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
二、安装zookeeper
zookeeper可从该页面下载:Apache ZooKeeper
这里下载的是3.6.1_bin版本,操作如下:
[root@lucas src]# wget https://archive.apache.org/dist/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1-bin.tar.gz
[root@lucas src]# tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz
[root@lucas src]# mv ./apache-zookeeper-3.6.1-bin /usr/local/zookeeper
[root@lucas local]# cd /usr/local/zookeeper/
[root@lucas zookeeper]# mkdir data
[root@lucas zookeeper]# cd ./conf/
[root@lucas conf]# cp zoo_sample.cfg zoo.cfg
[root@ucas conf]# vim 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=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
将参数dataDir路径设置为/usr/local/zookeeper/data,保存退出。然后启动zookeeper:
[root@lucas conf]# cd ..
[root@lucas zookeeper]# ./bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
至此,zookeeper服务端启动成功。再启动客户端可看到如下响应:
[root@lucas zookeeper]# ./bin/zkCli.sh
Connecting to localhost:2181
2021-01-10 14:50:58,253 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.6.1--104dcb3e3fb464b30c5186d229e00af9f332524b, built on 04/21/2020 15:01 GMT
2021-01-10 14:50:58,258 [myid:] - INFO [main:Environment@98] - Client environment:host.name=lucas
2021-01-10 14:50:58,258 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_271
......
Welcome to ZooKeeper!
......
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
三、安装kafka
kafka可从该页面中下载:Index of /kafka
这里下载的版本是2.12-2.6.0。操作如下:
[root@lucas src]# tar -zxvf kafka_2.12-2.6.0.tgz
[root@lucas src]# mv ./kafka_2.12-2.6.0 /usr/local/kafka
[root@lucas src]# cd /usr/local/kafka
[root@lucas kafka]# ./bin/kafka-server-start.sh config/server.properties
[2021-01-10 15:03:36,495] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$)
[2021-01-10 15:03:37,315] INFO Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation (org.apache.zookeeper.common.X509Util)
[2021-01-10 15:03:37,422] INFO starting (kafka.server.KafkaServer)
[2021-01-10 15:03:37,423] INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)
[2021-01-10 15:03:37,451] INFO [ZooKeeperClient Kafka server] Initializing a new session to localhost:2181. (kafka.zookeeper.ZooKeeperClient)
.....
[2021-01-10 15:03:39,298] INFO [LogDirFailureHandler]: Starting (kafka.server.ReplicaManager$LogDirFailureHandler)
[2021-01-10 15:03:39,336] INFO Creating /brokers/ids/0 (is it secure? false) (kafka.zk.KafkaZkClient)
[2021-01-10 15:03:39,381] INFO Stat of the created znode at /brokers/ids/0 is: 28,28,1610262219353,1610262219353,1,0,0,73595441757552641,188,0,28
(kafka.zk.KafkaZkClient)
......
[2021-01-10 15:03:40,191] INFO Kafka version: 2.6.0 (org.apache.kafka.common.utils.AppInfoParser)
[2021-01-10 15:03:40,191] INFO Kafka commitId: 62abe01bee039651 (org.apache.kafka.common.utils.AppInfoParser)
[2021-01-10 15:03:40,191] INFO Kafka startTimeMs: 1610262220187 (org.apache.kafka.common.utils.AppInfoParser)
[2021-01-10 15:03:40,192] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
至此kafka服务端启动成功,可启动如下命令终止kafka服务:
[root@lucas kafka]# ./bin/kafka-server-stop.sh config/server.properties