centos 7 将rc.local配置成服务

1.权限设置(/etc/rc.local和/etc/rc.d/rc.local都须要赋予执行权限)redis

chmod +x /etc/rc.d
chmod +x /etc/rc.d/rc.local

2.设置服务启动脚本。
1)进入路径centos

cd /usr/lib/systemd/system

2)编辑服务脚本服务器

vi rc-local.service

删除以前的全部数据,导入如下数据。ide

##This file is part of systemd.
#systemd is free software; you can redistribute it and/or modify it
#under the terms of the GNU Lesser General Public License as published by
#the Free Software Foundation; either version 2.1 of the License, or
#(at your option) any later version.

#This unit gets pulled automatically into multi-user.target by
#systemd-rc-local-generator if /etc/rc.d/rc.local is executable.
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

3.使用命令启动服务(确认服务可用)3d

systemctl start rc-localcode

使用systemctl -t service查看服务器全部服务的状态,确认服务rc-local.service是否运行正常.
4.执行systemctl enable rc-localblog

systemctl enable rc-local

出现如下提示表示成功添加开机自启动:
Created symlink from /etc/systemd/system/multi-user.target.wants/rc-local.service to /usr/lib/systemd/system/rc-local.service.ip

以下图:
centos 7 将rc.local配置成服务get

完成以上步骤就能够将开机自动执行的命令写入/etc/rc.d/rc.local中,实现开机自动执行。generator

相关文章
相关标签/搜索