Linux 启动、关闭和重启 Apache 2 服务器命令

Linux 启动、关闭和重启 Apache 2 服务器命令
Linux 启动、关闭和重启 Apache 2 服务器命令

Apache 主要用于在万维网上提供静态内容和动态网页。许多 Web 应用程序的设计都期望 Apache 提供的环境和功能。可以在 Linux 或类 Unix 系统上使用以下任何一种方法启动或重新启动 Apache。

首先,使用 ssh 客户端登录到您的网络服务器,如果服务器不在您的本地数据中心: 登录后,根据您的 Linux 或 Unix 变体键入以下命令。

ssh root@your-server-com #Linode box
ssh ec2-user@aws-ip-here # AWS
ssh vivek@192.168.2.100 # My home dev server

在 Debian/Ubuntu 上启动/关闭/重启 Apache 的命令

在 Debian 7.x 版本或 Ubuntu 14.10 或更低版本上,使用 service 或 /etc/init.d/ 命令,如下所示:

重启 Apache 2 服务器:

# /etc/init.d/apache2 restart$ sudo /etc/init.d/apache2 restart$ sudo service apache2 restart

关闭 Apache 2 服务器:

# /etc/init.d/apache2 stop

$ sudo /etc/init.d/apache2 stop

$ sudo service apache2 stop

启动 Apache 2 服务器:

# /etc/init.d/apache2 start

$ sudo /etc/init.d/apache2 start

$ sudo service apache2 start

在 Debian/Ubuntu 中使用 systemctl 命令

在Debian 8.x+ 版本或 Ubuntu 15.04+版本使用 systemctl 命令:

## 启动命令##
systemctl start apache2.service
## 关闭命令 ##
systemctl stop apache2.service
## 重启命令 ##
systemctl restart apache2.servic

可以使用以下命令查看 apache2 状态:

$ sudo systemctl status apache2.service

将输出如下所示内容:

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-02-24 20:39:39 UTC; 5 days ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 115 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
    Process: 15247 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
   Main PID: 128 (apache2)
      Tasks: 6 (limit: 4672)
     Memory: 16.4M
     CGroup: /system.slice/apache2.service
             ├─  128 /usr/sbin/apache2 -k start
             ├─15254 /usr/sbin/apache2 -k start
             ├─15255 /usr/sbin/apache2 -k start
             ├─15256 /usr/sbin/apache2 -k start
             ├─15257 /usr/sbin/apache2 -k start
             └─15258 /usr/sbin/apache2 -k start

Feb 27 00:00:23 ubuntu-db-mgmnt systemd[1]: Reloaded The Apache HTTP Server.
Feb 28 00:00:23 ubuntu-db-mgmnt systemd[1]: Reloading The Apache HTTP Server.

在 CentOS/RHEL (Red Hat) 4.x/5.x/6.x 及更早版本

## 启动 ##
service httpd start
## 关闭 ##
service httpd stop
## 重启 ##
service httpd restart

在 CentOS/Fedora/RHEL (Red Hat) 7.x 及更新版本

大多数基于 RHEL 的 Linux 发行版都使用 systemd,因此可以使用 systemctl 命令: 

## 启动命令 ##
systemctl start httpd.service
## 关闭命令 ##
systemctl stop httpd.service
## 重启命令 ##
systemctl restart httpd.service

上述命令适用于 RHEL、CentOS、RockyLinux、Fedora 和 AlmaLinux 等系统。

在 Alpine 版本如何启动/关闭/重启 Apache 2

我们需要以 root 用户身份使用 service 命令:

# service apache2 start
# service apache2 stop
# service apache2 status
# service apache2 restar

Session:

 Stopping apache2 …
 Starting apache2 

FreeBSD 用户重启 Apache

FreeBSD 用户可以按如下方式重新启动 Apache:

# /usr/local/etc/rc.d/apache22 restart
# service restart apache22
# service stop apache22
# service start apache22

在 Linux/Unix 上启动/关闭/重启 Apache 的通用方法

首先,使用 type 命令或 command 命令查找 apachectl 或 apachectl2 路径: 

type -a apachectl
type -a apache2ctl

Ubuntu 20.04 LTS 服务器的输出:

apachectl is /usr/sbin/apachectl
apachectl is /sbin/apachectl

然后使用如下命令(必须以 root 用户运行): 

## stop it ##
apachectl -k stop
## restart it ##
apachectl -k restart
## graceful restart it ##
apachectl -k graceful
## Start it ##
apachectl -f /path/to/your/httpd.conf
apachectl -f /usr/local/apache2/conf/httpd.con

apachectl/apache2ctl 是 Apache 服务器的控制接口。其他选项如下:

启动 Apache 守护进程

apachectl start
# OR #
apache2ctl start

停止 Apache 守护进程

apachectl stop
# OR #
apache2ctl stop

重启 Apache 守护进程

apachectl restart
# OR #
apache2ctl restart

显示 mod_status 的完整状态

apachectl fullstatus
# OR #
apache2ctl fullstatus

显示简短的状态

apachectl status
# OR #
apache2ctl status

平滑重启 Apache 守护进程

apachectl graceful
# OR #
apache2ctl graceful


我们也可以平滑关闭 Apache httpd 守护进程:

apachectl graceful-stop
# OR #
apache2ctl graceful-stop

运行配置文件测试

apachectl configtest
# OR #
apache2ctl configtest

作者:牛奇网,本站文章均为辛苦原创,在此严正声明,本站内容严禁采集转载,面斥不雅请好自为之,本文网址:https://www.niuqi360.com/linux/linux-start-stop-restart-apache-2/

(0)
牛奇网牛奇网
上一篇 2022年1月8日 下午3:00
下一篇 2022年1月9日 上午9:39

发表回复

登录后才能评论
很多新手不知道如何选择外贸独立站主机,这里推荐一款使用量最大,性价比最高的国外独立站主机Hostinger,立即获取优惠