1 环境准备

服务器清单服务器IP服务器配置
kolbe-a192.168.0.18核16G
kolbe-b192.168.0.28核16G
kolbe-c192.168.0.38核16G

2 设置Hostname

$ hostnamectl set-hostname kolbe-a

$ hostnamectl set-hostname kolbe-b

$ hostnamectl set-hostname kolbe-c

3 安装Java

3.1 下载并解压

# 下载并解压,移动到/opt/java
$ wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz

$ tar -zxvf jdk-8u131-linux-x64.tar.gz
$ mkdir /opt/java
$ mv jdk1.8.0_131 /opt/java

3.2 设置环境变量

$ vim /etc/profile
export JAVA_HOME=/opt/java/jdk1.8.0_131
export JRE_HOME=/opt/java/jdk1.8.0_131/jre
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=./://$JAVA_HOME/lib://$JRE_HOME/lib
$ source /etc/profile

4 安装Zookeeper

4.1 下载并解压

# 下载Zookeeper 3.4.12 版本
$ wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.12/zookeeper-3.4.12.tar.gz

# 解压缩
$ tar -zxvf zookeeper-3.4.12.tar.gz

# 新建安装地址,将目录移到 /opt/zookeeper下
$ mkdir /opt/zookeeper
$ mv zookeeper-3.4.12 /opt/zookeeper

# 新建数据目录、新建日志目录
$ mkdir /opt/zookeeper/zookeeper-3.4.12/data
$ mkdir /opt/zookeeper/zookeeper-3.4.12/log

4.2 修改配置文件

# 设置Zookeeper节点序号,注意 192.168.0.1设置为0,192.168.0.2设置为1,192.168.0.3设置成2
$ cd /opt/zookeeper/zookeeper-3.4.12/data
$ echo 0 > myid

# 修改配置文件
$ cd /opt/zookeeper/zookeeper-3.4.12/conf
$ mv zoo_sample.cfg zoo.cfg
$ vim zoo.cfg
# 核心配置项
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper/zookeeper-3.4.12/data
dataLogDir=/opt/zookeeper/zookeeper-3.4.12/log
clientPort=2181
server.0=192.168.0.1:2888:3888
server.1=192.168.0.2:2888:3888
server.2=192.168.0.3:2888:3888

4.3 设置环境变量

# 添加环境变量
$ vim /etc/profile

export ZOOKEEPER_HOME=/opt/zookeeper/zookeeper-3.4.12
export PATH=$PATH:$ZOOKEEPER_HOME/bin

$ source /etc/profile

4.4 启动Zookeeper

# 启动Zookeeper
$ zkServer.sh start

5 安装Kafka

5.1 下载及修改配置

# 下载安装包,解压并移动路径
$ wget https://archive.apache.org/dist/kafka/2.0.0/kafka_2.11-2.0.0.tgz
$ tar -zxvf kafka_2.11-2.0.0.tgz
$ mkdir /opt/kafka
$ mv kafka_2.11-2.0.0 /opt/kafka

# 创建日志文件目录
$ cd /opt/kafka/kafka_2.11-2.0.0
$ mkdir kafka-logs

# 修改配置文件
$ vim /opt/kafka/kafka_2.11-2.0.0/config/server.properties
# Broker编号
broker.id=0

# 监听客户端连接地址
listeners=PLAINTEXT://192.168.0.1:9092


num.network.threads=3
num.io.threads=8

socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600

# 日志文件路径
log.dirs=/opt/kafka/kafka_2.11-2.0.0/kafka-logs

# 默认的partitions数量
num.partitions=1
num.recovery.threads.per.data.dir=1

offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1

# 日志保存时间(7天)
log.retention.hours=168
# 每个日志segment大小,超过此值,将会创建新的segment
log.segment.bytes=1073741824
# 定期清除日志的间隔时间(单位毫秒)
log.retention.check.interval.ms=300000

# Zookeeper集群的连接地址,多外以英文逗号分隔
zookeeper.connect=192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181
# 连接Zookeeper集群的超时时间(单位毫秒)
zookeeper.connection.timeout.ms=6000

group.initial.rebalance.delay.ms=0

5.2 配置环境变量

$ vim /etc/profile
export KAFKA_HOME=/opt/kafka/kafka_2.11-2.0.0
export PATH=$PATH:$KAFKA_HOME/bin
$ source /etc/profile

5.3 启动Kafka

$ nohup kafka-server-start.sh /opt/kafka/kafka_2.11-2.0.0/config/server.properties &