错误:无法写入 pid 文件 Mosquitto v2.0.3

Car*_*Mon 5 linux pid mqtt mosquitto

由于我在 Ubuntu 16.04 上更新了 Mosquitto v2.0.3,用户无法连接到代理。

\n

当我尝试运行/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf它时,抛出以下消息。\n2020-12-22|12:37:02: Error: Unable to write pid file.

\n

我看到有人有同样的问题,所以我添加了pid_file /var/run/mosquitto/mosquitto.pid 了 mosquitto 配置,但问题并没有消失。

\n

我有这个/lib/systemd/system/mosquitto.service

\n
[Unit]\nDescription=Mosquitto MQTT Broker\nDocumentation=man:mosquitto.conf(5) man:mosquitto(8)\nAfter=network.target\nWants=network.target\n\n[Service]\nType=notify\nNotifyAccess=main\nExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf\nExecReload=/bin/kill -HUP $MAINPID\nRestart=on-failure\nExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto\nExecStartPre=/bin/chown mosquitto: /var/log/mosquitto\nExecStartPre=/bin/mkdir -m 740 -p /var/run/mosquitto\nExecStartPre=/bin/chown mosquitto: /var/run/mosquitto\n\n[Install]\nWantedBy=multi-user.target\n
Run Code Online (Sandbox Code Playgroud)\n

mosquitto.conf 文件配置为:

\n
# Place your local configuration in /etc/mosquitto/conf.d/\n#\n# A full description of the configuration file is at\n# /usr/share/doc/mosquitto/examples/mosquitto.conf.example\n\npid_file /var/run/mosquitto/mosquitto.pid\n\npersistence true\npersistence_location /var/lib/mosquitto/\n\nlog_dest file /var/log/mosquitto/mosquitto.log\n\ninclude_dir /etc/mosquitto/conf.d\n\nlistener 1883\n\nlog_type error\nlog_type notice\nlog_type information\nlog_type debug\nlog_type all\nlog_dest topic \nlog_type warning\n\nallow_anonymous false\nconnection_messages true\nmax_keepalive 10\nlog_timestamp true\nlog_timestamp_format %Y-%m-%d|%H:%M:%S\n\npassword_file /etc/mosquitto/pwfile\n\n####################################################\n# MOSQUITTO LISTENER WITH SLL\n####################################################\n\nlistener 8883\nprotocol mqtt\nallow_anonymous false\n\n#PARA BROKER EN PC\ncafile /etc/mosquitto/certs/ca.crt\nkeyfile /etc/mosquitto/certs/server.key\ncertfile /etc/mosquitto/certs/server.crt\n\n#PARA BROKER EN RASPBERRY PI 3\n#cafile /etc/mosquitto/certs/ca_pi.crt\n#keyfile /etc/mosquitto/certs/server_pi.key\n#certfile /etc/mosquitto/certs/server_pi.crt\n\ntls_version tlsv1.2\n
Run Code Online (Sandbox Code Playgroud)\n

当我从终端运行 systemctl status mosquitto 时,它向我显示以下消息......

\n
\xe2\x97\x8f mosquitto.service - Mosquitto MQTT Broker\n   Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled; vendor preset: enabled)\n   Active: activating (auto-restart) (Result: exit-code) since mar 2020-12-22 13:06:13 -04; 5s ago\n     Docs: man:mosquitto(8)\n           man:mosquitto.conf(5)\n  Process: 22889 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)\n Main PID: 22889 (code=exited, status=1/FAILURE)\n\ndic 22 13:06:13 carmenmoncada systemd[1]: \n
Run Code Online (Sandbox Code Playgroud)\n

我不知道发生了什么事,有人可以帮助我吗?\n提前致谢\n问候。

\n

小智 8

须藤 mkdir -m 777 蚊子

请永远不要这样做!

就地尝试这个:

sudo mkdir /var/run/mosquitto/ && sudo chown mosquitto: /var/run/mosquitto
Run Code Online (Sandbox Code Playgroud)

并放入/etc/mosquitto/mosquitto.conf

...
pid_file /var/run/mosquitto/mosquitto.pid
...
Run Code Online (Sandbox Code Playgroud)


Car*_*Mon 1

伙计们,我已经找到了解决问题的方法。

我也设法让它发挥作用。我手动创建了一个/var/run/mosquitto拥有用户 mosquitto 所有权的目录,然后自动创建文件夹和文件。

  sudo mkdir -m 777 mosquitto
Run Code Online (Sandbox Code Playgroud)

在 mosquitto.conf 我设置

pid_file /var/run/mosquitto/mosquitto.pid
Run Code Online (Sandbox Code Playgroud)