编辑 etc/rc.local
如果文件存在直接在 exit 0 前面加启动命令,如果文件不存在,新建一个,粘贴以下内容,在 exit 0 前面加启动命令
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
用以下命令使其生效
sudo chown root:root /etc/rc.local
sudo chmod 755 /etc/rc.local
sudo systemctl enable rc-local.service