银河麒麟高级服务器操作系统V10 SP2安装kafka_2.12-2.3.1
目录
1.安装环境设置
1.1关闭Selinux
[root@Kylinv10 ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# ukmls - Multi Level Security protection.
# ukmcs -ukmcs variants of the SELinux policy.
#SELINUXTYPE=ukmcs
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0
将selinux配置文件中的“SELINUX=enforcing”更改为“SELINUX=disabled”并注释“#SELINUXTYPE=ukmcs”
[root@Kylinv10 ~]# setenforce 0
setenforce: SELinux is disabled #使配置立即生效
1.2打开防火墙9092端口
[root@Kylinv10 ~]# vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 9092 -j ACCEPT #增加9092端口放行规则
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 9092 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
[root@Kylinv10 ~]# systemctl restart iptables #重启防火墙
2.安装JDK8
[root@Kylinv10 /]# mkdir /soft
[root@Kylinv10 /]# mkdir -p /usr/local/jdk
[root@Kylinv10 /]# cd /soft
[root@Kylinv10 soft]# wget http://192.168.10.101/soft/jdk-8u241-linux-x64.tar.gz
[root@Kylinv10 soft]# tar -zxvf jdk-8u241-linux-x64.tar.gz
[root@Kylinv10 soft]# mv jdk1.8.0_241 /usr/local/jdk/jdk8
[root@Kylinv10 jdk8]# pwd
/usr/local/jdk/jdk8
[root@Kylinv10 jdk8]# vim /etc/profile #增加jdk环境变量
JAVA_HOME=/usr/local/jdk/jdk8
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
[root@Kylinv10 jdk8]# source !$ #立即生效
source /etc/profile
[root@Kylinv10 jdk8]# java -version #查看jdk版本
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
3.安装kafka
3.1下载安装文件
[root@Kylinv10 jdk8]# cd /soft/
[root@Kylinv10 soft]# wget http://192.168.10.101/soft/kafka_2.12-2.3.1.tgz
备注:可以到kafka的官网,去下载想用的kafka包:http://kafka.apache.org/downloads
[root@Kylinv10 soft]# tar -zxvf kafka_2.12-2.3.1.tgz
[root@Kylinv10 soft]# mkdir -p /usr/local/kafka/kafka_data
[root@Kylinv10 soft]# mv kafka_2.12-2.3.1 /usr/local/kafka/kafka2.3
[root@Kylinv10 kafka]# cd /usr/local/kafka/
[root@Kylinv10 kafka]# mkdir -p kafka_data/zookeeper # zookeeper数据
[root@Kylinv10 kafka]# mkdir -p kafka_data/log/zookeeper
[root@Kylinv10 kafka]# mkdir -p kafka_data/log/kafka # kafka日志 # zookeeper日志
在kafka解压目录同一路径下:创建一个kafka_data,用于装kafka和zookeeper的log和数据啥的!
3.2配置kafka服务
[root@Kylinv10 kafka]# cd /usr/local/kafka/kafka2.3/config/
[root@Kylinv10 config]# vim server.properties
编辑修改相应的参数,内容改动和添加如下:
broker.id=0
port=9092 #端口号
host.name=192.168.10.113 #服务器IP地址,修改为自己的服务器IP
log.dirs=/usr/local/kafka/kafka_data/log/kafka #日志存放路径,上面创建的目录
zookeeper.connect=localhost:2181 #zookeeper地址和端口,单机配置部署,localhost:2181
3.3配置zookeeper服务
[root@Kylinv10 kafka]# cd /usr/local/kafka/kafka2.3/config/
[root@Kylinv10 config]# vim zookeeper.properties
编辑修改相应的参数,内容改动和添加如下:
dataDir=/usr/local/kafka/kafka_data/zookeeper
dataLogDir=/usr/local/kafka/kafka_data/log/zookeeper
clientPort=2181
maxClientCnxns=100
tickTime=2000
initLimit=10
syncLimit=5
3.4启动停止服务
编辑kafka启动脚本
[root@Kylinv10 kafka2.3]# vim kafka_start.sh
写入以下内容
#!/bin/sh
/usr/local/kafka/kafka2.3/bin/zookeeper-server-start.sh /usr/local/kafka/kafka2.3/config/zookeeper.properties &
sleep 3
/usr/local/kafka/kafka2.3/bin/kafka-server-start.sh /usr/local/kafka/kafka2.3/config/server.properties &
编辑kafka停止脚本
[root@Kylinv10 kafka2.3]# vim kafka_stop.sh
写入以下内容
#!/bin/sh
/usr/local/kafka/kafka2.3/bin/zookeeper-server-stop.sh /usr/local/kafka/kafka2.3/config/zookeeper.properties &
sleep 3
/usr/local/kafka/kafka2.3/bin/kafka-server-stop.sh /usr/local/kafka/kafka2.3/config/server.properties &
为启动、停止脚本赋执行权限
[root@Kylinv10 kafka2.3]# chmod +x kafka_start.sh kafka_stop.sh
至此,Linux下Kafka单机安装配置完成
4.kafka测试
创建生产者 topic 和 消费者 topic 简单示例
4.1 在一个终端执行创建生产者: (推消息到cqld_test)
[root@KylinV10001 kafka2.3]# cd /usr/local/kafka/kafka2.3
[root@KylinV10001 kafka2.3]# ./kafka_start.sh #启动kafka服务
[2022-11-11 08:00:47,461] INFO [SocketServer brokerId=0] Started data-plane processors for 1 acceptors (kafka.network.SocketServer)
[2022-11-11 08:00:47,468] INFO Kafka version: 2.3.1 (org.apache.kafka.common.utils.AppInfoParser)
[2022-11-11 08:00:47,468] INFO Kafka commitId: 18a913733fb71c01 (org.apache.kafka.common.utils.AppInfoParser)
[2022-11-11 08:00:47,468] INFO Kafka startTimeMs: 1668124847462 (org.apache.kafka.common.utils.AppInfoParser)
[2022-11-11 08:00:47,470] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
[2022-11-11 08:00:47,487] INFO Got user-level KeeperException when processing sessionid:0x100044c08530000 type:multi cxid:0x38 zxid:0x1c txntype:-1 reqpath:n/a aborting remaining multi ops. Error Path:/admin/preferred_replica_election Error:KeeperErrorCode = NoNode for /admin/preferred_replica_election (org.apache.zookeeper.server.PrepRequestProcessor)
启动完成
[root@KylinV10001 kafka2.3]# cd /usr/local/kafka/kafka2.3/bin
[root@KylinV10001 bin]# ./kafka-console-producer.sh --broker-list 192.168.10.113:9092 --topic cqld_test
4.2 在另一个终端执行创建消费者:(从cqld_test上消费消息)
[root@Kylinv10 ~]# cd /usr/local/kafka/kafka2.3/bin/
[root@Kylinv10 bin]# ./kafka-console-consumer.sh --bootstrap-server 192.168.10.113:9092 --topic cqld_test
4.3查看效果: 一个终端不断输入推送的消息,另一个终端则消费这个消息
4.3查看运行的进程 和 当前topic
jps:查看服务,说明zookeeper和kafka 启动了。
[root@Kylinv10 kafka2.3]# jps
59733 Kafka
59384 QuorumPeerMain
60141 Jps
查看当前的一些topic
[root@Kylinv10 ~]# cd /usr/local/kafka/kafka2.3/bin/
[root@Kylinv10 bin]# ./kafka-topics.sh --zookeeper localhost:2181 --list
版权归原作者 欧星立 所有, 如有侵权,请联系我们删除。