Centos7部署kafka+zookeeper三节点集群
Centos7部署kafka+zookeeper三节点集群
环境准备
1、准备JDK环境
yum install -y java-1.8.0
一、部署zookeeper三节点集群
1.1、下载zookeeper
#下载zookeeper
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
#解压
tar xf apache-zookeeper-3.7.0-bin.tar.gz
1.2、修改配置文件
#可以先将配置文件备份一份
# cp zoo_sample.cfg zoo.cfg
cd conf/
vim zoo.cfg
#zookeeper服务器之间或客户端与服务器之间维持心跳的间隔,每个tickTime时间发送一个心跳
tickTime=2000
#zookeeper客户端初始化连接时最长能忍受几个心跳间隔数
initLimit=10
#syncLimit这个配置项标识leader与follower之间发送消息,请求和应答时间长度,最长不能超过多少个tickTime的时间长度
syncLimit=5
#顾名思义就是zookeeper保存数据的目录,默认情况下zookeeper将写数据的日志文件也保存在这个目录里
dataDir=/data/server-data/zookeeper
# dataLogDir=/data/log/zookeeper 可以单独配置
#clientPort这个端口就是客户端连接Zookeeper服务器的端口,Zookeeper会监听这个端口接受客户端的访问请求
clientPort=2181
# server.[第几号服务器]=[服务器的ip地址]:[用来集群成员信息交换的端口,表示这个服务器与集群中的leader服务器交换信息的端口]:[在leader挂掉时专门用来进行选举leader所用的端口]
server.1=10.10.101.32:2888:3888
server.2=10.10.101.33:2888:3888
server.3=10.10.101.34:2888:3888
1.3、在datadir目录创建myid文件
#主节点
[root@test-k8s-master1 zookeeper]# cat myid
1
#从节点1
[root@test-k8s-master2 zookeeper]# cat myid
2
#从节点2
[root@test-k8s-master3 zookeeper]# cat myid
3
1.4、加入systemctl管理
vim /lib/systemd/system/zookeeper.service
[Unit]
Description=zookeeper.service
After=network.target
ConditionPathExists=/data/server-side/zookeeper/conf/zoo.cfg
[Service]
Type=forking
User=root
Group=root
ExecStart=/data/server-side/zookeeper/bin/zkServer.sh start
ExecStop=/data/server-side/zookeeper/bin/zkServer.sh stop
[Install]
WantedBy=multi-user.target
二、部署kafka三节点
2.1、下载kafka
wget https://mirrors.bfsu.edu.cn/apache/kafka/2.8.0/kafka_2.13-2.8.0.tgz
2.2、修改配置文件
vim config/server.properties
... ...
#三个节点要配置不同的值
broker.id 0
#zookeeper连接地址,多个以逗号隔开
#zookeeper.connect=[zookeeperIP]:[zookeeper端口],[zookeeperIP]:[zookeeper端口],[zookeeperIP]:[zookeeper端口]
zookeeper.connect=10.10.101.32:2181,10.10.101.33:2181,10.10.101.34:2181
... ...
2.3、加入systemctl管理
vim /lib/systemd/system/kafka.service
[Unit]
Description=Apache Kafka server (broker)
Documentation=http://kafka.apache.org/documentation.html
Requires=network.target
After=network.target zookeeper.service
[Service]
Type=simple
WorkingDirectory=/data/server-side/kafka
ExecStart=/data/server-side/kafka/bin/kafka-server-start.sh config/server.properties
ExecStop=/data/server-side/kafka/bin/kafka-server-stop.sh config/server.properties
Restart=on-failure
[Install]
WantedBy=multi-user.target
三、部署kafak manager
kafka manager 是kafka的web管理工具
3.1、下载编译好的文件
kafka-manager-2.0.0.0.zip
unzip kafka-manager-2.0.0.0.zip
3.2、修改配置文件
vim conf/application.conf
修改配置:
kafka-manager.zkhosts=[zk_ip1:zk_port1,zk_ip2:zk_port2,zk_ip3:zk_port3]
添加配置:
http.port= (默认9000)
3.3、查看kafka读取
#想要看到读取,写入速度需要开启JMX,修改kafka-server-start.sh 添加一行即可:添加JMX端口8999
if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
export JMX_PORT="8999"
fi
3.4、启动kafka manager
nohup ./kafka-manager -Dconfig.file=/data/server-side/kafka-manager/conf/application.conf >/dev/null 2>&1 &
3.5、网页浏览
[IP:9000]