- 注意事项:
#!/bin/bash
#Step 1
keytool -keystore server.keystore.jks -alias localhost -validity 365 -keyalg RSA -genkey
#Step 2
openssl req -new -x509 -keyout ca-key -out ca-cert -days 365 -config openssl.cnf
keytool -keystore server.truststore.jks -alias CARoot -import -file ca-cert
keytool -keystore client.truststore.jks -alias CARoot -import -file ca-cert
#Step 3
keytool -keystore server.keystore.jks -alias localhost -certreq -file cert-file
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 365 -CAcreateserial -passin pass:123456
keytool -keystore server.keystore.jks -alias CARoot -import -file ca-cert
keytool -keystore server.keystore.jks -alias localhost -import -file cert-signed
#Step 4
keytool -keystore client.keystore.jks -alias localhost -validity 365 -keyalg RSA -genkey
bash:输入密钥库口令:
bash:再次输入新口令:
bash:您的名字与姓氏是什么? (!!!这里必须输入域名(如:localhost、baidu.com),切记不是自己的名字)
...
#其他可以为空
#SSL配置必须是证书配置的域名(如:localhost在本机),不能写IP地址
advertised.listeners=PLAINTEXT://127.0.0.1:9192,SSL://localhost:9193
listeners=PLAINTEXT://127.0.0.1:9192,SSL://:9193
ssl.enabled.protocols=TLSv1.2,TLSv1.1,TLSv1
#创建topic
kafka-topics.sh --create --zookeeper www.liuwei.com:2181 --replication-factor 1 --partitions 1 --topic mytopic2
#生产者
kafka-console-producer.sh --broker-list localhost:9093 --topic mytopic2 --producer.config ./client-ssl.properties
#消费者
kafka-console-consumer.sh --bootstrap-server localhost:9093 --topic mytopic2 --from-beginning --consumer.config ./client-ssl.properties