您的位置:首页 > 理论基础 > 计算机网络

CentOS 7安装httpd服务

2017-05-25 22:49 127 查看
书写此博文的前提:在学习[b]CentOS 7中,发现在安装httpd服务的时候,老是报错,不和CentOS 6的命令相同,在网上查了很多资料以后,找到一个很好的解决办法,发表出来,大家共同学习。[/b]1、安装httpd软件包查看是否安装httpd服务 [root@localhost ~]rpm –qa | grep http如果没有安装[root@localhost ~] yum –y install httpd(或者通过yum search httpd选择安装的httpd版本) 针对CentOS7,httpd有专门的版本,此版本提供了针对systemd的单元文件,如下所示 [root@localhost ~]rpm -ql httpd | grep service
/usr/lib/systemd/system/htcacheclean.service
/usr/lib/systemd/system/httpd.service
[b]在自己安装httpd以后,使用systemctl status httpd.service命令,会发现如下问题,httpd服务未打开:[/b][b]

[/b]这是解决途径: 2、启动httpd服务并把此服务单元加入当前运行级亲测在CentOS7中,必须把服务加入服务单元中,否则无法正常访问,在加入防火墙中,还是最好加入。[root@localhost ~]systemctl start httpd.service #开启httpd服务[root@localhost ~]systemctl enable httpd 此时,这个配置文件被链接到了/etc/systemd/system/multi-user.target.wants/httpd.service,如下图

[root@localhost ~] # ll /etc/systemd/system/multi-user.target.wants/

显示httpd服务已加入 3、打开firewalld防火墙的80端口[root@localhost ~]firewall-cmd--add-service=http (即时打开)[root@localhost ~]firewall-cmd --permanent --add-service=http (写入配置文件)

此时,httpd这个服务添加到了/etc/firewalld/zones/public.xml这个zone配置文件中,所以firewalld才能够据此放行。此文件如下所示:<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the othercomputers on networks to not harm your computer. Only selected incomingconnections are accepted.</description>
<service name="dhcpv6-client"/>
<service name="http"/>
<servicename="ssh"/>
<service name="https"/>
</zone>经过这么几步的操作,再使用systemctl status httpd.service命令

此时用浏览器就能顺利打开网址
再次感谢http://blog.csdn.net/smstong/article/details/39343543的博文作者smstong
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息