零、关于为什么选择这个版本
因为从官网的信息上来看,目前elk 7.10.0最新也才支持2.2.2
一、上传安装包
上传安装包至/usr/local/目录下
二、部署jdk
从官网上来看,需要java11及以上版本
部署脚本参考本文集中(搭建ES集群)一文
三、部署脚本(两个kafka,注意修改id)
#!/bin/bash
kafkaVersion=2.12-2.2.2
#zookeeper
zookeeperID=1
zookeeperPath=/etc/kafka/kafka_$kafkaVersion/config/zookeeper.properties
#kafka
kafkaPath=/etc/kafka/kafka_$kafkaVersion/config/server.properties
brokerID=1
listeners=192.168.18.15:9092
zookeepersConnect=192.168.18.15:2181,192.168.18.16:2181
#解压kafka
mkdir /etc/kafka && mkdir /etc/kafka/logs
tar -xzvf /usr/local/kafka_$kafkaVersion.tgz -C /etc/kafka/
cd /etc/kafka/
mkdir -p /etc/kafka/zookeeper/{data,logs}
#备份配置
cp /etc/kafka/kafka_$kafkaVersion/config/server.properties{,.bak}
cp /etc/kafka/kafka_$kafkaVersion/config/zookeeper.properties{,.bak}
#配置zookeeper
cp
echo $zookeeperID >> /etc/kafka/zookeeper/data/myid
sed -i "s#dataDir=/tmp/zookeeper#dataDir=/etc/kafka/zookeeper/data/#" $zookeeperPath
echo "dataLogDir=/etc/kafka/zookeeper/logs" >> $zookeeperPath
sed -i "s/maxClientCnxns=0/maxClientCnxns=20/" $zookeeperPath
echo "tickTime=2000" >> $zookeeperPath
echo "initLimit=10" >> $zookeeperPath
echo "syncLimit=5" >> $zookeeperPath
echo "server.1=192.168.18.15:2888:3888" >> $zookeeperPath
echo "server.2=192.168.18.16:2888:3888" >> $zookeeperPath
echo "zookeeper配置内容"
cat $zookeeperPath | grep "^[a-z]"
#配置kafka
sed -i "s/^broker.id=0/broker.id=$brokerID/" $kafkaPath
echo "listeners=PLAINTEXT://$listeners" >> $kafkaPath
sed -i "s#log.dirs=/tmp/kafka-logs#log.dirs=/etc/kafka/logs#" $kafkaPath
sed -i "s#zookeeper.connect=localhost:2181#zookeeper.connect=$zookeepersConnect#" $kafkaPath
sed -i "s/zookeeper.connection.timeout.ms=18000/zookeeper.connection.timeout.ms=6000/" $kafkaPath
echo "kafka配置内容"
cat $kafkaPath | grep "^[a-z]"
#配置zookeeper服务
cat > /usr/lib/systemd/system/zookeeper.service << "EOF"
[Unit]
Description=zookeeper service
After=network.target
[Service]
Type=simple
PIDFile=/var/run/zookeeper.pid
ExecStart=/etc/kafka/kafka_2.12-2.2.2/bin/zookeeper-server-start.sh /etc/kafka/kafka_2.12-2.2.2/config/zookeeper.properties
ExecStop=/etc/kafka/kafka_2.12-2.2.2/bin/zookeeper-server-stop.sh
[Install]
WantedBy=multi-user.target
EOF
#配置kafka服务
cat > /usr/lib/systemd/system/kafka.service << "EOF"
[Unit]
Description=Kafka service
After=network.target zookeeper.service
[Service]
Type=simple
PIDFile=/var/run/kafka.pid
ExecStart=/etc/kafka/kafka_2.12-2.2.2/bin/kafka-server-start.sh /etc/kafka/kafka_2.12-2.2.2/config/server.properties
ExecStop=/etc/kafka/kafka_2.12-2.2.2/bin/kafka-server-stop.sh
[Install]
WantedBy=multi-user.target
EOF
#刷新服务列表
systemctl daemon-reload
四、启动服务
systemctl strat zookeeper
systemctl strat kafka
五、验证zookeeper
yum install -y nc
echo status | nc localhost 2181
六、验证kafka
在bin目录下有相关工具脚本,可直接使用。
验证方法这里不做讲述。
网友评论