centos7.x使用yum安装nginx

前端之家收集整理的这篇文章主要介绍了centos7.x使用yum安装nginx前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前置工作:

安装必要的库(Nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库)

ps:我的centos7自带就有上面的三个库,安装前可以用rpm命令检查一下看是否已经安装过

[root@mylsql local]# rpm -q pcre
pcre-8.32-15.el7_2.1.x86_64
[root@mylsql local]# rpm -q openssl
openssl-1.0.1e-60.el7.x86_64
[root@mylsql local]# rpm -q zlib
zlib-1.2.7-17.el7.x86_64

step1:

先执行下面的命令创建这个文件

vim /etc/yum.repos.d/Nginx.repo

step2:

输入下面的内容

[Nginx]
name=Nginx repo
baseurl=http://Nginx.org/packages/centos/7/$basearch/
#如果是centos6.x的则只需要将baseurl的值修改为http://Nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

step3:

执行安装命令

yum install Nginx -y

注意:

可能会出现如下图的错误

直接执行命令

rm -f /var/run/yum.pid

然后再执行上面的安装命令就可以了:执行成功会如下结果

[root@mylsql local]# yum install Nginx -y
已加载插件:fastestmirror,langpacks
base                                                                                                                                                                                                                                                   | 3.6 kB  00:00:00     
extras                                                                                                                                                                                                                                                 | 3.4 kB  00:00:00     
Nginx                                                                                                                                                                                                                                                  | 2.9 kB  00:00:00     
updates                                                                                                                                                                                                                                                | 3.4 kB  00:00:00     
(1/5): Nginx/x86_64/primary_db                                                                                                                                                                                                                         |  31 kB  00:00:15     
(2/5): base/7/x86_64/group_gz                                                                                                                                                                                                                          | 156 kB  00:00:48     
(3/5): extras/7/x86_64/primary_db                                                                                                                                                                                                                      | 128 kB  00:00:48     
base/7/x86_64/primary_db       Failed                                                                                    29% [================================-                                                                             ]  12 kB/s | 2.9 MB  00:09:48 ETA 
http://mirrors.btte.net/centos/7.4.1708/os/x86_64/repodata/0c34273ad0292747ee5e15c047d3e51c67ca59861a446972db45d71abacc7ad7-primary.sqlite.bz2: [Errno 14] curl#18 - "transfer closed with 4671133 bytes remaining to read"                 ]  12 kB/s | 2.9 MB  00:09:48 ETA 
正在尝试其它镜像。
updates/7/x86_64/primary_db    Failed                                                                                    55% [=============================================================                                                 ]  11 kB/s | 5.3 MB  00:06:27 ETA 
http://mirrors.btte.net/centos/7.4.1708/updates/x86_64/repodata/f39c1c5dc25223bad94e56068531b5a5710acdd2e604fa560a925c65d3f50cfc-primary.sqlite.bz2: [Errno 14] curl#18 - "transfer closed with 1090213 bytes remaining to read"            ]  11 kB/s | 5.3 MB  00:06:27 ETA 
正在尝试其它镜像。
(4/5): updates/7/x86_64/primary_db                                                                                                                                                                                                                     | 3.6 MB  00:03:06     
base/7/x86_64/primary_db       Failed                                                                                    83% [============================================================================================                  ]  11 kB/s | 8.0 MB  00:02:26 ETA 
http://mirrors.163.com/centos/7.4.1708/os/x86_64/repodata/0c34273ad0292747ee5e15c047d3e51c67ca59861a446972db45d71abacc7ad7-primary.sqlite.bz2: [Errno 14] curl#18 - "transfer closed with 1636415 bytes remaining to read"                  ]  11 kB/s | 8.0 MB  00:02:26 ETA 
正在尝试其它镜像。
(5/5): base/7/x86_64/primary_db                                                                                                                                                                                                                        | 5.7 MB  00:02:18     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 Nginx.x86_64.1.1.12.2-1.el7_4.ngx 将被 安装
--> 正在处理依赖关系 libcrypto.so.10(OPENSSL_1.0.2)(64bit),它被软件包 1:Nginx-1.12.2-1.el7_4.ngx.x86_64 需要
--> 正在检查事务
---> 软件包 openssl-libs.x86_64.1.1.0.1e-60.el7 将被 升级
--> 正在处理依赖关系 openssl-libs(x86-64) = 1:1.0.1e-60.el7,它被软件包 1:openssl-1.0.1e-60.el7.x86_64 需要
---> 软件包 openssl-libs.x86_64.1.1.0.2k-8.el7 将被 更新
--> 正在检查事务
---> 软件包 openssl.x86_64.1.1.0.1e-60.el7 将被 升级
---> 软件包 openssl.x86_64.1.1.0.2k-8.el7 将被 更新
--> 解决依赖关系完成

依赖关系解决

==============================================================================================================================================================================================================================================================================
 Package                                                            架构                                                         版本                                                                       源                                                           大小
==============================================================================================================================================================================================================================================================================
正在安装:
 Nginx                                                              x86_64                                                       1:1.12.2-1.el7_4.ngx                                                       Nginx                                                       716 k
为依赖而更新:
 openssl                                                            x86_64                                                       1:1.0.2k-8.el7                                                             base                                                        492 k
 openssl-libs                                                       x86_64                                                       1:1.0.2k-8.el7                                                             base                                                        1.2 M

事务概要
==============================================================================================================================================================================================================================================================================
安装  1 软件包
升级           ( 2 依赖软件包)

总下载量:2.4 M
Downloading packages:
No Presto Metadata available for base
警告:/var/cache/yum/x86_64/7/base/packages/openssl-1.0.2k-8.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature,密钥 ID f4a80eb5: NOKEY=====================================================================-                                       ]  11 kB/s | 1.5 MB  00:01:15 ETA 
openssl-1.0.2k-8.el7.x86_64.rpm 的公钥尚未安装
(1/3): openssl-1.0.2k-8.el7.x86_64.rpm                                                                                                                                                                                                                 | 492 kB  00:02:21     
(2/3): Nginx-1.12.2-1.el7_4.ngx.x86_64.rpm                                                                                                                                                                                                             | 716 kB  00:02:55     
(3/3): openssl-libs-1.0.2k-8.el7.x86_64.rpm                                                                                                                                                                                                            | 1.2 MB  00:03:35     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                                                                                           11 kB/s | 2.4 MB  00:03:35     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 软件包     : centos-release-7-3.1611.el7.centos.x86_64 (@anaconda)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : 1:openssl-libs-1.0.2k-8.el7.x86_64                                                                                                                                                                                                                        1/5 
  正在更新    : 1:openssl-1.0.2k-8.el7.x86_64                                                                                                                                                                                                                             2/5 
  正在安装    : 1:Nginx-1.12.2-1.el7_4.ngx.x86_64                                                                                                                                                                                                                         3/5 
----------------------------------------------------------------------

Thanks for using Nginx!

Please find the official documentation for Nginx here:
* http://Nginx.org/en/docs/

Please subscribe to Nginx-announce mailing list to get
the most important news about Nginx:
* http://Nginx.org/en/support.html

Commercial subscriptions for Nginx are available on:
* http://Nginx.com/products/

----------------------------------------------------------------------
  清理        : 1:openssl-1.0.1e-60.el7.x86_64                                                                                                                                                                                                                            4/5 
  清理        : 1:openssl-libs-1.0.1e-60.el7.x86_64                                                                                                                                                                                                                       5/5 
  验证中      : 1:Nginx-1.12.2-1.el7_4.ngx.x86_64                                                                                                                                                                                                                         1/5 
  验证中      : 1:openssl-libs-1.0.2k-8.el7.x86_64                                                                                                                                                                                                                        2/5 
  验证中      : 1:openssl-1.0.2k-8.el7.x86_64                                                                                                                                                                                                                             3/5 
  验证中      : 1:openssl-libs-1.0.1e-60.el7.x86_64                                                                                                                                                                                                                       4/5 
  验证中      : 1:openssl-1.0.1e-60.el7.x86_64                                                                                                                                                                                                                            5/5 

已安装:
  Nginx.x86_64 1:1.12.2-1.el7_4.ngx                                                                                                                                                                                                                                           

作为依赖被升级:
  openssl.x86_64 1:1.0.2k-8.el7                                                                                                       openssl-libs.x86_64 1:1.0.2k-8.el7                                                                                                      

完毕!
[root@mylsql local]#

成功之后运行Nginx

systemctl start Nginx

记得查看下80端口是否已经打开

firewall-cmd --zone=public --list-port

结果如下

如果没有开启端口则需要添加端口

[root@mylsql local]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@mylsql local]# firewall-cmd --reload
success

端口开启了,Nginx也运行了,接下来可以访问这台服务器的ip了

安装到此结束:

过程错误总结:

由于我们公司有专门的运维人员,所以操作系统,服务器系统都不需要我们自己装;然后我没先确认一下操作系统的版本,centos7安装了centos6.5的Nginx出l了各种问题

查看版本的命令

[root@mylsql local]# cat /proc/version
Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016

查看Nginx各个文件:

rpm -ql Nginx

这里包括Nginx所有文件的位置

原文链接:https://www.f2er.com/centos/375441.html

猜你在找的CentOS相关文章