Linux设置开机启动任务

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可以自定义

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值