服务器列表如下,并配置免密登陆
192.168.52.135 master
192.168.52.136 slave1
192.168.52.134 slave2
1.安装jdk ,并配置环境变量,略去
2. 安装zookeeper 集群
master节点:
[root@master app]# pwd
/usr/local/app
[root@master app]# tar -zxvf zookeeper-3.4.13.tar.gz
[root@master app]# cd zookeeper-3.4.13/conf/
[root@master conf]# mv zoo_sample.cfg zoo.cfg
[root@master conf]# vim zoo.cfg
信息如下:
initLimit=10
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper/data
dataLogDir=/tmp/zookeeper/log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.0=master:2888:3888
server.1=slave1:2888:3888
server.2=slave2:2888:3888
保存退出
[root@master tmp]# mkdir -p /tmp/zookeeper/data/
[root@master tmp]# mkdir -p /tmp/zookeeper/log/
[root@master tmp]# vim /tmp/zookeeper/data/myid
这里输入 0:
# 发送 zookeeper文件夹到其他两个服务器
[root@master app]# scp -r /usr/local/app/zookeeper-3.4.13 root@slave1:$PWD
[root@master app]# scp -r /usr/local/app/zookeeper-3.4.13 root@slave2:$PWD
[root@master app]# ssh slave1
Last login: Sat Mar 23 08:11:47 2019 from 192.168.52.1
[root@slave1 ~]# vim /tmp/zookeeper/data/myid
1
保存退出
[root@slave1 ~]# exit
logout
Connection to slave1 closed.
[root@master app]# ssh slave2
Last login: Sat Mar 23 08:11:46 2019 from 192.168.52.1
[root@slave2 ~]# vim /tmp/zookeeper/data/myid
2
保存退出
[root@slave2 ~]# exit
logout
Connection to slave2 closed.
三台服务器配置zookeeper环境变量
export ZK_HOME=/usr/local/app/zookeeper-3.4.13
export PATH=$PATH:$ZK_HOME/bin
三台服务器分别启动zookeeper
[root@master app]# zkServer.sh start
zookeeper信息如下:
master节点
[root@master ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/app/zookeeper-3.4.13/bin/../conf/zoo.cfg
Mode: follower
slave1节点:
[root@slave1 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/app/zookeeper-3.4.13/bin/../conf/zoo.cfg
Mode: follower
slave2节点
[root@slave2 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/app/zookeeper-3.4.13/bin/../conf/zoo.cfg
Mode: leader
3. 安装kafka 集群
[root@master app]# pwd
/usr/local/app
[root@master app]# ls
elasticsearch-6.5.4 jdk1.8.0_191 kafka_2.11-2.1.1.tgz zookeeper-3.4.13.tar.gz
zookeeper-3.4.13
[root@master app]# tar -zxvf kafka_2.11-2.1.1
[root@master app]# cd kafka_2.11-2.1.1
[root@master kafka_2.11-2.1.1]# pwd
/usr/local/app/kafka_2.11-2.1.1
[root@master kafka_2.11-2.1.1]# vim config/server.properties
需要关注的信息如下:
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
# 这里不能写localhost
listeners=PLAINTEXT://master:9092
# A comma separated list of directories under which to store log files
log.dirs=/tmp/kafka-logs
# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181/kafka
保存退出
##发送kafka文件到其他服务器
[root@master kafka_2.11-2.1.1]# scp -r /usr/local/app/kafka_2.11-2.1.1 root@slave1:$PWD
[root@master kafka_2.11-2.1.1]# scp -r /usr/local/app/kafka_2.11-2.1.1 root@slave2:$PWD
修改slave1配置文件如下:
[root@master kafka_2.11-2.1.1]# vim config/server.properties
broker.id=1
listeners=PLAINTEXT://slave1:9092
修改slave2配置文件如下:
[root@master kafka_2.11-2.1.1]# vim config/server.properties
broker.id=2
listeners=PLAINTEXT://slave2:9092
三台服务器分别配置kafka环境变量:
export KAFKA_HOME=/usr/local/app/kafka_2.11-2.1.1
export PATH=$PATH:$KAFKA_HOME/bin
三台服务器分别启动kafka:
[root@master kafka_2.11-2.1.1]# pwd
/usr/local/app/kafka_2.11-2.1.1
[root@master kafka_2.11-2.1.1]# bin/kafka-server-start.sh config/server.properties &
查看是否启动成功:
[root@master kafka_2.11-2.1.1]# jps
7168 QuorumPeerMain
7224 Kafka
7673 Jps
配置完成!!