kafka 简介

Kafka 是一种高吞吐量的分布式发布订阅消息系统。

环境介绍

Linux 系统:Centos7

192.168.122.10 server1
192.168.122.11 server2
192.168.122.12 server3

jdk 部署

解压 jdk 压缩包到/opt/jdk 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

tar zxvf jdk-8u111-linux-x64.tar.gz
mv jdk1.8.0_111 /opt/jdk

创建普通用户运行 kafka

useradd kafka

修改文件句柄和进程限制,并修改 hosts

echo '192.168.122.10 server1' >> /etc/hosts
echo '192.168.122.11 server2' >> /etc/hosts
echo '192.168.122.12 server3' >> /etc/hosts
echo 'kafka soft nproc 65535 ' >> /etc/security/limits.conf
echo 'kafka hard nproc 65535 ' >> /etc/security/limits.conf
echo 'kafka soft nofile 65535 ' >> /etc/security/limits.conf
echo 'kafka hard nofile 65535 ' >> /etc/security/limits.conf

修改环境变量

su - kafka
echo 'export JAVA_HOME=/opt/jdk' >> /home/kafka/.bash_profile
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /home/kafka/.bash_profile
. /home/kafka/.bash_profiles

下载 kafka 并解压安装

下载地址:http://mirror.bit.edu.cn/apache/kafka/0.10.2.0/kafka_2.11-0.10.2.0.tgz

tar zxvf kafka_2.11-0.10.2.0.tgz
mv kafka_2.11-0.10.2.0 /opt/
cd /opt
ln -s kafka_2.11-0.10.2.0 kafka

修改配置文件

cd /opt/kafka/config
vim server.properties

修改 broker.id ,在集群里面是唯一的

broker.id=0

修改日志目录路径

log.dirs=/data/kafka-logs

修改连接的 zookeeper

zookeeper.connect=192.168.122.10:2181,192.168.122.11:2181,192.168.122.12:2181

创建目录及修改权限

su - root
mkdir -p /data/kafka-logs
chown kafka.kafka /data/kafka-logs -R

启动 kafka

cd /opt/kafka/
nohup bin/kafka-server-start.sh config/server.properties &

其他两个节点只要 broker.id 分别设置成 2 3 就可以了