如何在Linux下启动、停止、重启和管理apacheweb服务器?

Apache或apache2是internet上最流行的web服务器。我们已经设置了Apache服务器并进行了一些配置更改,我们希望激活这些更改。要激活更改,必须重新启动Apache服务器。在本文中,我们将研究如何在Ubuntu和CentOS中以不同的方式重新启动Apache。

null

用systemctl命令启动Apache

Systemctl是一个用于管理Linux服务、操作系统状态、运行级别等的工具。Systemctl非常流行,目前支持CentOS、Fedora和Ubuntu作为默认服务管理器。

Ubuntu、Debian、Mint、Kali:

$ sudo systemctl restart apache2
Start Apache with systemctl Command
用systemctl命令启动Apache

CentOS,软呢帽:

$ sudo systemctl restart httpd

如果我们看一下状态行的开头 我们可以看到Apache2服务是在5秒前启动的。用systemctl命令重新启动Apache2的另一种方法可能更复杂,即先停止服务,然后再启动它。

Ubuntu、Debian:

$ sudo systemctl stop apache2$ sudo systemctl start apache2
Start Apache with systemctl Command
用systemctl命令启动Apache

CentOS,软呢帽:

$ sudo systemctl stop httpd$ sudo systemctl start httpd

使用apachectl命令启动并重新启动Apache

重新启动apache2服务的另一种方法是使用本机工具apachectl。apachectl的语法如下所示。

apachectl COMMAND

我们可以在apachectl中使用restart命令。

$ sudo apachectl restart
Start and Restart Apache with apachectl Command
使用apachectl命令启动并重新启动Apache

正如我们看到的,apachectl也提供了重启操作日志。

使用Init.rc脚本启动并重新启动Apache

Apache在/etc/init.d下提供了init.rc相关的守护进程控制脚本。这些脚本也可以用来重新启动Apache。

Ubuntu、Debian:

$ sudo /etc/init.d/apache2 restart

CentOS,软呢帽:

$ sudo /etc/init.d/httpd restart

我们也需要根权限才能使用这个init.rc脚本。重新启动后脚本提供有关重新启动操作的信息。在本例中,似乎所有操作都没有问题。

相关文章: 如何在Linux、Ubuntu、Debian、CentOS、Fedora上安装和配置MongoDB NoSQL数据库

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享