方式一:通过CodeIT库升级
1、找出默认软件库上的Apache版本
查看已安装Apache版本
[root@yun ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Jun 27 2018 13:48:59
为了查找Centos上软件库里的Apache版本,在命令行下输入以下指令:
[root@yun ~]# yum info httpd
Loaded plugins: changelog, fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: ftp.jaist.ac.jp
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: uk.repo.webtatic.com
Installed Packages
Name : httpd
Arch : x86_64
Version : 2.4.6
Release : 80.el7.centos.1
Size : 9.4 M
Repo : installed
From repo : updates
Summary : Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
Available Packages
Name : httpd
Arch : x86_64
Version : 2.4.6
Release : 93.el7.centos
Size : 2.7 M
Repo : base/7/x86_64
Summary : Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
从上面的输出结果中看到,默认软件库中只有2.4.6版本的apache.
2、安装CodeIT库
CodeIT的人提供了一个很好的自定义库。这个库提供了最新版本的服务器软件(Apache & Nginx)。
在安装CodeIT库之前,需要开启 EPEL 。EPEL提供了CodeIT库需要的依赖。
[root@yun ~]# yum install -y epel-release
最后,我们来安装CodeIT库
[root@yun ~]# cd /etc/yum.repos.d && wget https://repo.codeit.guru/codeit.el`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)`.repo
接下来,我们再次确认Apache的包版本,你应该会看到类似下面的输出
[root@yun yum.repos.d]# yum info httpd
Loaded plugins: changelog, fastestmirror
CodeIT | 2.9 kB 00:00
CodeIT/x86_64/primary_db | 57 kB 00:09
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: ftp.jaist.ac.jp
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: uk.repo.webtatic.com
Installed Packages
Name : httpd
Arch : x86_64
Version : 2.4.6
Release : 80.el7.centos.1
Size : 9.4 M
Repo : installed
From repo : updates
Summary : Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
Available Packages
Name : httpd
Arch : x86_64
Version : 2.4.46
Release : 1.codeit.el7
Size : 1.4 M
Repo : CodeIT/x86_64
Summary : Apache HTTP Server
URL : https://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
3、升级Apache
现在直接使用 yum update升级即可:
[root@yun yum.repos.d]# yum update httpd
一旦Apache安装好,我们就可以启动apache
[root@yun yum.repos.d]# systemctl start httpd