编程语言
首页 > 编程语言> > Kakfa安装,PHP安装RdKafka扩展

Kakfa安装,PHP安装RdKafka扩展

作者:互联网

Kakfa安装,PHP安装RdKafka扩展

标签(空格分隔): 未分类

Java环境安装

1. 创建目录

2. 下载jdk1.8并解压
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html#license-lightbox
tar -zxvf jdk-8u281-linux-x64.tar.gz

3. 配置环境变量
vim /etc/profile

# 增加配置
JAVA_HOME=/usr/local/java/jdk1.8.0_281
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

source /etc/profile

Kafka安装使用

1. 下载源码
https://www.apache.org/dyn/closer.cgi?path=/kafka/2.7.0/kafka_2.12-2.7.0.tgz

2. 解压
tar -zxvf kafka_2.12-2.7.0.tgz

3. 启动

# 需先启动zookeeper
# -daemon 可启动后台守护模式
# 如果你已经启动了zookeeper 就不用启动下面这 (kafka默认提供有zookeeper)
bin/zookeeper-server-start.sh config/zookeeper.properties

# 启动Kafka服务端
bin/kafka-server-start.sh config/server.properties

4. 启动kafka客户端测试
# 创建一个话题,test话题2个分区
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 2 --topic test
Created topic "test".

# 显示所有话题
bin/kafka-topics.sh --list --zookeeper localhost:2181
test

# 显示话题信息
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
Topic:test    PartitionCount:2    ReplicationFactor:1    Configs:
    Topic: test    Partition: 0    Leader: 0    Replicas: 0    Isr: 0
    Topic: test    Partition: 1    Leader: 0    Replicas: 0    Isr: 0


# 启动一个生产者(输入消息)
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
[等待输入自己的内容 出现>输入即可]
>i am a new msg !
>i am a good msg ?

# 启动一个消费者(等待消息) 
# 注意这里的--from-beginning,每次都会从头开始读取,你可以尝试去掉和不去掉看下效果
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
[等待消息]
i am a new msg !
i am a good msg ?

PHP安装RdKafka

1. 下载librdkafka
git clone https://codechina.csdn.net/mirrors/edenhill/librdkafka.git

2. 编译安装
cd librdkafka/
./configure
make && make install

3. 下载RdKafka扩展
https://pecl.php.net/get/rdkafka-5.0.0.tgz
tar -zxvf rdkafka-5.0.0.tgz
cd rdkafka-5.0.0.tgz

4. 编译安装
/usr/local/php/bin/phpize
./configure --with-config=/usr/local/php/bin/php-config 
make && make install

5. php.ini 追加扩展,重启php-fpm
extension=rdkafka.so
systemctl restart php-fpm

6. php -m 验证

标签:bin,php,--,zookeeper,kafka,Kakfa,test,PHP,安装
来源: https://www.cnblogs.com/yanweifeng/p/14605612.html