FreeBSD 12 构建 mosquitto v2.0.10 + websockets + TLS + PostgreSQL认证
MQTT服务器需求
- 支持Websocket
- 支持命令行输出json输出
- 支持通过PostgreSQL认证用户
graph LR pg[(PostgreSQL)] auth(Auth plugin) mos([Mosquitto]) ws(LibWebsockets) c(MQTT Client) b(Web Browser) click auth "https://github.com/iegomez/mosquitto-go-auth" _blank click pg "https://www.postgresql.org/" "PostgreSQL 官方" _blank click mos "https://mosquitto.org/" "mosquitto 官方" _blank pg --- auth auth --- mos mos --- ws ws --- b mos --- c
源码
mosquitto 资源
官网源码包下载地址: https://mosquitto.org/download/
官方推荐认证扩展
https://github.com/iegomez/mosquitto-go-auth
编译
编译 mosquitto
安装依赖:
gmake
编译工具cmake
编译工具libcjson
命令行支持json格式输出依赖libwebsockets
websocket依赖
1 | pkg install gmake libcjson |
根据开发者描述:https://github.com/eclipse/mosquitto/issues/2060libwebsockets
高于v2.4.2
后会默认关闭LWS_WITH_EXTERNAL_POLL
选项.导致mosquitto
功能受损.
所以,要么选择低版本的libwebsockets
,要么重新手动编译高版本.
这里选择重新手动编译高版本,开启LWS_WITH_EXTERNAL_POLL
选项.
cmake
编译:
1 | git clone https://libwebsockets.org/repo/libwebsockets |
在
Unix
上编译时,需将CMakefile.txt
中的-Werror
项,删去!!!!
否则编译不了
1 | cd .. |
cmake
on MocOS1
2
3
4
5
6
7
8
9cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/opt/libwebsockets \
-DLWS_WITH_EXTERNAL_POLL=ON \
-DLWS_WITH_HTTP2=ON \
-DLWS_WITHOUT_TESTAPPS=ON \
-DLWS_UNIX_SOCK=ON \
-DLWS_IPV6=ON \
-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
../libwebsockets编译
gmake
编译:
配置config.mk
- WITH_WEBSOCKETS:=no -> yes
- WITH_CJSON:=yes
1 | gmake CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" |
cmake
编译:
1 | mkdir build |
- ‘cmake’ on MacOS
1
2
3
4
5
6
7
8cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/opt/mosquitto \
-DDOCUMENTATION=OFF \
-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
-DWITH_WEBSOCKETS=ON \
-E env LDFLAGS="-L/usr/local/opt/cjson/lib -L/usr/local/opt/libwebsockets/lib" \
-DCMAKE_C_FLAGS="-I/usr/local/opt/cjson/include -I/usr/local/opt/libwebsockets/include -I/usr/local/opt/openssl/include" \
../mosquitto编译 mosquitto-go-auth
安装依赖:
go
编译工具,此为golang
源码
1 | pkg install go |
配置国内源
1 | go env -w GO111MODULE=on |
编译
1 | gmake |
- 本文标题:FreeBSD 12 构建 mosquitto v2.0.10 + websockets + TLS + PostgreSQL认证
- 本文作者:jf wang
- 创建时间:2021-02-01 00:07:53
- 本文链接:https://www.wangjunfeng.com.cn/2021/02/01/build-mosquitto-on-freebsd/
- 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!