单机kafka安装使用
将kafka和zookeeper安装包上传至/usr/local/目录下,解压,重命名
zookeeper安装
解压 tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz 重命名 mv apache-zookeeper-3.5.7-bin zookeeper
进入配置文件目录
cp zoo_sample.cfg zoo.cfg
创建zookeeper日志文件和数据文件目录
mkdir -p /data/zkdata/{dataDir,logDir}
编辑zookeeper配置文件
vi /usr/local/zookeeper/conf/zoo.cfg
配置zookeeper环境变量
vi /etc/profile
使环境变量生效
source /etc/profile
启动zookeeper服务
zkServer.sh start
启动zookeeper客户端
zkCli.sh
生成服务启动文件
vi /usr/lib/systemd/system/zookeeper.service
添加内容
[Unit]
Description=zookeeper
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
[Install]
WantedBy=multi-user.target
生效 systemctl daemon-reload 改变文件权限 chmod 777 /usr/lib/systemd/system/zookeeper.service systemctl开机启动zookeeper systemctl enable /usr/lib/systemd/system/zookeeper.service 或 systemctl enable /usr/lib/systemd/system/zookeeper 查看是否开机启动 systemctl is-enabled zookeeper.service systemctl取消开机启动zookeeper systemctl disable zookeeper.service 查看zookeeper 的进程数 启动状态命令 ps -aux | grep 'zookeeper' netstat -anp|grep 2181
kafka安装
解压 tar -zxvf kafka_2.13-2.5.0.tgz 重命名 mv kafka_2.13-2.5.0 kafka 编辑服务配置文件 vi kafka/config/server.properties
配置环境变量
vi /etc/profile
使环境变量生效 source /etc/profile 后台启动kafka nohup kafka-server-start.sh config/server.properties >> /dev/null &
查看服务
jps
创建test主题
bin/kafka-topics.sh --create --bootstrap-server 192.168.244.129:9092 --replication-factor 1 --partitions 1 --topic test
查看主题
bin/kafka-topics.sh --list --bootstrap-server 192.168.244.129:9092
启动生产者
bin/kafka-console-producer.sh --broker-list 192.168.244.129:9092 --topic test
启动消费者进行消费
kafka-console-consumer.sh --bootstrap-server 192.168.244.129:9092 --topic test --from-beginning