在Ubuntu上配置Kafka網絡參數涉及多個步驟,包括安裝必要的軟件、配置Kafka和Zookeeper、以及啟動服務。以下是一個詳細的指南:
Kafka需要Java運行環境,建議安裝JDK 1.8或更高版本??梢酝ㄟ^以下命令檢查Java是否已安裝:
java -version
wget https://downloads.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
tar -xzvf apache-zookeeper-3.7.0-bin.tar.gz
cd apache-zookeeper-3.7.0
mkdir /tmp/zookeeper
conf/zoo.cfg
文件:dataDir=/tmp/zookeeper
clientPort=2181
server.1 localhost:2888:3888
server.2 localhost:2889:3889
server.3 localhost:2890:3890
./bin/zkServer.sh start
wget https://downloads.apache.org/kafka/2.8.1/kafka_2.12-2.8.1.tgz
tar -xzvf kafka_2.12-2.8.1.tgz
cd kafka_2.12-2.8.1
mkdir /tmp/kafka
config/server.properties
文件:broker.id=0
listeners=PLAINTEXT://your_server_ip:9092
zookeeper.connect=localhost:2181
log.dirs=/tmp/kafka
./bin/zookeeper-server-start.sh config/zookeeper.properties
./bin/kafka-server-start.sh config/server.properties
對于Ubuntu 20.04 LTS及以上版本,使用Netplan工具管理網絡。編輯 /etc/netplan/01-netcfg.yaml
文件,將 dhcp4: yes
更改為 dhcp4: no
,并添加靜態IP地址、網關和DNS服務器:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [Your_Static_IP/Netmask]
gateway4: Your_Gateway_IP
nameservers:
addresses: [DNS_Server_IPs]
保存更改并應用配置:
sudo netplan apply
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
以上步驟應該能幫助你在Ubuntu上配置Kafka網絡。請根據你的具體需求和環境進行調整。