Debian/Ubuntu系统 mosquitto移植记录

Debian/Ubuntu系统 mosquitto移植记录

时间:2021年4月21日

一、debian/ubuntu 官方源安装

发现debian/ubuntu官方源仓库里有mosquitto,所以最简洁方便的方法就是使用apt-get直接安装

第一步需要安装mosquitto依赖(uuid 和 openssl)

sudo apt-get install uuid-dev
sudo apt-get install openssl

接下来安装 mosquitto

sudo apt-get install mosquitto
sudo apt-get install mosquitto-dev
sudo apt-get install mosquitto-clients

二、mosquitto的移植

1、先下载源码包

wget http://mentors.debian.net/debian/pool/main/m/mosquitto/mosquitto_1.4.10.orig.tar.gz

或者官网下载(待补充)

2、解压,打开config.mk文件,在文件顶部添加

CC=arm-linux-gnueabihf-gcc
CXX=arm-linux-gnueabihf-g++
CPP=arm-linux-gnueabihf-gcc
AR=arm-linux-gnueabihf-ar
LD=arm-linux-gnueabihf-ld

文件末尾的prefix=需要输出路径

INSTALL?=install
prefix?=安装路径
incdir?=${prefix}/include
libdir?=${prefix}/lib/${LIB_SUFFIX}
localedir?=${prefix}/share/locale
mandir?=${prefix}/share/man
STRIP?=arm-linux-gnueabihf-strip

3、根据要求选择config.mk的选项

WTITH_TLS:=no 
WITH_TLS_PSK:=no
WITH_SRV:=no
WITH_UUID:=no

需要这些选项改成yes,前提是需要外部库的支持
4、编译

make && makeinstall

5、移植到开发板:

cp bin/mosquitto_* /bin/
cp sbin/mosquitto /sbin/
cp lib/libmosquitto* /usr/bin

6、开发板中运行

mosquitto &

7、查看mosquitto进程

ps -ef | grep mosquitto

将mosquitto加入service中自启动

1、在/etc/init.d/中创建mosquitto脚本文件

#! /bin/sh
### BEGIN INIT INFO
# Provides:             mosquitto
# Required-Start:       $remote_fs $syslog
# Required-Stop:        $remote_fs $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    mosquitto MQTT v3.1 message broker
# Description: 
#  This is a message broker that supports version 3.1 of the MQ Telemetry
#  Transport (MQTT) protocol.
#  
#  MQTT provides a method of carrying out messaging using a publish/subscribe
#  where a sensor or other simple device may be implemented using an arduino for
#  example.
### END INIT INFO
PIDFILE=/var/run/mosquitto.pid
DAEMON=/usr/sbin/mosquitto
# /etc/init.d/mosquitto: start and stop the mosquitto MQTT message broker
test -x ${DAEMON} || exit 0
umask 022
. /lib/lsb/init-functions
# Are we running from init?
run_by_init() {
    ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
}
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
case "$1" in
  start)
        if init_is_upstart; then
            exit 1
        fi
        log_daemon_msg "Starting network daemon:" "mosquitto"
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;
  stop)
        if init_is_upstart; then
        log_daemon_msg "Stopping network daemon:" "mosquitto"
        if start-stop-daemon --stop --quiet --oknodo --pidfile ${PIDFILE}; then
            log_end_msg 0
            log_end_msg 1
        fi
        ;;
  reload|force-reload)
        if init_is_upstart; then
            exit 1
        fi
        log_daemon_msg "Reloading network daemon configuration:" "mosquitto"
        if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PIDFILE; then
            log_end_msg 0
        else
            log_end_msg 1
  restart)
        if init_is_upstart; then
        log_daemon_msg "Restarting network daemon:" "mosquitto"
        if start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${PIDFILE}; then
            rm -f ${PIDFILE}
        fi
            log_end_msg 0
        else
            log_end_msg 1
        fi
        ;;
  try-restart)
        if init_is_upstart; then
            exit 1
        fi
        log_daemon_msg "Restarting Mosquitto message broker" "mosquitto"
        set +e
        start-stop-daemon --stop --quiet --retry 30 --pidfile ${PIDFILE}
        RET="$?"
        set -e
        case $RET in
            0)
                # old daemon stopped
                rm -f ${PIDFILE}
                    log_end_msg 0
                else
                    log_end_msg 1
                fi
                ;;
            1)
                # daemon not running
                log_progress_msg "(not running)"
                log_end_msg 0
                ;;
            *)
                # failed to stop
                log_progress_msg "(failed to stop)"
                log_end_msg 1
                ;;
        esac
        ;;
  status)
        if init_is_upstart; then
            exit 1
        fi
        status_of_proc -p ${PIDFILE} ${DAEMON} mosquitto && exit 0 || exit $?
        ;;
  *)
        log_action_msg "Usage: /etc/init.d/mosquitto {start|stop|reload|force-reload|restart|try-restart|status}"
        exit 1
esac
exit 0

2、移植/etc/moquitto 目录
(包含ca_certificates 、certs 、conf.d 、mosquitto.conf)
之前存在mosquitto.conf文件需要 添加
user root(root 根据/var/log/mosquitto的所属用户修改)
< mosquitto.conf >

# Place your local configuration in /etc/mosquitto/conf.d/
# 
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
user root   
pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

3、添加/lib/systemd/system/mosquitto.service文件(已有适当修改)
user=root (根据 /var/lib/mosquitto文件所属用户修改)

[Unit]
Description=Mosquitto MQTT v3.1/v3.1.1 Broker
Documentation=man:mosquitto(8)
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
User=root

[Install]
WantedBy=multi-user.target

接下来就可以使用服务systemctl查看状态以及开启关闭了

systemctl status mosquitto
systemctl start mosquitto
systemctl stop mosquitto

记录一次mosquitto的移植过程,踩了好多坑,最后终于成功!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
imx6ul应用开发资料。卷序列号为 A899-5E01 H:. │ FCU1101嵌入式控制单元支持功能项列表-2018.10.18.xlsx │ 文件夹目录.txt │ 文件夹目录名批列出.bat │ ├─Linux │ ├─应用 │ │ │ 系统常用命令.pdf │ │ │ │ │ ├─485 │ │ │ 485-test │ │ │ 485-test.c │ │ │ │ │ ├─lora-EC32-TTL-100 │ │ │ │ E32_Demo.zip │ │ │ │ E32_Usermanual_CN_1.40.pdf │ │ │ │ lora.pdf │ │ │ │ RF_Setting.Form1.resources │ │ │ │ RF_Setting.Properties.Resources.resources │ │ │ │ RF_Setting3.47.exe │ │ │ │ RF_Setting3.47.zip │ │ │ │ SX1278无线模块LoRa扩频技术文档(433M亿佰特E32-TTL-100) (1).pdf │ │ │ │ │ │ │ └─Sscom32 │ │ │ sscom.ini │ │ │ sscom32.exe │ │ │ 注意事项.txt │ │ │ │ │ ├─modbus │ │ │ │ libmodbus-3.1.2.tar.gz │ │ │ │ ul-modbus测试.txt │ │ │ │ │ │ │ ├─库文件 │ │ │ │ m3.tar.bz2 │ │ │ │ │ │ │ └─测试程序 │ │ │ unit-test-client │ │ │ unit-test-server │ │ │ │ │ ├─mosquitto │ │ │ │ mosquitto-1.5.tar.gz │ │ │ │ mqtt协议移植总结.pdf │ │ │ │ openssl-1.0.2h.tar.gz │ │ │ │ │ │ │ └─移植到开发板上 │ │ │ install_mosquitto.tar.bz2 │ │ │ install_openssl.tar.bz2 │ │ │ │ │ ├─socket │ │ │ │ build.sh │ │ │ │ eth0_server.c │ │ │ │ eth1_server.c │ │ │ │ Makefile │ │ │ │ Makefile.arm │ │ │ │ socket_client.c │ │ │ │ socket测试.pdf │ │ │ │ │ │ │ ├─bin │ │ │ │ └─arm │ │ │ │ client │ │ │ │ client.sh │ │ │ │ server.sh │ │ │ │ server1 │ │ │ │ server2 │ │ │ │ │ │ │ └─源码 │ │ │ build.sh │ │ │ eth0_server.c │ │ │ eth1_server.c │ │ │ Makefile │ │ │ Makefile.arm │ │ │ socket_client.c │ │ │ │ │ ├─tcpdump │ │ │ │ libpcap-1.8.1.tar.gz │ │ │ │ tcpdump-4.9.2.tar.gz │ │ │ │ │ │ │ └─移植到开发板 │ │ │ tcpdump.tar.bz2 │ │ │ │ │ ├─TFTP与NFS服务器搭建 │ │ │ TFTP与NFS服务器搭

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值