上传kafka包,解压,赋权限
unzip kafka
修改配置文件config/server.properties
broker.id=0
host.name=IP
zookeeper.connect=IP:2181
给kafka整个目录下赋权限
chmod +x sbin/*
修改log4j.properties文件
log4j.appender.D.File = /home/wyz/kafka_2.9.2-0.8.1.1/logs/debug.log
log4j.appender.E.File =/home/wyz/kafka_2.9.2-0.8.1.1/logs/error.log
jps -l
netstat -ant |grep 9092
创建topic主题
bin/kafka-topics.sh --create --zookeeper 192.168.218.160:2181 --replication-factor 1 --partitions 1 --topic topic-test-wyz
查看topic是否创建成功
bin/kafka-topics.sh --list --zookeeper 192.168.218.160:2181
启动productor
bin/kafka-console-producer.sh --broker-list 192.168.218.160:9092 --topic topic-test-wyz
另启一个窗口,启动consumer
bin/kafka-console-consumer.sh --zookeeper 192.168.218.160:2181 --topic topic-test-wyz
将log注释掉,插入以下命令
log="INSERT INTO test (user,content) VALUES('wu yuezhen','hello everybody');"
启动运行
nohup sh shelllogger.sh >> shelllogger.log 2>&1 &
查看实时输出
tail -f access.log
bin/kafka-console-consumer.sh --zookeeper 192.168.218.160:2181 --topic topic-test-wyz
开启另一个端口,在kafka目录中执行
nohup tail -f /home/wyz/kafka_2.9.2-0.8.1.1/logger/access.log | /home/wyz/kafka_2.9.2-0.8.1.1/bin/kafka-console-producer.sh --broker-list 192.168.218.160:9092 --topic topic-test-wyz >/home/wyz/kafka_2.9.2-0.8.1.1/logs/producer.log 2>&1 &
unzip kafka
修改配置文件config/server.properties
broker.id=0
host.name=IP
zookeeper.connect=IP:2181
给kafka整个目录下赋权限
chmod +x sbin/*
修改log4j.properties文件
log4j.appender.D.File = /home/wyz/kafka_2.9.2-0.8.1.1/logs/debug.log
log4j.appender.E.File =/home/wyz/kafka_2.9.2-0.8.1.1/logs/error.log
启动kafka服务
方法1:
在/home/wyz/kafka_2.9.2-0.8.1.1目录下执行
sbin/start-kafka.sh
/home/wyz/kafka_2.9.2-0.8.1.1/sbin下start-kafka.sh的内容为
bin/kafka-server-start.sh -daemon config/server.properties &
方法2:
在/home/wyz/kafka_2.9.2-0.8.1.1/bin目录下执行
./kafka-server-start.sh -daemon ../config/server.properties
jps -l
netstat -ant |grep 9092
创建topic主题
bin/kafka-topics.sh --create --zookeeper 192.168.218.160:2181 --replication-factor 1 --partitions 1 --topic topic-test-wyz
查看topic是否创建成功
bin/kafka-topics.sh --list --zookeeper 192.168.218.160:2181
启动productor
bin/kafka-console-producer.sh --broker-list 192.168.218.160:9092 --topic topic-test-wyz
另启一个窗口,启动consumer
bin/kafka-console-consumer.sh --zookeeper 192.168.218.160:2181 --topic topic-test-wyz
在productor端口输入,看consumer端的输出
将log注释掉,插入以下命令
log="INSERT INTO test (user,content) VALUES('wu yuezhen','hello everybody');"
启动运行
nohup sh shelllogger.sh >> shelllogger.log 2>&1 &
查看实时输出
tail -f access.log
将日志实时传送到kafka指定主题中
bin/kafka-console-consumer.sh --zookeeper 192.168.218.160:2181 --topic topic-test-wyz
开启另一个端口,在kafka目录中执行
nohup tail -f /home/wyz/kafka_2.9.2-0.8.1.1/logger/access.log | /home/wyz/kafka_2.9.2-0.8.1.1/bin/kafka-console-producer.sh --broker-list 192.168.218.160:9092 --topic topic-test-wyz >/home/wyz/kafka_2.9.2-0.8.1.1/logs/producer.log 2>&1 &