systemd 里有 rc-local.service ,只需要再写一个 rc.local 的脚本即可。

1、编辑 /usr/lib/systemd/system/rc-local.service 文件:

[Unit]

Description=/etc/rc.d/rc.local Compatibility

After=network.target

 

[Service]

Type=forking

ExecStart=/etc/rc.d/rc.local start

TimeoutSec=0

RemainAfterExit=yes

SysVStartPriority=99


[Install]

WantedBy=multi-user.target


其中 Install 那部分是自己写的,multi-user.target 代表3级别,graphical.target 代表5级别。


2、编辑 /etc/rc.d/rc.local 文件:

# cat /etc/rc.d/rc.local

#!/bin/bash

xxxxxxxxxx 代表自定义内容,设置开机启动


3、给 /etc/rc.d/rc.local 可执行权限:

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

4、开启 rc-local.service 服务:

#systemctl   enable   rc-local.service

#systemctl   --system  daemon-reload

#systemctl   start  rc-local.service