centos7开机自启动

方法一 rc.local文件

1.先创建一个简单的脚本,输出当前文件的时间

touch outNowTime.sh

#!/bin/bash

date > /root/nowTime.txt

2.编辑文件

vi /etc/rc.d/rc.local

# !/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/root/outNowTime.sh &

/root/outNowTime.sh & 这里一定要加 &

3.给文件权限

chmod +x /etc/rc.d/rc.local
chmod +x /root/outNowTime.sh

一些错误

在开放web端口的时候可能会访问不通,那么可以选择开放端口或者永久关闭防火墙
查看防火墙状态
systemctl status firewalld.service
关闭防火墙
systemctl stop firewalld.service
永久关闭防火墙
systemctl disable firewalld.service
如果遇到了centos重启后卡在进度条的情况下,可以进入单用户模式,暂时把rc.local后台自启动的命令注释或者删除掉
在这里插入图片描述

开机时,大概启动到这里按"E"键,也可以提前就按着。
在这里插入图片描述
然后再这个位置加入 init=/bin/bash
在这里插入图片描述
然后按 ctrl+x 进入单用户模式
然后编辑rc.local的时候可能会遇到权限不够,输入如下命令即可编辑
在这里插入图片描述
mount -o remount,rw /
重新编辑你的rc.local文件后重启后就好了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值