CentOS系统环境搭建(八)——CentOS7开机自动执行脚本(以MySQL为例)

CentOS7开机自动执行脚本

文章目录

以MySQL为例子

第一步:新建一个脚本run.sh

/srv下新建system文件夹

bash 复制代码
cd /srv
bash 复制代码
mkdir system

新建脚本run.sh

bash 复制代码
vim run.sh

run.sh内容如下

bash 复制代码
#! /bin/bash
# 开机运行下列指令

# 安全模式启动mysql
/usr/local/mysql8/bin/mysqld_safe --defaults-file=/usr/local/etc/my.cnf &

第二步:脚本添加可执行权限

bash 复制代码
chmod +x run.sh

第三步:执行如下命令将/etc/rc.d/rc.local文标记为可执行文件

bash 复制代码
chmod +x /etc/rc.d/rc.local

第四步:打开/etc/rc.d/rc.local文件,在最后面添加要执行脚本

bash 复制代码
vim /etc/rc.d/rc.local

>/dev/null 2>&1 将所有输出重定向到空设备,即不输出日志。最后的 & 符号将命令放到后台运行。

bash 复制代码
bash /srv/system/run.sh >/dev/null 2>&1 &
相关推荐
orion5716 小时前
Missing Semester Class1:course overview and introduction of shell
linux
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
这个DBA有点耶1 天前
SQL改写进阶:标量子查询的“隐形代价”与消除实战
数据库·mysql·架构
smallyoung1 天前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·mysql·postgresql
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
数据技术说1 天前
MySQL 迁移实战——如何实现真正的"零改造"平滑切换
mysql
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia3 天前
linux curl命令详解_curl详解
linux
扛枪的书生3 天前
Linux 网络管理器用法速查
linux