第一步:找出默认软件库上的Apache版本
为了查找Centos上软件库里的Apache版本,在命令行下输入以下指令:
yuminfohttpd
如果你的centos保持着默认的配置的话,你很可能会按到类似的结果:
[root@crosp~]#yuminfohttpd
Loadedplugins:fastestmirror
epel/x86_64/metalink|19kB00:00
epel|4.3kB00:00
(1/3):epel/x86_64/group_gz|170kB00:00
(2/3):epel/x86_64/primary_db|4.6MB00:00
(3/3):epel/x86_64/updateinfo|780kB00:00
Loadingmirrorspeedsfromcachedhostfile
*base:mirrors.ircam.fr
*epel:mirrors.ircam.fr
*extras:centos.mirror.fr.planethoster.net
*updates:centos.mirror.fr.planethoster.net
AvailablePackages
Name:httpd
Arch:x86_64
Version:2.4.6
Release:45.el7.centos.4
Size:2.7M
Repo:updates/7/x86_64
Summary:ApacheHTTPServer
URL:http://httpd.apache.org/
License:ASL2.0
Description:TheApacheHTTPServerisapowerful,efficient,andextensible
:webserver.
正如你从上面的输出结果中看到,默认软件库中只有2.4.6版本的apache。
注意:
Centos使用向后修复安全实践来将新的软件修复应用到更早期的版本。所以,默认库中的早期版本软件不意味着就更脆弱。不过对于我来说,并不算是个满足需求的更新。
你可以使用changelog来查看版本更新:
1sudoyuminstallyum-changelog
2.yumchangeloghttpd
第二步:安装CodeIT库
CodeIT的人提供了一个很好的自定义库。这个库提供了最新版本的服务器软件(Apache&Nginx)。
在安装CodeIT库之前,你需要开启EPEL。EPEL提供了CodeIT库需要的依赖。
3.sudoyuminstall-yepel-release
最后,我们来安装CodeIT库
4.cd/etc/yum.repos.d&&wgethttps://repo.codeit.guru/codeit.el`rpm-q--qf"%{VERSION}"$(rpm-q--whatprovidesredhat-release)`.repo
接下来,我们再次确认Apache的包版本,你应该会看到类似下面的输出
[root@crosp~]#yuminfohttpd
Loadedplugins:changelog,fastestmirror
Loadingmirrorspeedsfromcachedhostfile
*base:centos.crazyfrogs.org
*epel:mirror.23media.de
*extras:mirrors.ircam.fr
*updates:centos.mirror.fr.planethoster.net
AvailablePackages
Name:httpd
Arch:x86_64
Version:2.4.25
Release:3.el7.codeit
Size:1.4M
Repo:CodeIT/x86_64
Summary:ApacheHTTPServer
URL:http://httpd.apache.org/
License:ASL2.0
Description:TheApacheHTTPServerisapowerful,efficient,andextensible
:webserver.
第三步:安装Apache
现在你应该有了安装最新版apache所需要的所有东西:
5.yuminstallhttpd
6.Isthisok[y/d/N]y
一旦Apache安装好,我们就可以测试apache是否正常工作:
[root@crosp~]#systemctlstarthttpd
输出应该是类似下图:
[root@crosp~]#curllocalhost
...
最后,让systemctl将Apache设置为开机自启动:
[root@crosp~]#systemctlenablehttpd