centos 安装 nginx

7-12 1,663 views

由于单独下载nginx安装,还需要先安装pcre,openssl以及zlib,较为复杂,所以本文主要介绍使用yum安装nginx的过程,一共有两种方法来安装,一种是按照nginx官网介绍的安装方法,第二种是先安装epel 源,然后利用epel来安装nginx。

先介绍第一种方法:

 官网链接 http://nginx.org/en/linux_packages.html  已经介绍了如何安装,这里简单解释一下

To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “5”, “6”, or “7”, for 5.x, 6.x, or 7.x versions, respectively.

 

(1)这里需要在/etc/yum.repos.d/这个目录下,新建一个nginx.repo文件,然后输入上面说的那些内容,下面贴出我本地的内容:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/6/$basearch/
gpgcheck=0
enabled=1

这里主要是把os替换成rhel,然后把linux的版本也写上,本次操作是Centos6,所以这里写6,如果是Centos7系统的话,这里就写7,这里的rhel写成centos也可以。

(2)有了这个文件后,直接使用yum search nginx,就可以把nginx搜索出来,即:

nginx

 

(3)然后直接输入  yum install nginx -y 安装即可。最终看到安装最后出现complete! 即表示安装完成,安装完成后,nginx被安装在了  /etc/nginx 这个目录,而且配置文件分开存放,在这个目录下的nginx.conf存放的主配置文件,它会加载conf.d目录下的所有文件,如图:

nginxconf

第二种方法:

需要先安装epel源,epel有很多软件包,所以这个源也是一个非常常用的。

(1)如图,先下载centos6版本的epel安装包,然后赋予执行权限,执行rpm -ivh epel-release-6-8.noarch.rpm  这个命令来安装:

epelinstall

 

(2)然后跟第一种方式一样,执行 yum search nginx 会出现如图的执行结果:

nginxepelsearch

如果执行这个命令出现这个错误

Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

请参照前一篇文章的解决方案    Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

(3)与前面第三部是一样的,同样是执行yum install nginx -y进行安装,下面是我的安装过程

[root@localhost yum.repos.d]# yum install nginx -y
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package nginx.x86_64 0:1.10.1-1.el6.ngx will be installed
–> Processing Dependency: openssl >= 1.0.1 for package: nginx-1.10.1-1.el6.ngx.x86_64
–> Processing Dependency: libssl.so.10(libssl.so.10)(64bit) for package: nginx-1.10.1-1.el6.ngx.x86_64
–> Processing Dependency: libcrypto.so.10(libcrypto.so.10)(64bit) for package: nginx-1.10.1-1.el6.ngx.x86_64
–> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit) for package: nginx-1.10.1-1.el6.ngx.x86_64
–> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.1)(64bit) for package: nginx-1.10.1-1.el6.ngx.x86_64
–> Running transaction check
—> Package openssl.x86_64 0:1.0.0-27.el6 will be updated
—> Package openssl.x86_64 0:1.0.1e-48.el6_8.1 will be an update
–> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================================================================
 Package                                             Arch                                               Version                                                        Repository                                           Size
=================================================================================================================================================================================================================================
Installing:
 nginx                                               x86_64                                             1.10.1-1.el6.ngx                                               nginx                                               821 k
Updating for dependencies:
 openssl                                             x86_64                                             1.0.1e-48.el6_8.1                                              updates                                             1.5 M
Transaction Summary
=================================================================================================================================================================================================================================
Install       1 Package(s)
Upgrade       1 Package(s)
Total download size: 2.3 M
Downloading Packages:
(1/2): nginx-1.10.1-1.el6.ngx.x86_64.rpm                                                                                                                                                                  | 821 kB     00:20     
(2/2): openssl-1.0.1e-48.el6_8.1.x86_64.rpm                                                                                                                                                               | 1.5 MB     00:01     
———————————————————————————————————————————————————————————————————————————
Total                                                                                                                                                                                            100 kB/s | 2.3 MB     00:23     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
** Found 1 pre-existing rpmdb problem(s), ‘yum check’ output follows:
rhn-check-1.0.0.1-4.el6.noarch has missing requires of yum-rhn-plugin >= (‘0′, ‘0.9.1’, ’35’)
  Updating   : openssl-1.0.1e-48.el6_8.1.x86_64                                                                                                                                                                              1/3 
  Installing : nginx-1.10.1-1.el6.ngx.x86_64                                                                                                                                                                                 2/3 
———————————————————————-
Thanks for using nginx!
Please find the official documentation for nginx here:
Commercial subscriptions for nginx are available on:
———————————————————————-
  Cleanup    : openssl-1.0.0-27.el6.x86_64                                                                                                                                                                                   3/3 
  Verifying  : nginx-1.10.1-1.el6.ngx.x86_64                                                                                                                                                                                 1/3 
  Verifying  : openssl-1.0.1e-48.el6_8.1.x86_64                                                                                                                                                                              2/3 
  Verifying  : openssl-1.0.0-27.el6.x86_64                                                                                                                                                                                   3/3 
Installed:
  nginx.x86_64 0:1.10.1-1.el6.ngx                                                                                                                                                                                                
Dependency Updated:
  openssl.x86_64 0:1.0.1e-48.el6_8.1                                                                                                                                                                                             
Complete!
使用第二种方法安装的安装目录与第一种是一样的。
接下来介绍nginx的简单命令,使用如上的方法安装nginx后,自动安装为service,所以直接就可以使用
service nginx start
service nginx stop
service nginx status
此外,如果更改了nginx的配置文件,需要重新加载时,可以使用
nginx -s reload

 

 

linux 配置http代理以及epel源安装

在线上部署环境,安装软件时,经常碰到的一种情况就是使用yum来安装软件,但是有时无法访问外网,这时就需要正向代理的支持了。说到代理服务器,有正向代理,...

阅读全文

记录一次线上mysql主从数据库的迁移(数据量为亿级别)

前一阵迁移了线上服务器上的mysql的数据,数据量达到了亿级别。特在此记录一下操作流程。 现状: 目前线上使用了mysql主从库,即主库A和从库B,由于当初在安...

阅读全文

centos6下 mysql 5.5 数据目录迁移

前一篇文章 http://www.xiaomager.com/651.html 介绍了centos6下 mysql 5.5的安装过程。 当启动后,可以使用命令 ps -ef|grep mysql 看来mysql的进程情况,如...

阅读全文

欢迎留言