CentOS6部署安装kafka和zookeeper集群

###安装之前准备工作
1.修改hostname,修改hosts文件
2.ssh三台机器之前打通,我这边使用的key方式登陆

###zookeeper安装方法
1.下载
wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

2.把zoo_sample.cfg复制成zoo.cfg,并修改.三台机器都需要做如下配置修改
[root@zm-pro-kafka-01 kafka_2.9.1-0.8.2.1]# cat  /usr/local/zookeeper-3.4.6/conf/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
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/data/zookeeper
# 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.1=10.47.105.229:2888:3888
server.2=10.47.106.147:2888:3888
server.3=10.47.106.7:2888:3888
[root@zm-pro-kafka-01 kafka_2.9.1-0.8.2.1]#
3.创建目录
[root@zm-pro-kafka-01 kafka_2.9.1-0.8.2.1]# ll /data/zookeeper/ -d
drwxr-xr-x 3 root root 4096 Jan 12 17:14 /data/zookeeper/
[root@zm-pro-kafka-01 kafka_2.9.1-0.8.2.1]# 
4.创建文件ID每台不一样,我这边设置是1 2 3
    [root@zm-pro-kafka-01 kafka_2.9.1-0.8.2.1]# cat /data/zookeeper/myid
    1
    [root@zm-pro-kafka-01 kafka_2.9.1-0.8.2.1]#

5.启动 查看
    ./zookeeper-3.4.6/bin/zkServer.sh start

6.查看
    [root@zm-pro-kafka-01 local]# ./zookeeper-3.4.6/bin/zkServer.sh status
    JMX enabled by default
    Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
    Mode: follower
    [root@zm-pro-kafka-01 local]#

###kafka安装部署方法
1.下载
wget http://apache.fayea.com/kafka/0.8.2.1/kafka_2.9.1-0.8.2.1.tgz

    2.配置, 需要注意三个点 
    1.hostname要修改
    2.broker.ids三个ID要保持不一样
    3.zk的地址需要修改 就是我们zk集群的地址
PS:三台配置都一样除过三个需要修改的点
[root@zm-pro-kafka-01 local]# cat /usr/local/kafka_2.9.1-0.8.2.1/config/server.properties  |grep -v '^#' | grep -v '^$'
broker.id=0
port=9092
host.name=10.47.105.229
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
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
log.cleaner.enable=false
zookeeper.connect=10.47.105.229:2181,10.47.106.147:2181,10.47.106.7:2181/kafka
zookeeper.connection.timeout.ms=6000
[root@zm-pro-kafka-01 local]#

3.启动
    nohup ./bin/kafka-server-start.sh config/server.properties &

4.测试
    #创建
    ./bin/kafka-topics.sh --create --zookeeper 10.47.105.229:2181,10.47.106.147:2181,10.47.106.7:2181/kafka  --replication-factor 3 --partitions 5 --topic mytest
    #查看创建的详细信息
    ./bin/kafka-topics.sh --describe  --zookeeper 10.47.105.229:2181,10.47.106.147:2181,10.47.106.7:2181/kafka --topic mytest
    #查看列表
./bin/kafka-topics.sh --list  --zookeeper 10.47.105.229:2181,10.47.106.147:2181,10.47.106.7:2181/kafka
OpsNotes wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!