systemctl start xxxxx.service命令无法正常启动服务

项目场景:

在Linux系统下,源码包解压安装了Keepalived服务,安装完后使用systemctl start keepalived.service命令启动服务未能成功启动服务。


问题描述:

运行了systemctl start keepalived.service命令启动服务;

然后使用ps -aux | grep keepalived 查看服务启动情况;

输出结果为:

root     21068  0.0  0.0 112812   976 pts/0    S+   17:04   0:00 grep --color=auto keepalived

这是服务没有运行起来呀。


原因分析:

运行systemctl status keepalived.service命令查看服务状态;

输出结果为:

● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2021-03-23 16:36:49 CST; 6s ago
  Process: 20699 ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=7)

Mar 23 16:36:49 tinghs systemd[1]: Starting LVS and VRRP High Availability Monitor...
Mar 23 16:36:49 tinghs Keepalived[20699]: Starting Keepalived v2.2.2 (03/05,2021)
Mar 23 16:36:49 tinghs systemd[1]: keepalived.service: control process exited, code=exited status=7
Mar 23 16:36:49 tinghs systemd[1]: Failed to start LVS and VRRP High Availability Monitor.
Mar 23 16:36:49 tinghs systemd[1]: Unit keepalived.service entered failed state.
Mar 23 16:36:49 tinghs systemd[1]: keepalived.service failed.

Mar 23 16:36:49 tinghs systemd[1]: Failed to start LVS and VRRP High Availability Monitor.

这个是它报红的一行。

使用journalctl -xe 命令查看详细信息;

输出结果为:

Mar 23 16:36:49 tinghs Keepalived[20699]: Starting Keepalived v2.2.2 (03/05,2021)
Mar 23 16:36:49 tinghs Keepalived[20699]: Running on Linux 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 (built for Linux 3.10.0)
Mar 23 16:36:49 tinghs Keepalived[20699]: Command line: '/usr/local/keepalived/sbin/keepalived' '-D'
Mar 23 16:36:49 tinghs Keepalived[20699]: CPU usage (self/children) user: 0.001035/0.000000 system: 0.014492/0.000000
Mar 23 16:36:49 tinghs Keepalived[20699]: Stopped Keepalived v2.2.2 (03/05,2021)
Mar 23 16:36:49 tinghs systemd[1]: keepalived.service: control process exited, code=exited status=7
Mar 23 16:36:49 tinghs systemd[1]: Failed to start LVS and VRRP High Availability Monitor.
-- Subject: Unit keepalived.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit keepalived.service has failed.
--
-- The result is failed.
Mar 23 16:36:49 tinghs systemd[1]: Unit keepalived.service entered failed state.
Mar 23 16:36:49 tinghs systemd[1]: keepalived.service failed.
Mar 23 16:36:49 tinghs polkitd[685]: Unregistered Authentication Agent for unix-process:20693:165200446 (system bus name :1.1022, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)

Mar 23 16:36:49 tinghs Keepalived[20699]: Command line: ‘/usr/local/keepalived/sbin/keepalived’ ‘-D’

从这一行可以看出,启动服务时没有指定配置文件。

我们去查看一下/usr/lib/systemd/system/keepalived.service 文件,运行 cat /usr/lib/systemd/system/keepalived.service命令;

输出结果为:

[Unit]
Description=LVS and VRRP High Availability Monitor
After=network-online.target syslog.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/keepalived.pid
KillMode=process
EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived
ExecStart=/usr/local/keepalived/sbin/keepalived  $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived

根据这一行去寻找 config , 运行 cat /usr/local/keepalived/etc/sysconfig/keepalived 命令;

输出结果为:

# Options for keepalived. See `keepalived --help' output and keepalived(8) and
# keepalived.conf(5) man pages for a list of all options. Here are the most
# common ones :
#
# --vrrp               -P    Only run with VRRP subsystem.
# --check              -C    Only run with Health-checker subsystem.
# --dont-release-vrrp  -V    Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs  -I    Dont remove IPVS topology on daemon stop.
# --dump-conf          -d    Dump the configuration data.
# --log-detail         -D    Detailed log messages.
# --log-facility       -S    0-7 Set local syslog facility (default=LOG_DAEMON)
#

KEEPALIVED_OPTIONS="-D"

KEEPALIVED_OPTIONS="-D"

重点就是上面这一行了;


解决方案:

运行 vi /usr/local/keepalived/etc/sysconfig/keepalived 命令,shift+G 将光标移动至文件末尾,点击 i ,将文件改为:

# Options for keepalived. See `keepalived --help' output and keepalived(8) and
# keepalived.conf(5) man pages for a list of all options. Here are the most
# common ones :
#
# --vrrp               -P    Only run with VRRP subsystem.
# --check              -C    Only run with Health-checker subsystem.
# --dont-release-vrrp  -V    Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs  -I    Dont remove IPVS topology on daemon stop.
# --dump-conf          -d    Dump the configuration data.
# --log-detail         -D    Detailed log messages.
# --log-facility       -S    0-7 Set local syslog facility (default=LOG_DAEMON)


#KEEPALIVED_OPTIONS="-D"

# 根据个人安装的目录指定keepalived配置文件
KEEPALIVED_OPTIONS="-f /usr/local/keepalived/etc/keepalived/keepalived.conf -D -S 0"

点击 Esc ,输入:wq ,点击Enter,保存并退出。

再次运行systemctl start keepalived.service命令启动服务,就可以启动成功了。

systemctl 服务相关命令

# 重新加载服务
systemctl daemon-reload  
# 启动服务
systemctl start keepalived.service 
# 停止服务
systemctl stop keepalived.service
# 重启服务
systemctl restart keepalived.service 
# 查看服务状态
systemctl status keepalived.service
# 设置开机自动启动服务
systemctl enable keepalived.service  
# 取消开机自动启动服务
systemctl disable keepalived.service 
# 查看服务是否开机启动
systemctl is-enabled keepalived.service
# 查看已启动的服务列表
systemctl list-unit-files|grep enabled
# 查看启动失败的服务列表
systemctl --failed

猜你喜欢

转载自blog.csdn.net/baidu_41847368/article/details/115130770
今日推荐