Rootop 服务器运维与web架构

Amazon linux 2023没有/etc/rc.local文件

系统为 Amazon linux 2023

[root@rootop ~]# cat /etc/os-release 
NAME="Amazon Linux"
VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2023"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="Amazon Linux 2023"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
HOME_URL="https://aws.amazon.com/linux/"
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
SUPPORT_END="2028-03-01"

系统里已经没有 /etc/rc.local 文件,没法实现开机启动nginx,但是系统里提供了一个systemd服务叫 rc-local.service

[root@rootop ~]# cat /usr/lib/systemd/system/rc-local.service 

[Unit]
Description=/etc/rc.d/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

# 注意下面这2行默认是没有的,需要加上,否则不能使用 systemctl enable 实现开机运行,执行时会提示没有 installation config 
[Install]
WantedBy=multi-user.target

通过配置文件可以看到是执行了/etc/rc.d/rc.local脚本,这个脚本默认也没有,需要自己创建,并加上执行权限。

[root@rootop ~]# cat /etc/rc.d/rc.local 
#!/bin/bash
/home/software/openresty/nginx/sbin/nginx

[root@rootop ~]# chmod 777 /etc/rc.d/rc.local 

[root@rootop ~]# systemctl start rc-local
[root@rootop ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1632/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1507/sshd: /usr/sbi 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1632/nginx: master  
tcp6       0      0 :::22                   :::*                    LISTEN      1507/sshd: /usr/sbi 

[root@rootop ~]# systemctl enable rc-local
Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /usr/lib/systemd/system/rc-local.service.

重启系统测试效果。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/5287.html

作者:Venus

服务器运维与性能优化

评论已关闭。