配置密码认证时,蚊子启动失败



我有一只蚊子在树莓派上完美地运行直到配置密码认证。

这是我在启动蚊子时的错误:

> pi@pi3:/etc/systemd/system $ systemctl status mosquitto.service
● mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2023-04-02 11:29:12 CEST; 18s ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Process: 1178 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUC>
Process: 1179 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUC>
Process: 1180 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 1181 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 1182 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, st>
Main PID: 1182 (code=exited, status=3)
CPU: 64ms
>
>Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Apr 02 11:29:12 pi3 systemd[1]: Stopped Mosquitto MQTT Broker.
Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Start request repeated too quickly.
Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Apr 02 11:29:12 pi3 systemd[1]: Failed to start Mosquitto MQTT Broker.
...skipping...
● mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2023-04-02 11:29:12 CEST; 18s ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Process: 1178 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUC>
Process: 1179 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUC>
Process: 1180 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 1181 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 1182 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, st>
Main PID: 1182 (code=exited, status=3)
CPU: 64ms
>
>Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Apr 02 11:29:12 pi3 systemd[1]: Stopped Mosquitto MQTT Broker.
Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Start request repeated too quickly.
Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Apr 02 11:29:12 pi3 systemd[1]: Failed to start Mosquitto MQTT Broker.
~
~
~
~
~
~
~
...skipping...
● mosquitto.service - Mosquitto MQTT Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2023-04-02 11:29:12 CEST; 18s ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Process: 1178 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUC>
Process: 1179 ExecStartPre=/bin/chown mosquitto /var/log/mosquitto (code=exited, status=0/SUC>
Process: 1180 ExecStartPre=/bin/mkdir -m 740 -p /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 1181 ExecStartPre=/bin/chown mosquitto /run/mosquitto (code=exited, status=0/SUCCESS)
Process: 1182 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, st>
Main PID: 1182 (code=exited, status=3)
CPU: 64ms
>
>Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 5.
Apr 02 11:29:12 pi3 systemd[1]: Stopped Mosquitto MQTT Broker.
Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Start request repeated too quickly.
Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Failed with result 'exit-code'.
Apr 02 11:29:12 pi3 systemd[1]: Failed to start Mosquitto MQTT Broker.
~
~
~
~
~
>
>pi@pi3:/etc/systemd/system $ journalctl -xe
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ Automatic restarting of the unit mosquitto.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
Apr 02 11:29:12 pi3 systemd[1]: Stopped Mosquitto MQTT Broker.
░░ Subject: A stop job for unit mosquitto.service has finished
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A stop job for unit mosquitto.service has finished.
░░ 
░░ The job identifier is 2938 and the job result is done.
Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Start request repeated too quickly.
Apr 02 11:29:12 pi3 systemd[1]: mosquitto.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit mosquitto.service has entered the 'failed' state with result 'exit-code'.
Apr 02 11:29:12 pi3 systemd[1]: Failed to start Mosquitto MQTT Broker.
░░ Subject: A start job for unit mosquitto.service has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit mosquitto.service has finished with a failure.
░░ 
░░ The job identifier is 2938 and the job result is failed.

以下是我的配置文件:来自mosquito的信息与README中的信息略有不同…

pi@pi3:/etc/mosquitto $ cat 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
pid_file /run/mosquitto/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
listener 1883
pi@pi3:/etc/mosquitto $ ls conf.d
harold.conf  notsecur.conf  README

有人知道我的设置有什么问题吗?

这些信息有帮助吗?

pi@pi3:/etc/mosquitto/conf.d $ sudo mosquitto -c /etc/mosquitto/mosquitto.conf
1680461082: Loading config file /etc/mosquitto/conf.d/harold.conf
1680461082: Error: Unknown configuration variable      "harold:$7$101$FQZWHiGkvnVWZKHs$vaiDEiJh09sH/KTRF7gOR4rFnn5hEbvBXqAMJFF  P74BHtg==".
1680461082: Error found at /etc/mosquitto/conf.d/harold.conf:1.
1680461082: Error found at /etc/mosquitto/mosquitto.conf:13.

pi@pi3:/etc/mosquitto/conf.d $ sudo cat /var/log/mosquitto/mosquitto.log | tail -20
1680446446: Config loaded from /etc/mosquitto/mosquitto.conf.
1680446446: Opening ipv4 listen socket on port 1883.
1680446446: Opening ipv6 listen socket on port 1883.
1680446446: mosquitto version 2.0.11 running
1680447269: mosquitto version 2.0.11 starting
1680447269: Config loaded from /etc/mosquitto/mosquitto.conf.
1680447269: Opening ipv4 listen socket on port 1883.
1680447269: Opening ipv6 listen socket on port 1883.
1680447269: mosquitto version 2.0.11 running
1680449361: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1680451162: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1680452963: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1680454764: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1680456565: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1680458366: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1680460167: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1680461035: mosquitto version 2.0.11 starting
1680461035: Config loaded from /etc/mosquitto/mosquitto.conf.
1680461035: Opening ipv4 listen socket on port 1883.
1680461035: Error: Address already in use

harold.conf文件已经生成:-c harold.conf harold

pi@pi3:/etc/mosquitto/conf.d $ sudo cat harold.conf && cat notsecur.conf 
harold:$7$101$FQZWHiGkvnVWZKHs$...4BHtg==
#listener 1883
allow_anonymous true

我认为"per_listener_settings "缺少参数。现在我成功了。但是配置非常棘手。

你不能像harold.conf那样在配置文件中包含用户名/密码对。

从mosquito .conf man页:

password_file文件路径

设置路径为密码文件。如果定义了该文件,则该文件的内容将用于控制客户机对代理的访问。文件可以是使用mosquito - to_passwd(1)实用程序创建。如果蚊子是在不支持TLS的情况下编译(建议使用TLS支持)包含),那么密码文件应该是包含每行的文本文件格式为"username:password"冒号和密码所在可选但推荐使用。如果allow_anonymous设置为false,则只有在此文件中定义的用户将能够连接。设置当password_fileis定义有效时,Allow_anonymous变为true可以与acl_file一起使用,例如只读guest/anonymous可以发布的帐户和定义用户

用户名/密码对需要在他们自己的特定文件中,并从上面描述的配置文件中引用。

您需要将harold.conf文件重命名并移动到/etc/mosquitto/passwd,然后编辑notsecur.conf以读取:

password_file /etc/mosquitto/passwd
allow_anonymous false

设置allow_anonymous false将允许您正确测试提供的用户名/密码是否正确。

相关内容

  • 没有找到相关文章

最新更新