Linux配置开机自启动服务

背景

Linux服务器存在重启的情况,服务器重启后原来在跑的服务就停止了,由于服务器重启是个随机事件,因此需要配置在重启后自动开启一些服务。

本篇文章对于Linux发行版Debian和Red Hat。

实现

1、配置启动脚本

进入目录: /etc/init.d/ ,编写要开机启动的脚本 custom-service.sh

#!/bin/sh
#chkconfig: 345 95 95
#description: custom-service

RDS_HOME=/root/app/rds
sh $RDS_HOME/bin/startup.sh
2、使用chkconfig命令配置添加custom-service.sh至自启动服务
[root@localhost init.d]# chkconfig --add custom-service.sh
[root@localhost init.d]# chkconfig custom-service.sh on
[root@localhost init.d]# chkconfig custom-service.sh --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

custom-service.sh       0:关    1:关    2:开    3:开    4:开    5:开    6:关
[root@localhost init.d]#

3、修改脚本custom-service.sh文件权限
[root@localhost init.d]# chmod 777 custom-service.sh
4、重启服务器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值