一、安装 java8
yum install java-1.8.0-openjdk.x86_64 yum install java-1.8.0-openjdk-devel.x86_64
二、安装 Zookeeper
1. 下载zookeeper
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.5.9/apache-zookeeper-3.5.9-bin.tar.gz
2. 解压
tar -zxvf apache-zookeeper-3.5.9-bin.tar.gz
3. 移动重命名
mv apache-zookeeper-3.5.9-bin /usr/local/zookeeper
4. 进入conf文件夹,复制zoo_sample.cfg命名为zoo.cfg
cd /usr/local/zookeeper/conf/ cp zoo_sample.cfg zoo.cfg
5. 修改zoo.cfg中配置,改好后保存
vim zoo.cfg
dataDir=/data/zookeeper
dataLogDir=/data/log/zookeeper
6. 编辑 /etc/profile, 在文件末尾追加内容
vim /etc/profile
#zookeeper-3.5.9 config start export ZOOKEEPER_HOME=/usr/local/zookeeper export PATH=$ZOOKEEPER_HOME=/bin/$PATH export PATH #zookeeper-3.5.9 config end
7. 生效profile
source /etc/profile8. 启动zookeeper
cd /usr/local/zookeeper/bin/ # 启动zookeeper ./zkServer.sh start # 查看zookeeper状态 ./zkServer.sh status # 关闭zookeeper服务 ./zkServer.sh stop # 重启zookeeper服务 ./zkServer.sh restart
9. 设置服务和开机启动
添加到服务管理
vim /usr/lib/systemd/system/zookeeper.service
添加以下内容后,保存
[Unit] Description=zookeeper-3.5.9 After=syslog.target network.target [Service] Restart=alwaysRestartSec=1 Type=forking TimeoutSec=120 User=root ExecStart=/usr/local/zookeeper/bin/zkServer.sh start ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart Restart=always [Install] WantedBy=multi-user.target
生效服务及开机自启动
systemctl daemon-reload systemctl enable zookeeper.service
启动
# 启动 systemctl start zookeeper # 查看状态 systemctl status zookeeper # 停止 systemctl stop zookeeper
三、安装 kafka
1、下载
wget https://downloads.apache.org/kafka/3.3.1/kafka_2.13-3.3.1.tgz
2、解压
tar -zxvf kafka_2.13-3.3.1.tgz
3、移动重命名
mv kafka_2.13-3.3.1 /usr//local/kafka
4、配置KAFKA外网访问
cd /usr/local/kafka/config/ vim server.properties #放开注释 listeners=PLAINTEXT://:9092 #放开注释并修改 advertised.listeners=PLAINTEXT://172.17.0.3:9092
5、配置KAFKA log路径
vim server.properties log.dirs=/software/kafka/kafka-logs
6、配置zookeeper数据路径
#在目录下创建zookeeper文件夹用来存放数据 cd /usr/local/kafka mkdir zookeeper #打开config目录下的zookeeper.properties文件修改配置 cd /usr/local/kafka/config vim zookeeper.properties dataDir=/usr/local/kafka/zookeeper
7、启动KAFKA
cd /usr/local/kafka # 启动zookeeper bin/zookeeper-server-start.sh config/zookeeper.properties # 启动kafka bin/kafka-server-start.sh config/server.properties # 生产消息(创建名为testTopic的主题) bin/kafka-console-producer.sh --topic testTopic --bootstrap-server localhost:9092 # 监听消息(重开一个终端监听testTopic主题的消息,在生产消息的终端发消息,此终端收消息) bin/kafka-console-consumer.sh --topic testTopic --from-beginning --bootstrap-server localhost:9092
标签:bin,zookeeper,kafka,centos7,sh,usr,local,搭建 From: https://www.cnblogs.com/shenqilun/p/17030952.html