启动nginx报错Failed to start nginx.service: Unit is not loaded properly: Bad message

1.报错分析

使用创建服务脚本:

vi /usr/lib/systemd/system/nginx.service
systemctl daemon-reload
systemctl start nginx.service

报错是因为我的配置文件:
/usr/lib/systemd/system/nginx.service没有被按正确格式编写导致。改好之后重新加载就可以了.
具体问题分析一下。

通过报错日志看第2行、第8行、第9行报错。主要是我在编写nginx.service文件时,把第2行的单词“Description”写成“Descri ption”了,第8行的单词“ExecStartPre”写成“ExecstartPre”,还有第9行的ExecStartPre的“-t -c ”后面的内容“/usr/local/nginx/conf/nginx.conf”不能换行。

2.正确的nginx.service内容

[Unit]
Description=nginx - web server
After=network.targt

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

修改完脚本后执行命令:

systemctl daemon-reload
systemctl start nginx.service
systemctl status nginx.service

执行成功后查看运行状态:

最后设置开机自启:

systemctl enable nginx.service

参考地址:

https://www.cnblogs.com/pengsay/p/16206920.html

Failed to start nginx.service: Unit is not loaded properly: Bad message-CSDN博客

[root@Docker-register ~]# systemctl list-units --type=service --state=running UNIT LOAD ACTIVE SUB DESCRIPTION auditd.service loaded active running Security Auditing Service chronyd.service loaded active running NTP client/server couchbase-server.service loaded active running Couchbase Server crond.service loaded active running Command Scheduler dbus.service loaded active running D-Bus System Message Bus docker.service loaded active running Docker Application Container Engine getty@tty1.service loaded active running Getty on tty1 gssproxy.service loaded active running GSSAPI Proxy Daemon irqbalance.service loaded active running irqbalance daemon lvm2-lvmetad.service loaded active running LVM2 metadata daemon metricbeat.service loaded active running Metricbeat is a lightweight shipper for metrics. NetworkManager.service loaded active running Network Manager polkit.service loaded active running Authorization Manager postfix.service loaded active running Postfix Mail Transport Agent rhnsd.service loaded active running LSB: Starts the Spacewalk Daemon rhsmcertd.service loaded active running Enable periodic update of entitlement certificates. rpcbind.service loaded active running RPC bind service rsyslog.service loaded active running System Logging Service sshd.service loaded active running OpenSSH server daemon systemd-journald.service loaded active running Journal Service systemd-logind.service loaded active running Login Service systemd-udevd.service loaded active running udev Kernel Device Manager tuned.service loaded active running Dynamic System Tuning Daemon vgauthd.service loaded active running VGAuth Service for open-vm-tools vmtoolsd.service loaded active running Service for virtual machines hosted on VMware zabbix-agent.service loaded active running Zabbix Agent LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 26 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
最新发布
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值