龙空技术网

如何在centos7系统实现用rc.local来管理开机自启动脚本

波波说运维 436

前言:

此时你们对“centos指定启动系统”大致比较注意,朋友们都需要分析一些“centos指定启动系统”的相关知识。那么小编在网络上网罗了一些有关“centos指定启动系统””的相关资讯,希望兄弟们能喜欢,兄弟们一起来学习一下吧!

概述

centos7后新的Linux发行版已经没有rc.local文件了,因为已经将其服务化了。那么如果我们还是想用rc.local文件来管理的话可以怎么解决呢?下面介绍下一个解决方式,仅供参考。

1、设置rc-local.service

# vim /etc/systemd/system/rc-local.service=====================================================[Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local[Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99[Install] WantedBy=multi-user.target=====================================================#chmod u+x /etc/systemd/system/rc-local.service
2、激活rc-local.service
systemctl daemon-reloadsystemctl enable rc-local.service
3、添加启动服务

手工创建或者拷贝已有的/etc/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

我们只需要把想开机启动的脚本写到里面就可以了。

觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~

标签: #centos指定启动系统