1. zookeeper部署
安装JDK1.7:
rpm -ivh jdk-7u79-linux-x64.rpm
vi /etc/profile
JAVA_HOME=/usr/java/jdk1.7.0_79
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
source /etc/profile
安装zookeeper(单机)
mkdir -p /home/app/zookeeper
tar -zxvf zookeeper-3.4.10.tar.gz
mv zookeeper-3.4.10/ /home/app/zookeeper
cd /home/app/zookeeper
cp conf/zoo_sample.cfg conf/zoo.cfg
设置配置文件zoo.cfg
# 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 # leader与follower之间发送消息,请求和应答时间长度
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/app/zookeeper/data #数据(注意每个机器都要新建)
dataLogDir=/home/app/zookeeper/logs #日志
# 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
启动测试
./zkServer.sh start (启动)
./zkServer.sh status(查看状态)
安装zookeeper(集群)
配置文件zoo.cfg最后增加如下:
server.1= 192.168.199.69:2888:3888 #信息交换和选举端口,集群配置
server.2= 192.168.199.70:2888:3888
server.3= 192.168.199.71:2888:3888
除了修改zoo.cfg配置文件外,zookeeper集群模式下还要配置一个myid文件,这个文件需要放在dataDir目录下。
echo "1" > /home/app/zookeeper1/data/myid
echo "2" > /home/app/zookeeper2/data/myid
echo "3" > /home/app/zookeeper3/data/myid
其他配置
需要防火墙开启三个端口 2181 2888 3888(可以使用其他端口)
如果zookeeper无法启动请检查配置文件,关闭防火墙再测试下
创建目录data logs(在zookeeper目录下,根据配置文件设置)
mkdir data
mkdir logs
启动测试
./zkServer.sh start (启动)
./zkServer.sh status(查看状态)
参考:https://www.cnblogs.com/luotianshuai/p/5206662.html
kafka部署
Kafka¬集群和zookeeper集群如下图所示,每个kafka作为一个broker注册到zookeeper集群中,同时注册到一个zookeeper集群中就会组成一个kafka集群,在集群中需要唯一的标识:broker.id。
Kafka的存储:https://www.jianshu.com/p/3e54a5a39683
Kakfa原理:https://www.cnblogs.com/lujinhong2/p/4686483.html
Kafka部署:https://www.cnblogs.com/lujinhong2/p/4686467.html
Zookeeper是注册中心,会存储kafka的所有数据信息。以便其他程序消费时使用。https://blog.csdn.net/u013735511/article/details/75505677
下载kafka
wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.2.1/kafka_2.12-2.2.1.tgz
解压、移动到指定文件夹
tar -zxvf kafka_2.12-2.2.1.tgz
mkdir /home/kafka/
mv kafka_2.12-2.2.1/* /home/kafka/
可以看到bin目录下所有的命令,其中有内置zookeeper,这里没有使用,而是自己创建zookeeper。
设置sever.properties
broker.id=0 #集群中唯一标识
listeners=PLAINTEXT://172.16.15.48:9092 #监听的ip和端口 需要根据所在机器设置
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=/tmp/kafka-logs #消息存放的位置,特别注意磁盘大小
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
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connect=172.16.15.48:2181 #注册的zookeeper,可以是集群例如:192.168.7.100:12181,192.168.7.101:12181,192.168.7.107:1218
group.initial.rebalance.delay.ms=0
message.max.byte=5242880 #消息保存最大值此处需要特别注意默认接受1M 只有设置后可以接受大数据消息
default.replication.factor=2 #保存副本数
replica.fetch.max.bytes=5242880 #取消息最大值
启动kafka
如果是集群在每台设置好配置文件(注意broker.id和listeners),在全部启动即可。
cd /home/app/kafka/
nohup bin/kafka-server-start.sh config/server.properties &
或者
cd /home/app/kafka/bin
./kafka-server-start.sh -daemon ../config/server.properties
操作kafka
#创建topic 一个分区一个备份
./kafka-topics.sh --create --zookeeper 172.16.15.48:2181 --replication-factor 1 --partitions 1 --topic testTopic
#查看topic
./kafka-topics.sh --list --zookeeper 172.16.15.48:2181
#生产消息
./kafka-console-producer.sh --broker-list 172.16.15.48:9092 --topic testTopic
#消费信息
./kafka-console-producer.sh --broker-list 172.16.15.48:9092 --topic testTopic --from-beginning
#查看topic描述
./kafka-topics.sh --describe --zookeeper 172.16.15.48:2181 --topic testTopic
kafka命令行可以参考:https://www.cnblogs.com/JThinking/p/9447789.html