kafka集群搭建(二) - spring boot集成SASL权限认证方式kafka集群
kafka集群搭建(三) -kafka可视化管理工具kafka tool2使用
1、安装zookeeper集群
- 环境需求
Zookeeper需要JDK1.6以上版本的Java环境
可以参考:
CentOS 6使用rpm方式安装JDK8
此处在一台机器上部署三个zk
- 下载软件包
到ZooKeeper官网上http://zookeeper.apache.org/下载软件包,例如:zookeeper-3.4.14.tar.gz,加压到任意目录,此处放到opt下面
tar -xzvf zookeeper-3.4.14.tar.gz
mv zookeeper-3.4.14 /opt
因为我是在一台机器上面部署三个zk服务,因此我在opt下面分别放三个zk组件:zookeeper1、zookeeper2、zookeeper3,
在/apps/zookeeper下面分别建三个文件夹zk1、zk2、zk3,每个文件夹下面分别创建两个文件夹data和log,
- 修改配置文件
cd /opt/zookeeper-3.4.14/conf/
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
Zookeeper提供了一份默认的配置文件,复制为zoo.cfg打开后,我们需要修改数据存放的路径:这里贴出zookeeper1的配置,
# 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.
#############data文件和log文件目录配置,单机部署多服务时需要配置不同的目录
dataDir=/apps/zookeeper/zk1/data
dataLogDir=/apps/zookeeper/zk1/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
###########启用zookeeper连接认证,broker连接zookeeper时需要账号密码
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
requireClientAuthScheme=sasl
jaasLoginRenew=3600000
####集群部署,单机部署时用端口区分,多机部署时IP不同,端口可以相同,server后面的数字就是自己机器的myid
server.1=10.199.96.148:2880:3880
server.2=10.199.96.148:2881:3881
server.3=10.199.96.148:2882:3882
- 创建服务器标示
在目录下/apps/zookeeper/zk1/data、/apps/zookeeper/zk2/data、/apps/zookeeper/zk3/data创建文件,文件名myid,里面根据自己zk配置文件中集群配置中IP对应的需要写入1,2,3
echo "1" > /apps/zookeeper/zk1/data/myid
- 添加认证文件
在/opt/zookeeper_1/conf和/opt/zookeeper_2/conf、/opt/zookeeper_3/conf下添加文件zoo_jaas.conf:
Server {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="kafka"
password="kafkapwd"
user_kafka="kafkapwd";
};
其中username和password用户zookeeper集群之间进行认证
user_kaffka="kafkapwd"用于kafka连接zookeeper时进行认证
- 添加zk连接认证依赖jar包
在/opt/zookeeper_1和/opt/zookeeper_2、/opt/zookeeper_3下添加文件夹zk_sasl_lib,从kafka安装包libs目录下拷贝对应文件到zk_sasl_lib文件夹中,文件目录:
kafka-clients-2.3.1