1. 可以修改开机启动文件/etc/rc.local,把需要开机启动的命令贴上去
随开机启动的文件有:
/etc/profile、/root/.bash_profile
/etc/bashrc、/root/.bashrc
/etc/profile.d/*.sh、/etc/profile.d/lang.sh
/etc/sysconfig/i18n、/etc/rc.local
2. 将写好的脚本放到/etc/profile.d/下
将编辑好的脚本(.sh文件)放到目录/etc/profile.d/下,系统启动后就会自动执行该目录下的所有shell脚本。
3. 通过chkconfig命令设置
chkconfig是用于把服务加到开机自动启动列表里,只要启动它,就能自动启动,重启后永久生效即:
chkconfig --add COMMAND
chkconfig COMMAND on/off 重启后永久生效
4. 通过Systemctl管理
查看所有已启动的服务
[root@localhost ~]# systemctl list-units --type=service
设置开机自启动
[root@localhost ~]# systemctl enable nginx.service
[root@localhost ~]# systemctl start nginx.service
停止开机自启动
[root@localhost ~]# systemctl disable nginx.service
[root@localhost ~]# systemctl stop nginx.service
查看nginx服务当前状态
[root@localhost ~]# systemctl status nginx.service
验证一下是否为开机启动
[root@localhost ~]# systemctl is-enabled nginx
当然nginx.service可以自定义