InfluxDB 无法作为服务启动

InfluxDB 无法作为服务启动

我正在尝试在 RHEL7 机器上配置 InfluxDB 以实现自动启动。

如果我做:

sudo systemctl start influxdb

服务失败

[dadmin@localhost dashboard]$ sudo systemctl start influxdb
[sudo] password for dadmin: 
[dadmin@localhost dashboard]$ sudo systemctl status influxdb
● influxdb.service - InfluxDB is an open-source, distributed, time series database
   Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/influxdb.service.d
           └─override.conf
   Active: failed (Result: start-limit) since Thu 2017-05-11 13:16:29 CEST; 10s ago
     Docs: https://docs.influxdata.com/influxdb/
  Process: 2562 ExecStart=/usr/bin/influxd -config /dashboard/influxdb.conf ${INFLUXD_OPTS} (code=exited, status=1/FAILURE)
 Main PID: 2562 (code=exited, status=1/FAILURE)

May 11 13:16:29 localhost.localdomain systemd[1]: influxdb.service: main process exited, code=exited, status=1/FAILURE
May 11 13:16:29 localhost.localdomain systemd[1]: Unit influxdb.service entered failed state.
May 11 13:16:29 localhost.localdomain systemd[1]: influxdb.service failed.
May 11 13:16:29 localhost.localdomain systemd[1]: influxdb.service holdoff time over, scheduling restart.
May 11 13:16:29 localhost.localdomain systemd[1]: start request repeated too quickly for influxdb.service
May 11 13:16:29 localhost.localdomain systemd[1]: Failed to start InfluxDB is an open-source, distributed, time series database.
May 11 13:16:29 localhost.localdomain systemd[1]: Unit influxdb.service entered failed state.
May 11 13:16:29 localhost.localdomain systemd[1]: influxdb.service failed.

这是单元文件:

[dadmin@localhost dashboard]$ sudo systemctl cat influxdb.service
[sudo] password for dadmin: 
# /usr/lib/systemd/system/influxdb.service
# If you modify this, please also make sure to edit init.sh

[Unit]
Description=InfluxDB is an open-source, distributed, time series database
Documentation=https://docs.influxdata.com/influxdb/
After=network-online.target

[Service]
User=influxdb
Group=influxdb
LimitNOFILE=65536
EnvironmentFile=-/etc/default/influxdb
ExecStart=/usr/bin/influxd -config /etc/influxdb/influxdb.conf ${INFLUXD_OPTS}
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=multi-user.target
Alias=influxd.service

# /etc/systemd/system/influxdb.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/influxd -config /dashboard/influxdb.conf ${INFLUXD_OPTS}

但如果我直接执行

/usr/bin/influxd -config /dashboard/influxdb.conf

InfluxDB启动顺利。

我哪里错了?

答案1

我发现了问题:

[dadmin@localhost dashboard]$ sudo tail /var/log/messages
May 11 16:21:41 localhost influxd: [I] 2017-05-11T14:21:41Z Using data dir: /dashboard/influxdb/data service=store
May 11 16:21:41 localhost influxd: run: open server: open tsdb store: open /dashboard/influxdb/data/_internal: permission denied
May 11 16:21:41 localhost systemd: influxdb.service: main process exited, code=exited, status=1/FAILURE
May 11 16:21:41 localhost systemd: Unit influxdb.service entered failed state.
May 11 16:21:41 localhost systemd: influxdb.service failed.
May 11 16:21:41 localhost systemd: influxdb.service holdoff time over, scheduling restart.
May 11 16:21:41 localhost systemd: start request repeated too quickly for influxdb.service
May 11 16:21:41 localhost systemd: Failed to start InfluxDB is an open-source, distributed, time series database.
May 11 16:21:41 localhost systemd: Unit influxdb.service entered failed state.
May 11 16:21:41 localhost systemd: influxdb.service failed.

当我执行完

/usr/bin/influxd -config /dashboard/influxdb.conf

这些文件夹的所有者是 dadmin

我删除了文件夹并重新启动了服务。现在一切正常。

答案2

配置脚本没有权限。

它引用目录。当您运行 /opt/influxdb/influxd config > /etc/opt/influxdb/influxdb.conf 时,输出的配置文件会将所有目录放在 ~ 下。当您是 root 时,~ 会转换为 /root。

如果您不想使用 /root 作为您的 InfluxDB 数据目录,那么有几个选项。

以您想要运行 influxd 的用户身份运行 /opt/influxdb/influxd config > /etc/opt/influxdb/influxdb.conf。然后配置文件将使用该用户的主目录作为安装位置。明确编辑 /etc/opt/influxdb/influxdb.conf 以引用您想要使用的目录。

另请查看博客这可能会帮你解决

答案3

您可以将用户和组更改为 root

[dadmin@localhost dashboard]$ sudo systemctl cat influxdb.service
[sudo] password for dadmin: 
# /usr/lib/systemd/system/influxdb.service
# If you modify this, please also make sure to edit init.sh

[Unit]
Description=InfluxDB is an open-source, distributed, time series database
Documentation=https://docs.influxdata.com/influxdb/
After=network-online.target

[Service]
User=root
Group=root
LimitNOFILE=65536
EnvironmentFile=-/etc/default/influxdb
ExecStart=/usr/bin/influxd -config /etc/influxdb/influxdb.conf ${INFLUXD_OPTS}
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=multi-user.target
Alias=influxd.service

# /etc/systemd/system/influxdb.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/influxd -config /dashboard/influxdb.conf ${INFLUXD_OPTS}

相关内容