Linux重启服务器设置程序自启;

本文介绍了如何在Linux系统中通过修改/etc/rc.d/rc.local文件实现服务的开机自启。内容包括:打开并编辑rc.local文件,添加自启脚本,确保文件有执行权限,并进行重启测试。在测试中发现服务未自启,检查了文件权限和脚本问题。通过赋予rc.local文件执行权限和检查脚本内容,确保服务能在开机时正确启动。

重启设置

在 /etc/rc.d/rc.local 文件服务器重启后会被执行是用于添加开机启动命令,/etc/rc.local是/etc/rc.d/rc.local的软连接,软连接相当于windows的快捷键

打开rc.local文件

# /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

# 自启 禅道 服务
/opt/zbox/zbox  start

# 自启 service 应用服务
/opt/app/service/bin/start.sh

在/var/lock/subsys/ 下创建local文件

作用:
检验rc.local是否执行过,执行过的话就会有local文件(默认没有执行)

重启测试

[root@xxx ~]# reboot

问题

1.服务未自启

#要执行的脚本没有执行权限,变更权限
[root@xxx ~]# chmod 775 /ext/rc.d/rc.local

2.再次确认/etc/rc.d/rc.local文件有执行权限

[root@xxx ~]# ls /etc/rc.local
[root@xxx ~] lrwxrwxrwx 1 root root 13 mar 9 19:30 /etc/rc.local -> rc.d/rc.local
若没有执行权限,需赋予
[root@xxx ~]# chmod 775 /etc/rc.local

3.最后检查脚本是否有问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值