1.安装jdk 1.8
系统版本: CentOS Linux release 7.8.2003 (Core)
2.安装zookeeper 3.4.9
下载地址:zookeeper3.4.9 http://archive.apache.org/dist/zookeeper
1. 下载zookeeper-3.4.8.tar.gz
2. 解压tar -zxvf zookeeper-3.4.8.tar.gz
3. 修改配置文件,将$ZOOKEEPER_HOME/conf/zoo_sample.cfg复制重命名为zoo.cfg,修改zoo.cfg
修改如下6个属性,主要是修改dataDir与dataLogDir:
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/home/.../zookeeper-3.4.8/data dataLogDir=/home/.../zookeeper-3.4.8/log clientPort=2181
4. 在设置的dataDir路径下添加文件myid在这个文件中echo 1作为单机版的节点id
5. 设置zookeeper
启动后,zookeeper.out
日志输出位置
修改脚本$ZOOKEEPER_HOME/bin/zkEnv.sh
if [ "x${ZOO_LOG_DIR}" = "x" ] then ZOO_LOG_DIR="/.../zookeeper/log" fi
启动测试:
1. /export/servers/zookeeper/bin/zkServer.sh start 启动zk
2. /export/servers/zookeeper/bin/zkServer.sh status 查看启动状态或者jps命令查看服务。QuorumPeerMain表示zookeeper服务
11729 QuorumPeerMain 24982 Jps
3.安装kafka_2.11-0.10.0
下载地址:http://archive.apache.org/dist/kafka/0.10.0.0/kafka_2.11-0.10.0.0.tgz
部署步骤
1. 下载kafka_2.11-0.10.0.0.tgz
2. 解压tar -zxvf kafka_2.11-0.10.0.0.tgz
3. 设置kakfa环境变量,修改/etc/profile文件添加如下配置,然后source /etc/profile使其生效
export KAFKA_HOME=/home/.../kafka_2.11-0.10.1.1 export PATH=$PATH:$KAFKA_HOME/bin
命令行输入kafka,Tab键检查是否自动提示bin目录下命令检查是否配置成功
4. 修改配置文件:$KAFKA_HOME/config目录下的server.properties, 设置如下参数,其他参数使用默认值,broker.id对应zookeeper中myid中的数值
broker.id=1 port=9092 host.name=localhost # kafka代理地址 listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://ip:9092
log.dirs=/home/panfudong/soft/kafka/kafka_2.11-0.10.1.1/kafka-logs zookeeper.connect=localhost:2181
启动测试:
nohup /export/servers/kafka_2.11-0.10.0.0/bin/kafka-server-start.sh /export/servers/kafka_2.11-0.10.0.0/config/server.properties 2>&1 &
4.测试
创建topic:
bin/kafka-topics.sh --create --zookeeper ip:2181 --replication-factor 1 --partitions 1 --topic test
查看topic:
bin/kafka-topics.sh --list --zookeeper ip:2181
生产数据:
bin/kafka-console-producer.sh --broker-list ip:9092 --topic test
消费者消费数据:
bin/kafka-console-consumer.sh --from-beginning --topic test --zookeeper ip:2181