美文网首页
Nginx Yum安装

Nginx Yum安装

作者: DB哥 | 来源:发表于2019-08-20 11:59 被阅读0次

Linux System Environment

[root@nginx02 ~]#cat /etc/redhat-release            #==》系统版本
CentOS Linux release 7.5.1804 (Core) 
[root@nginx02 ~]# uname –r                          #==》内核版本
3.10.0-862.el7.x86_64 
[root@nginx02 ~]# uname -m                          #==》系统架构
x86_64
[root@nginx02 ~]# echo $LANG                        #==》系统字符集
en_US.UTF-8
[root@nginx02 ~]# nginx –v                          #==》官方仓库安装的Nginx版本
nginx version: nginx/1.16.1
[root@nginx02 ~]# nginx –v                          #==》epel仓库安装的Nginx版本
nginx version: nginx/1.12.2

yum安装Nginx有两种源安装

1、epel仓库(1.版本较低 2.安装简单 3.配置不易读)
2、Nginx官方仓库(1.版本较新 2.可选择版本安装 3.安装简单 4.配置易读,推荐使用)

Nginx配置文件

1、/etc/nginx/nginx.conf         #==》Nginx主配置文件nginx.confi
2、/etc/nginx/fastcgi.conf       #==》Nginx调用FastCGI功能优化配置文件

Nginx功能

1、web服务(http 80)
2、负载均衡 (反向代理proxy)
3、web 缓存(web cache)

Nginx优点

1、配置简单,灵活
2、高并发(静态小文件)
3、占用资源少
4、功能种类多(web/proxy/cache),每一个功能并不是特别强。
5、支持epoll模型,使用nginx可以支持高并发
6、利用nginx可以对Ip限速,也可以限制连接数

Nginx常用命令
标注:不要使用Nginx 自带的nginx二进制命令重启或启动Nginx服务,否则会与systemctl命令启动Nginx服务产生冲突。

1、[root@nginx02 ~]# nginx  –t                   #==》检查配置文件语法
2、[root@nginx02 ~]# nginx  –V                   #==》查看nginx版本及编译参数
3、[root@nginx02 ~]# systemctl start nginx       #==》启动Nginx
4、[root@nginx02 ~]# systemctl stop nginx        #==》停止Nginx
5、[root@nginx02 ~]# systemctl status nginx      #==》查看Nginx状态
6、[root@nginx02 ~]# systemctl reload nginx      #==》平滑重启Nginx
7、[root@nginx02 ~]# systemctl restart nginx     #==》重启Nginx

一、使用阿里云提供的epel源安装Nginx
1、配置阿里云yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

2、安装Nginx服务

[root@nginx02 ~]# yum privodes nginx
[root@nginx02 ~]# yum -y install nginx
[root@nginx02 ~]# rpm -qc nginx
[root@nginx02 ~]# nginx -v
nginx version: nginx/1.12.2

3、Nginx语法检查

[root@nginx02 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

4、启动Nginx服务

[root@nginx02 ~]# systemctl start nginx
[root@nginx02 ~]# ss  -tlunp
[root@nginx02 ~]# curl -I 127.0.0.1

5、设置Nginx开机自启动

[root@nginx02 ~]# systemctl enable nginx
[root@nginx02 ~]# systemctl status nginx

二、使用Nginx官方提供的yum源安装Nginx
1、配置阿里云yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

2、yum安装Nginx软件依赖包
标注:pcre(Perl Compatible Regular Expressions)库,支持HTTP Rewrite模块

[root@nginx01 ~]# yum -y install openssl-devel pcre-devel gcc gcc+

3、配置Nginx官方提供的Nginx安装源
标注:Nginx官方仓库网址 http://nginx.org/en/linux_packages.html

[root@nginx02 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

4、安装Nginx
标注:默认安装最新版本Nginx,可以选择安装

[root@nginx02 ~]# yum provides nginx
[root@nginx02 ~]# yum -y install nginx
[root@nginx02 ~]# rpm -qc nginx
[root@nginx02 ~]# nginx -v
nginx version: nginx/1.16.1

5、Nginx语法检查

[root@nginx02 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

6、启动Nginx服务

[root@nginx02 ~]# systemctl start nginx
[root@nginx02 ~]# ss  -tlunp
[root@nginx02 ~]# curl -I 127.0.0.1

7、设置Nginx开机自启动

[root@nginx02 ~]# systemctl enable nginx
[root@nginx02 ~]# systemctl status nginx

相关文章

网友评论

      本文标题:Nginx Yum安装

      本文链接:https://www.haomeiwen.com/subject/iwnusctx.html