美文网首页
Docker 部署 带鉴权的kafka集群 SASL

Docker 部署 带鉴权的kafka集群 SASL

作者: Sunnky | 来源:发表于2019-12-03 11:18 被阅读0次
    1. 新建配置文件
      sudo mkdir /root/secrets
      cd /root/secrets
      sudo vim server_jaas.conf
    KafkaServer {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="admin"
    password="admin-secret"
    user_admin="admin-secret"
    user_alice="alice-secret";
    };
    Client {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="admin"
    password="admin-secret";
    };
    
    Server {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="admin"
    password="admin-secret"
    user_admin="admin-secret";
    };
    
    1. 新建docker-compose文件
      sudo vim docker-compose.yaml
    version: '2'
    services:
        zookeeper:
            image: confluentinc/cp-zookeeper:5.1.2
            hostname: zookeeper
            restart: always
            ports:
                - 2182:2182
            environment:
                ZOOKEEPER_CLIENT_PORT: 2182
                ZOOKEEPER_TICK_TIME: 2000
                ZOOKEEPER_MAXCLIENTCNXNS: 0
                ZOOKEEPER_AUTHPROVIDER.1: org.apache.zookeeper.server.auth.SASLAuthenticationProvider
                ZOOKEEPER_REQUIRECLIENTAUTHSCHEME: sasl
                ZOOKEEPER_JAASLOGINRENEW: 3600000
                KAFKA_OPTS: -Djava.security.auth.login.config=/etc/kafka/secrets/zk_server_jaas.conf
            volumes:
                - /root/secrets:/etc/kafka/secrets
        kafka:
            image: confluentinc/cp-kafka:5.1.2
            hostname: broker
            container_name: kafka
            depends_on:
                - zookeeper
            ports:
                - 9093:9093
            environment:
                KAFKA_BROKER_ID: 1
                KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2182'
                KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
                KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
                KAFKA_LISTENERS: SASL_PLAINTEXT://172.18.0.3:9093
                KAFKA_ADVERTISED_LISTENERS: SASL_PLAINTEXT://47.101.221.106:9093
                KAFKA_SECURITY_INTER_BROKER_PROTOCOL: SASL_PLAINTEXT
                KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL: PLAIN
                KAFKA_SASL_ENABLED_MECHANISMS: PLAIN
                KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer
                KAFKA_OPTS: -Djava.security.auth.login.config=/etc/kafka/secrets/kafka_server_jaas.conf
                KAFKA_SUPER_USERS: User:admin
            volumes:
                - /root/secrets:/etc/kafka/secrets
    
    1. 启动
      直接 docker-compose up .

    2. 如果是不需要鉴权的,直接docker run下面命令即可

    • zookeeper
    docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper
    
    • kafka
    docker run -d --name kafka \
    --p 9092:9092 \
    --link zookeeper \
    --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
    --env KAFKA_ADVERTISED_HOST_NAME=47.101.221.106 \
    --env KAFKA_ADVERTISED_PORT=9092 \
    --volume /etc/localtime:/etc/localtime \
    wurstmeister/kafka:2.11-0.11.0.3
    

    其中47.101.221.106这个ip换成自己机器的外网ip

    相关文章

      网友评论

          本文标题:Docker 部署 带鉴权的kafka集群 SASL

          本文链接:https://www.haomeiwen.com/subject/inhcgctx.html