書寫此博文的前提:在學習CentOS 7中,發現在安裝httpd服務的時候,老是報錯,不和CentOS 6的命令相同,在網上查了很多資料以後,找到一個很好的解決辦法,發表出來,大家共同學習。
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
在自己安裝httpd以後,使用systemctl status httpd.service命令,會發現如下問題,httpd服務未打開:
這是解決途徑:
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。