linux安装zookeeper和kafka

        安装zookeeper和kafka之前,先检查是否安装java。如果没有,可以在如下链接中下载对应版本的jdk。

Java Downloads | Oracle

一、安装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

当然可以,下面是安装ZookeeperKafka的详细教程: 1. 安装Zookeeper: 1. 在终端中运行以下命令安装Zookeeper: ``` sudo apt update sudo apt install zookeeperd ``` 2. 安装完成后,Zookeeper将自动启动并在后台运行。 2. 配置Zookeeper: 1. 进入Zookeeper的配置目录: ``` cd /etc/zookeeper/conf ``` 2. 复制示例配置文件: ``` sudo cp zoo_sample.cfg zoo.cfg ``` 3. 使用文本编辑器(如nano或vim)打开配置文件: ``` sudo nano zoo.cfg ``` 4. 修改以下配置项: ``` dataDir=/var/lib/zookeeper ``` 5. 保存并关闭文件。 3. 启动Zookeeper: 1. 在终端中运行以下命令启动Zookeeper服务: ``` sudo systemctl start zookeeper ``` 2. 检查Zookeeper的状态: ``` sudo systemctl status zookeeper ``` 如果状态显示为"active (running)",则表示Zookeeper已成功启动。 4. 安装Kafka: 1. 在终端中运行以下命令安装Kafka: ``` sudo apt update sudo apt install kafka ``` 2. 安装完成后,Kafka将自动启动并在后台运行。 5. 配置Kafka: 1. 进入Kafka的配置目录: ``` cd /etc/kafka ``` 2. 使用文本编辑器(如nano或vim)打开配置文件: ``` sudo nano server.properties ``` 3. 修改以下配置项: ``` listeners=PLAINTEXT://localhost:9092 advertised.listeners=PLAINTEXT://your_server_ip:9092 ``` 将"your_server_ip"替换为你的服务器IP地址。 4. 保存并关闭文件。 6. 启动Kafka: 1. 在终端中运行以下命令启动Kafka服务: ``` sudo systemctl start kafka ``` 2. 检查Kafka的状态: ``` sudo systemctl status kafka ``` 如果状态显示为"active (running)",则表示Kafka已成功启动。 现在你已经成功安装和配置了ZookeeperKafka。你可以继续进行Kafka的使用和相关开发。如果需要更多详细的配置和使用信息,请参考官方文档或其他教程。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值