首先要安装JDK及zookeeper,参考 https://www.cnblogs.com/dotqin/p/13560419.html 及 https://www.cnblogs.com/dotqin/p/13560764.html
环境说明:三台百度云服务器,内网IP分别为: 192.168.32.36、192.168.32.37、192.168.32.38, 不开放公网IP访问
分别在三台服务器上执行以下操作:
1.创建目录及下载解压(下载速度很慢)
mkdir /usr/local/kafka cd /usr/local/kafka/ wget https://archive.apache.org/dist/kafka/1.0.0/kafka_2.11-1.0.0.tgz tar -zxvf kafka_2.11-1.0.0.tgz
2.编辑配置文件(三台不一样)
vim /usr/local/kafka/kafka_2.11-1.0.0/config/server.properties # 修改或替换以下内容 broker.id=0 # 三台服务器分别对应 0 1 2 listeners=PLAINTEXT://192.168.32.36:9092 # 分别对应服务器的内网IP advertised.listeners=PLAINTEXT://192.168.32.36:9092 # 分别对应服务器的内网IP (这个设置是有关公网访问的,这里不开放公网请求) # 以下配置三台一样
log.dirs=/tmp/kafka-logs zookeeper.connect=192.168.32.36:2181,192.168.32.37:2181,192.168.32.38:2181/kafka zookeeper.connection.timeout.ms=6000
3.添加到服务管理
vim /usr/lib/systemd/system/kafka.service # 添加以下内容 [Unit] Description=kafka_2.11-1.0.0 service After=syslog.target network.target zookeeper.service [Service]
Restart=always
RestartSec=1 Type=forking TimeoutSec=120 User=root Environment=JAVA_HOME=/usr/local/java/jdk1.8.0_261 ExecStart=/usr/local/kafka/kafka_2.11-1.0.0/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka_2.11-1.0.0/config/server.properties ExecStop=/usr/local/kafka/kafka_2.11-1.0.0/bin/kafka-server-stop.sh /usr/local/kafka/kafka_2.11-1.0.0/config/server.properties [Install] WantedBy=multi-user.target
4.设置服务生效及开机自启动
systemctl daemon-reload
systemctl enable kafka.service
5.启动kafka
systemctl start kafka
systemctl status kafka