Kafka_2.12-2.2.0集群搭建

  1. 安装包
        a:zookeeper版本
              
        b:kafka版本
               
  2. 虚机环境
      3台机器
           a:192.168.191.101  eshop-cache01
           b:192.168.191.102  eshop-cache02
           c:192.168.191.103  eshop-cache03
  3. 将安装包上传到/usr/local/module路径下,并且解压
      
  4. 配置zookeeper的环境变量,vim /etc/profile
      
  5. 修改/usr/local/module/zookeeper-3.4.10/conf路径下zoo_sample.cfg文件,将zoo_sample.cfg修改为zoo.cfg
    并且配置其内容。
      
    配置zoo.cfg内容:
      
  6. 进入/usr/local/module/zookeeper-3.4.10创建data目录,并且创建myid文件,填写指定的server
     
  7. 将刚刚在eshop-cache01上面配置的内容使用scp拷贝到eshop-cache02,eshop-cache03上面一份
     
      注意:
            /etc/profile的环境变量也要配置一下在其它两台机器上面。
            其它两台机器的/usr/local/module/zookeeper-3.4.10/data路径下myid要修改
            eshop-cache02修改为1,eshop-cache03修改为2
  8. 启动zookeeper服务器
      在3台服务器上分别启动zookeeper,路径:/usr/local/module/zookeeper-3.4.10
      启动命令:bin/zkServer.sh start
      启动后查看状态命令:bin/zkServer.sh status
      
  9. 下面配置kafka的/usr/local/module/kafka_2.12-2.2.0/config/server.properties文件,以及producer.properties,
     和consumer.properties文件
     a:server.properties
     
    #broker的全局唯一编号,不能重复
    broker.id=0
    
    host.name=eshop-cache01
    
    listeners=PLAINTEXT://eshop-cache01:9092
    
    #kafka运行日志存放的路径
    log.dirs=/usr/local/module/kafka_2.12-2.2.0/tmp/kafka-logs
    
    #zookeeper连接
    zookeeper.connect=eshop-cache01:2181,eshop-cache02:2181,eshop-cache03:2181
    
    
    b:producer.properties
      
     c:consumer.properties文件
       
     
  10. 将kafka的配置分别拷贝到eshop-cache02,eshop-cache03两台机器上
     
  11. 将其他两台机器的/usr/local/module/kafka_2.12-2.2.0/config/server.properties文件中的broker.id分别修改为1和2
     
     
  12. 下面开始使用命令启动kafka,进入/usr/local/module/kafka_2.12-2.2.0目录下,3台机器都启动
     命令:nohup bin/kafka-server-start.sh config/server.properties &
     
  13. 效果
     
     
     
  14. 使用基本命令检查kafka是否搭建成功
     ⑴命令:创建一个副本数为1,分区为1的topic,名称为test
            bin/kafka-topics.sh --zookeeper 192.168.191.101:2181,192.168.191.102:2181,192.168.191.103:2181 --topic test --replication-factor 1 --partitions 1 --create

      ⑵命令:进入生产者窗口
               bin/kafka-console-producer.sh --broker-list 192.168.191.101:9092,192.168.191.102:9092,192.168.191.103:9092 --topic test
            
       ⑶命令:进入消费者窗口
             bin/kafka-console-consumer.sh --bootstrap-server eshop-cache01:9092,eshop-cache02:9092,eshop-cache03:9092 --topic test --from-beginning
            
  15. 在生产这窗口发送消息看效果
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值