没有可用软件包httpd_CentOS 7安装httpd服务

书写此博文的前提:在学习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才能够据此放行。此文件如下所示:

Public

For use in public areas. You do not trust the othercomputers on networks to not harm your computer. Only selected incomingconnections are accepted.

经过这么几步的操作,再使用systemctl status httpd.service命令

此时用浏览器就能顺利打开网址

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值