==作者:YB-Chi==
[toc]
所需组件
1 2 3
| JDK1.8 Zookeeper3.4.6 kafka_2.11-0.10.0.0
|
安装jdk
配置jdk要先卸载centos自带的openjdk 先查看 rpm -qa | grep java 显示如下信息:
1 2 3 4 5 6 7 8
| [root@localhost /]# rpm -qa | grep java java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64 javapackages-tools-3.4.1-11.el7.noarch java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64 tzdata-java-2015g-1.el7.noarch java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64 java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64 python-javapackages-3.4.1-11.el7.noarch
|
卸载
1 2 3 4
| rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64 rpm -e --nodeps java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64 rpm -e --nodeps java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64 rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
|
解压jdk在/usr/local并配置环境变量
1 2 3 4 5 6 7 8 9 10 11
| vim /etc/profile 在最后添加 JAVA_HOME=/usr/local/jdk_1.8 PATH=$PATH:$JAVA_HOME/bin: CLASSPATH=.:$JAVA_HOME/lib export JAVA_HOME PATH CLASSPATH 更新配置文件 source /etc/profile 验证 java -version javac
|
安裝Zookeeper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| 解压tar zxvf zookeeper-3.4.6.tar.gz
重命名mv zookeeper-3.4.6 zookeeper
修改配置文件 cp zoo_simple.cfg zoo.cfg vim zoo.cfg 修改dataDir zk的目录 dataDir=/usr/local/zookeeper/data 创建data目录
配置zk的环境变量(参考添加) vim /etc/profile export ZK_HOME=/usr/local/zookeeper PATH=$PATH:$JAVA_HOME/bin:$ZK_HOME/bin:
更新配置文件 source /etc/profile
启动 zkServer.sh start zk使用 可以使用命令zkCli.sh进入zk客户端
|
图示成功
安装Kafka
解压在/usr/local 重命名为kafka方便修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| mkdir -p /var/local/kafka/data/ cd /usr/local/kafka/config
vi server.properties
broker.id=0 port=9092 listeners = PLAINTEXT://192.168.56.212:9092 log.dirs=/var/local/kafka/data/ zookeeper.connect=192.168.56.212:2181
启动 cd /usr/local/kafka bin/kafka-server-start.sh config/server.properties
|
脚本
1 2 3 4 5 6 7 8 9 10 11 12 13
| cd /usr/local/kafka
vim kafkastart.sh
/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties &
vim kafkastop.sh
/usr/local/kafka/bin/kafka-server-stop.sh /usr/local/kafka/config/server.properties &
chmod +x kafkastart.sh chmod +x kafkastop.sh
|
开启SASL认证(未成功)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| cd config/
vim kafka_server_jaas.conf
KafkaServer{ org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin" user_admin="admin" user_alice="alice"; };
vim kafka_client_jaas.conf
KafkaClient { org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin"; };
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| vim server.properties
listeners=SASL_PLAINTEXT://192.168.56.212:9092 security.inter.broker.protocol=SASL_PLAINTEXT sasl.mechanism.inter.broker.protocol=PLAIN sasl.enabled.mechanisms=PLAIN authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer super.users=User:admin
vim producer.properties
security.protocol = SASL_PLAINTEXT sasl.mechanism = PLAIN
vim consumer.properties
security.protocol = SASL_PLAINTEXT sasl.mechanism = PLAIN
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| cd ../bin/
vim kafka-run-class.sh
KAFKA_SASL_OPTS='-Djava.security.auth.login.config=/usr/local/kafka/config/kafka_server_jaas.conf' if [ "x$DAEMON_MODE" = "xtrue" ]; then nohup $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_SASL_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@" > "$CONSOLE_OUTPUT_FILE" 2>&1 < /dev/null & else exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_SASL_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@" fi
vim kafka-console-producer-sasl.sh
export KAFKA_OPTS="-Djava.security.auth.login.config=/usr/local/kafka/config/kafka_client_jaas.conf" /usr/local/kafka/bin/kafka-console-producer.sh "$@"
vim kafka-console-consumer-sasl.sh
export KAFKA_OPTS="-Djava.security.auth.login.config=/usr/local/kafka/config/kafka_client_jaas.conf" /usr/local/kafka/bin/kafka-console-consumer.sh --new-consumer "$@"
|
1 2 3
| 使用命令对topic赋予指定用户的读写权限 启动sasl的客户端进行认证 本文不提供命令 参考kafka记录中SHELL标题
|