项目场景:
centos7服务器,kafka单机安装及简单应用
解决方案:
#安装jdk
rpm -ivh jdk-8u191-linux-x64.rpm
#设置环境变量
vi .bashrc
--------------------------------
JAVA_HOME=/usr/java/latest
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.
export JAVA_HOME
export PATH
export CLASSPATH
---------------------------------
source .bashrc
#测试
echo $JAVA_HOME
#设置主机名
hostnamectl set-hostname master
#设置hosts
vi /etc/hosts
----------------------------------
192.168.159.129 master
----------------------------------
#测试
ping master
#查看防火墙status,关闭stop
service iptables status
#查看
chkconfig --list
解压zookeeper,安装
tar -zxf zookeeper-3.4.6.tar.gz
-------------------------------
[root@localhost zookeeper-3.4.6]# ls
bin docs README_packaging.txt zookeeper-3.4.6.jar.md5
build.xml ivysettings.xml README.txt zookeeper-3.4.6.jar.sha1
CHANGES.txt ivy.xml recipes zookeeper.out
conf lib src
contrib LICENSE.txt zookeeper-3.4.6.jar
dist-maven NOTICE.txt zookeeper-3.4.6.jar.asc
--------------------------------
cd conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
--------------------------
dataDir=/tmp/zookeeper
--------------------------
#开启
[root@localhost zookeeper-3.4.6]# ./bin/zkServer.sh start zoo.cfg
[root@localhost zookeeper-3.4.6]# jps
解压kafka,安装
tar -zxf kafka_2.11-2.2.0.tgz
--------------------------------
[root@localhost kafka_2.11-2.2.0]# ls
bin config libs LICENSE logs NOTICE site-docs
--------------------------------
cd config/
[root@localhost config]# vi server.properties
--------------------------------
listeners=PLAINTEXT://master:9092
log.dirs=/tmp/kafka-logs
zookeeper.connect=master:2181
--------------------------------
#开启
./bin/kafka-server-start.sh -daemon config/server.properties
jps
#创建topic,一个分区,一个因子
./bin/lafka-topics.sh --bootstrap-server master:9092 --create --topic topic01 --partitions 1 --replication-factor 1
#另开一个窗口,测试生产者
./bin/kafka-console-producer.sh --broker-list master:9092 --topic topic01
#另开一个窗口,测试消费者
./bin/kafka-console-consumer.sh --bootstrap-server master:9092 --topic topic01 --group group1
#若关闭kafka、zookeeper
./bin/kafka-server-stop.sh
./bin/zkServer.sh stop zoo.cfg
complete!