ubuntu mosquitto broker服务器搭建与测试
安装软件
sudo apt install mosquitto
生成CA密钥
openssl genrsa -des3 -out ca.key 2048
签发CA证书/根证书
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt
生成服务端密钥
openssl genrsa -out server.key 2048
生成证书签名请求
openssl req -new -out server.csr -key server.key
让CA签发证书
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360
修改mosquitto.conf内容
listener 8883
cafile /etc/mosquitto/ca_certificates/ca.crt
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
tls_version tlsv1.2
mqtt broker运行测试
mosquitto -c etc/mosquitto.conf
1626408211: mosquitto version 2.0.11 starting
1626408211: Config loaded from etc/mosquitto.conf.
1626408211: Opening ipv4 listen socket on port 8883.
发布消息
mosquitto_pub -d -h localhost -t "topic/test" -m "hello world" --cafile /etc/mosquitto/ca_certificates/ca.crt -p 8883
订阅消息
mosquitto_sub -d -h localhost -t "topic/test" --cafile /etc/mosquitto/ca_certificates/ca.crt -p 8883
本文链接地址:https://const.net.cn/158.html