环境搭建
1、mosquitto所需要的rpm包
2、c-ares-1.12.0
3、安装最新的openssl版本
4、mosquitto-1.4.10
mosquitto需要的rpm包
c-ares安装
c-ares源码下载
./buildconf #提示libtoolize not found. 需要安装libtool,autoconf,automake
./configure
make
make install
用最新的openssl
编译mosquitto提示出错,‘EC_KEY’ undeclared
代码不支持老的openssl,所以宏定义提示找不到。
使用openssl-OpenSSL_1_1_0.zip版本
$ ./config
$ make
$ make install
代码不支持老的openssl,所以宏定义提示找不到。
使用openssl-OpenSSL_1_1_0.zip版本
其他程序会用到旧版的openssl,拷贝新的/usr/local/lib/libssl、/usr/local/lib/libcrypto到 /usr/lib/满足兼容
mosquitto使用
编译
make binary #只编译二进制文件,不编译man,否则会提示xml错误
src目录下生成mosquitto代理服务器
client目录下生成mosquitto_pub、mosquitto_sub 发布/订阅端。
编译出错一
: Error: Invalid user 'mosquitto'. 错误提示
编译出错二
warning: failed to load external entity "/usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl"
compilation error: file manpage.xsl line element import
xsl:import : unable to load /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl
compilation error: file mosquitto..xml line element refentry
解决出错一
adduser mosquitto
解决出错二
yum install docbook-style-xsl
修改 ./man/manpage.xsl第三行
href="/usr/share/sgml/docbook/xsl-stylesheets-1.75.2/manpages/docbook.xsl"/>
运行/client/mosquitto_pub -t sex -m woman 之后
mosquitto 代理端打印:
[root@localhost src]# ./mosquitto -v
: mosquitto version 1.4. (build date -- ::-) starting
: Using default config.
: Opening ipv4 listen socket on port .
: Opening ipv6 listen socket on port .
: New connection from :: on port .
: New client connected from :: as mosqpub/-localhost (c1, k60).
: Sending CONNACK to mosqpub/-localhost (, )
: Received PUBLISH from mosqpub/-localhost (d0, q0, r0, m0, 'sex', ... (5 bytes))
: Received DISCONNECT from mosqpub/-localhost
: Client mosqpub/-localhost disconnected.
运行/client/mosquitto_sub -t sex 之后
mosquitto 代理端打印:
: New connection from :: on port .
: New client connected from :: as mosqsub/-localhost (c1, k60).
: Sending CONNACK to mosqsub/-localhost (, )
: Received SUBSCRIBE from mosqsub/-localhost
: sex (QoS )
: mosqsub/-localhost sex
: Sending SUBACK to mosqsub/-localhost
mosquitto_sub 端收到订阅的消息:
[root@localhost client]# ./mosquitto_sub -v -t sex
sex woman
待续
.......