CentOS7 最小化安装后,安装配置并启动httpd的步骤
2014-09-17 15:54
766 查看
记录供查阅
针对CentOS7,httpd有专门的版本,此版本提供了针对systemd的单元文件,如下所示
-bash-4.2# rpm -ql httpd | grep service
/usr/lib/systemd/system/htcacheclean.service
/usr/lib/systemd/system/httpd.service
systemctl enable httpd
此时,这个配置文件被链接到了/etc/systemd/system/multi-user.target.wants/httpd.service,如下图
-bash-4.2# ll /etc/systemd/system/multi-user.target.wants/
total 0
lrwxrwxrwx. 1 root root 38 Sep 16 19:08 auditd.service -> /usr/lib/systemd/system/auditd.service
lrwxrwxrwx. 1 root root 44 Sep 16 19:08 avahi-daemon.service -> /usr/lib/systemd/system/avahi-daemon.service
lrwxrwxrwx. 1 root root 37 Sep 16 19:08 crond.service -> /usr/lib/systemd/system/crond.service
lrwxrwxrwx. 1 root root 37 Sep 17 02:38 httpd.service -> /usr/lib/systemd/system/httpd.service
lrwxrwxrwx. 1 root root 42 Sep 16 19:08 irqbalance.service -> /usr/lib/systemd/system/irqbalance.service
lrwxrwxrwx. 1 root root 37 Sep 16 19:08 kdump.service -> /usr/lib/systemd/system/kdump.service
lrwxrwxrwx. 1 root root 46 Sep 16 19:08 NetworkManager.service -> /usr/lib/systemd/system/NetworkManager.service
lrwxrwxrwx. 1 root root 39 Sep 16 19:08 postfix.service -> /usr/lib/systemd/system/postfix.service
lrwxrwxrwx. 1 root root 40 Sep 16 19:08 remote-fs.target -> /usr/lib/systemd/system/remote-fs.target
lrwxrwxrwx. 1 root root 39 Sep 16 19:08 rsyslog.service -> /usr/lib/systemd/system/rsyslog.service
lrwxrwxrwx. 1 root root 36 Sep 16 19:08 sshd.service -> /usr/lib/systemd/system/sshd.service
lrwxrwxrwx. 1 root root 37 Sep 16 19:08 tuned.service -> /usr/lib/systemd/system/tuned.service
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 other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="dhcpv6-client"/>
<service name="http"/>
<service name="ssh"/>
<service name="https"/>
</zone>
注意不要将此处firewalld管理的service与systemd中的sevice配置单元混淆,两者没有任何关系。
http服务是安装firewalld时自动安装的,这个服务的配置文件为 /usr/lib/firewalld/services/http.xml,我们来看看这个文件。
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>WWW (HTTP)</short>
<description>HTTP is the protocol used to serve Web pages. If you plan to make your Web server publicly available, enable this option. This option is not required for viewing pages locally or developing Web pages.</description>
<port protocol="tcp" port="80"/>
</service>
据此知道http服务对应的就是tcp协议的80端口。firewalld根据zone配置文件中的服务名http,依次在/etc/firwalld/services/目录,/usr/lib/firewalld/services/目录查找名为http.xml的文件,找到即停止继续查找,所以位于/etc/firwalld/services/目录的配置文件优先级更高。
1 安装httpd软件包
yum install httpd针对CentOS7,httpd有专门的版本,此版本提供了针对systemd的单元文件,如下所示
-bash-4.2# rpm -ql httpd | grep service
/usr/lib/systemd/system/htcacheclean.service
/usr/lib/systemd/system/httpd.service
2 启动httpd服务并把此服务单元加入当前运行级
systemctl start httpd.servicesystemctl enable httpd
此时,这个配置文件被链接到了/etc/systemd/system/multi-user.target.wants/httpd.service,如下图
-bash-4.2# ll /etc/systemd/system/multi-user.target.wants/
total 0
lrwxrwxrwx. 1 root root 38 Sep 16 19:08 auditd.service -> /usr/lib/systemd/system/auditd.service
lrwxrwxrwx. 1 root root 44 Sep 16 19:08 avahi-daemon.service -> /usr/lib/systemd/system/avahi-daemon.service
lrwxrwxrwx. 1 root root 37 Sep 16 19:08 crond.service -> /usr/lib/systemd/system/crond.service
lrwxrwxrwx. 1 root root 37 Sep 17 02:38 httpd.service -> /usr/lib/systemd/system/httpd.service
lrwxrwxrwx. 1 root root 42 Sep 16 19:08 irqbalance.service -> /usr/lib/systemd/system/irqbalance.service
lrwxrwxrwx. 1 root root 37 Sep 16 19:08 kdump.service -> /usr/lib/systemd/system/kdump.service
lrwxrwxrwx. 1 root root 46 Sep 16 19:08 NetworkManager.service -> /usr/lib/systemd/system/NetworkManager.service
lrwxrwxrwx. 1 root root 39 Sep 16 19:08 postfix.service -> /usr/lib/systemd/system/postfix.service
lrwxrwxrwx. 1 root root 40 Sep 16 19:08 remote-fs.target -> /usr/lib/systemd/system/remote-fs.target
lrwxrwxrwx. 1 root root 39 Sep 16 19:08 rsyslog.service -> /usr/lib/systemd/system/rsyslog.service
lrwxrwxrwx. 1 root root 36 Sep 16 19:08 sshd.service -> /usr/lib/systemd/system/sshd.service
lrwxrwxrwx. 1 root root 37 Sep 16 19:08 tuned.service -> /usr/lib/systemd/system/tuned.service
3 打开firewalld防火墙的80端口
firewall-cmd --add-service=http (即时打开)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 other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="dhcpv6-client"/>
<service name="http"/>
<service name="ssh"/>
<service name="https"/>
</zone>
注意不要将此处firewalld管理的service与systemd中的sevice配置单元混淆,两者没有任何关系。
http服务是安装firewalld时自动安装的,这个服务的配置文件为 /usr/lib/firewalld/services/http.xml,我们来看看这个文件。
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>WWW (HTTP)</short>
<description>HTTP is the protocol used to serve Web pages. If you plan to make your Web server publicly available, enable this option. This option is not required for viewing pages locally or developing Web pages.</description>
<port protocol="tcp" port="80"/>
</service>
据此知道http服务对应的就是tcp协议的80端口。firewalld根据zone配置文件中的服务名http,依次在/etc/firwalld/services/目录,/usr/lib/firewalld/services/目录查找名为http.xml的文件,找到即停止继续查找,所以位于/etc/firwalld/services/目录的配置文件优先级更高。
4 与CentOS6.5的区别
总体思路是一致的,都是防火墙放行,把服务加入运行级配置文件。只是CentOS7中防火墙和运行级管理程序均发生彻底改变了。firewalld代替iptables,systemd代替SystemV init,所以需要重新熟悉相关命令。个人感觉新的程序更加人性化,操作也很容易。 配置文件也都采用了标准的xml格式,放弃了容易出错的老式配置文件。相关文章推荐
- CentOS7 最小化安装后,安装配置并启动httpd的步骤
- centos7最小化安装后配置笔记
- centOS7最小化安装配置网络
- centos7安装mysql5.7脚本并配置开机启动
- Centos7系统安装设置网络、防火墙配置、自动启动配置
- CentOS7安装配置mysql5.7详细步骤
- CentOS7最小化安装 配置NODE.JS环境
- Centos6.5最小化安装:配置网络和自启动服务
- Centos7安装配置tomcat9并设置自动启动的方法
- CentOS7最小化安装配置IP
- centos7 最小化安装后配置
- 【绝对能用】阿里云ECS上Centos7安装Apache(httpd)并实现多域名转不同tomcat配置
- CentOS7最小化安装 配置NODE.JS环境
- Centos7安装配置tomcat 9并设置自动启动
- 关于virtualBox中最小化安装CentOS7系统,更改httpd.conf中的DocumentRoot之后访问出现Forbidden的问题
- virtualbox 最小化安装centos7 配置双网卡(nat和桥接)记录----已经过期
- CentOS6.5下redis3.0.7安装、启动、关闭、配置密码、开机启动详细步骤
- CentOS7最小化安装配置
- 解决最小化安装Centos7后无法上网的问题,以及安装成功后的基本配置
- centos7 apache httpd安装和配置django项目