当前位置:   article > 正文

Kafka集群搭建(Docker方式部署)_docker部署kafka集群

docker部署kafka集群

Docker方式部署
    1.创建数据目录

  1. mkdir -p /tmp/kafka/broker{1..3}/{data,logs}
  2. mkdir -p /tmp/zookeeper/zookeeper/{data,datalog,logs,conf}

    2.Zookeeper配置,创建Zookeeper配置文件

vi /tmp/zookeeper/zookeeper/conf/zoo.cfg

        1)文件修改内容

  1. # The number of milliseconds of each tick
  2. tickTime=2000
  3. # The number of ticks that the initial
  4. # synchronization phase can take
  5. initLimit=10
  6. # The number of ticks that can pass between
  7. # sending a request and getting an acknowledgement
  8. syncLimit=5
  9. # the directory where the snapshot is stored.
  10. # do not use /tmp for storage, /tmp here is just
  11. # example sakes.
  12. dataDir=/data
  13. dataLogDir=/datalog
  14. # the port at which the clients will connect
  15. clientPort=2181
  16. # the maximum number of client connections.
  17. # increase this if you need to handle more clients
  18. #maxClientCnxns=60
  19. #
  20. # Be sure to read the maintenance section of the
  21. # administrator guide before turning on autopurge.
  22. #
  23. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  24. #
  25. # The number of snapshots to retain in dataDir
  26. autopurge.snapRetainCount=3
  27. # Purge task interval in hours
  28. # Set to "0" to disable auto purge feature
  29. autopurge.purgeInterval=1

    3.创建Zookeeper日志配置

vi /tmp/zookeeper/zookeeper/conf/log4j.properties

        1)文件修改内容

  1. # Define some default values that can be overridden by system properties
  2. zookeeper.root.logger=INFO, CONSOLE
  3. zookeeper.console.threshold=INFO
  4. zookeeper.log.dir=/logs
  5. zookeeper.log.file=zookeeper.log
  6. zookeeper.log.threshold=DEBUG
  7. zookeeper.tracelog.dir=.
  8. zookeeper.tracelog.file=zookeeper_trace.log
  9. #
  10. # ZooKeeper Logging Configuration
  11. #
  12. # Format is "<default threshold> (, <appender>)+
  13. # DEFAULT: console appender only
  14. log4j.rootLogger=${zookeeper.root.logger}
  15. # Example with rolling log file
  16. #log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
  17. # Example with rolling log file and tracing
  18. #log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE
  19. #
  20. # Log INFO level and above messages to the console
  21. #
  22. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
  23. log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
  24. log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
  25. log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
  26. #
  27. # Add ROLLINGFILE to rootLogger to get log file output
  28. # Log DEBUG level and above messages to a log file
  29. log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
  30. log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
  31. log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
  32. # Max log file size of 10MB
  33. log4j.appender.ROLLINGFILE.MaxFileSize=10MB
  34. # uncomment the next line to limit number of backup files
  35. log4j.appender.ROLLINGFILE.MaxBackupIndex=10
  36. log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
  37. log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
  38. #
  39. # Add TRACEFILE to rootLogger to get log file output
  40. # Log DEBUG level and above messages to a log file
  41. log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
  42. log4j.appender.TRACEFILE.Threshold=TRACE
  43. log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}
  44. log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
  45. ### Notice we are including log4j's NDC here (%x)
  46. log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n

    4.创建Docker编排文件

vi docker-compose.yaml

        1)文件修改内容

  1. version: '2'
  2. services:
  3. zookeeper:
  4. container_name: zookeeper
  5. image: wurstmeister/zookeeper
  6. restart: unless-stopped
  7. hostname: zoo1
  8. volumes:
  9. - "/tmp/zookeeper/zookeeper/data:/data"
  10. - "/tmp/zookeeper/zookeeper/datalog:/datalog"
  11. - "/tmp/zookeeper/zookeeper/logs:/logs"
  12. - "/tmp/zookeeper/zookeeper/conf:/opt/zookeeper-3.4.13/conf"
  13. ports:
  14. - "2181:2181"
  15. networks:
  16. - kafka
  17. kafka1:
  18. container_name: kafka1
  19. image: wurstmeister/kafka
  20. ports:
  21. - "9092:9092"
  22. environment:
  23. KAFKA_ADVERTISED_HOST_NAME: 192.168.245.253 ## 修改:宿主机IP
  24. KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.245.253:9092 ## 修改:宿主机IP
  25. KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
  26. KAFKA_ADVERTISED_PORT: 9092
  27. KAFKA_BROKER_ID: 1
  28. KAFKA_LOG_DIRS: /kafka/data
  29. volumes:
  30. - /tmp/kafka/broker1/logs:/opt/kafka/logs
  31. - /tmp/kafka/broker1/data:/kafka/data
  32. depends_on:
  33. - zookeeper
  34. networks:
  35. - kafka
  36. kafka2:
  37. container_name: kafka2
  38. image: wurstmeister/kafka
  39. ports:
  40. - "9093:9092"
  41. environment:
  42. KAFKA_ADVERTISED_HOST_NAME: 192.168.245.253 ## 修改:宿主机IP
  43. KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.245.253:9093 ## 修改:宿主机IP
  44. KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
  45. KAFKA_ADVERTISED_PORT: 9093
  46. KAFKA_BROKER_ID: 2
  47. KAFKA_LOG_DIRS: /kafka/data
  48. volumes:
  49. - /tmp/kafka/broker2/logs:/opt/kafka/logs
  50. - /tmp/kafka/broker2/data:/kafka/data
  51. depends_on:
  52. - zookeeper
  53. networks:
  54. - kafka
  55. kafka3:
  56. container_name: kafka3
  57. image: wurstmeister/kafka
  58. ports:
  59. - "9094:9092"
  60. environment:
  61. KAFKA_ADVERTISED_HOST_NAME: 192.168.245.253 ## 修改:宿主机IP
  62. KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.245.253:9094 ## 修改:宿主机IP
  63. KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
  64. KAFKA_ADVERTISED_PORT: 9094
  65. KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
  66. KAFKA_MIN_INSYNC_REPLICAS: 2
  67. KAFKA_BROKER_ID: 3
  68. KAFKA_LOG_DIRS: /kafka/data
  69. volumes:
  70. - /tmp/kafka/broker3/logs:/opt/kafka/logs
  71. - /tmp/kafka/broker3/data:/kafka/data
  72. depends_on:
  73. - zookeeper
  74. networks:
  75. - kafka
  76. kafka-manager:
  77. image: sheepkiller/kafka-manager ## 镜像:开源的web管理kafka集群的界面
  78. environment:
  79. ZK_HOSTS: 192.168.245.253 ## 修改:宿主机IP
  80. ports:
  81. - "9000:9000" ## 暴露端口
  82. networks:
  83. - kafka
  84. networks:
  85. kafka:
  86. driver: bridge

    5.启动服务
      

docker-compose up -d

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/818820
推荐阅读
相关标签
  

闽ICP备14008679号