2023年11月28日发(作者:)

CentOS7设置nginx开机⾃启动

前⾔

服务器每次重启,都需要⼿动启动⼀些服务,这不是⼀个程序员可以忍受的,难怪⼤家都喜欢写脚本。接下来三篇⽂章,分别记录⼀下nginx、

tomcat和mysql的开机⾃启动配置。

systemd

systemd简介

CentOS7已不再使⽤chkconfig管理启动项,⽽是使⽤systemd。关于systemd的衍⽣和发展,可以参见《CentOS7/RHEL7 systemd详

解》《CentOS7进程管理systemd详解》。简单介绍如下:

Linux系统从启动到提供服务的过程是这样,先是机器加电,然后通过MBR或者UEFI加载GRUB,再启动内核,内核启动服务,然后开始对外服

systemctl list-unit-files | grep enable,查看⾃启动的软件。

systemctl is-enabled e,查看某个单元是否开机启动。

systemctl status e,查看某个单元的状态。

systemctl start e,启动某个单元。

systemctl restart e,重启某个单元。

systemctl stop e,停⽌某个单元。

mkdir-p /var/temp/run/nginx

chmod a+wrx -R temp

curl localhost

浏览器如果不能访问,就打开防⽕墙或者开端⼝。

关闭防⽕墙,systemctl stop e

开放端⼝,firewall-cmd --zone=public --add-port=80/tcp --permanent,firewall-cmd --reload

设置开机启动

ExecStart为服务的具体运⾏命令

ExecReload为重启命令