【Linux】循序渐进学运维-CentOS7使用yum方式安装nginx,项目实战

        *   [3\. 启动nginx](about:blank#3_nginx_70)

        *   *   [4\. 从浏览器端查看](about:blank#4__90)

        *   [总结](about:blank#_103)
前言

上篇文章我们介绍了nginx的相关知识,并进行了编译安装nginx, 学习apache的时候我们知道apache是可以用yum安装的,那nginx是否也可以呢,今天我们就来探讨下,关于yum安装nginx的那些事。

测试环境

操作系统:

[root@ecs-c13b ~]# cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core)

内核:

[root@ecs-c13b ~]# uname -r

3.10.0-1062.12.1.el7.x86_64

当前系统中的软件环境:

大家最好找一台干净的机器,我这里因为条件限制,暂时找了一台跑mysql的机器来操作。


[root@ecs-c13b ~]# netstat -antup

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2970/sshd           

tcp        0      0 192.168.0.192:39040     100.125.1.41:443        ESTABLISHED 9037/hostguard      

tcp        0     36 192.168.0.192:22        120.244.152.188:22217   ESTABLISHED 20942/sshd: root@pt 

tcp6       0      0 :::3306                 :::*                    LISTEN      21184/mysqld        

tcp6       0      0 :::22                   :::*                    LISTEN      2970/sshd           

udp        0      0 0.0.0.0:68              0.0.0.0:*                           701/dhclient        

udp        0      0 127.0.0.1:323           0.0.0.0:*                           642/chronyd         

udp6       0      0 ::1:323                 :::*                                642/chronyd    



安装前准备

官网:http://nginx.org/en/linux_packages.html#RHEL-CentOS

大多数时候我们都需要按照官网来做,这就跟你买了一个豆浆机,会附带一个说明书。你可以按照说明书进行操作。当然你能从网上找到豆浆机的操作方法吗? 也可以,但是你需要去筛选看看是不是你的型号的,看看是第几代产品等等。

1. 安装前准备

yum install yum-utils

2. To set up the yum repository(添加源)

create the file named /etc/yum.repos.d/nginx.repo with the following contents:


[root@ecs-c13b ~]# 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

module_hotfixes=true



[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

module_hotfixes=true



安装nginx
1. 查看nginx源是否添加成功

[root@ecs-c13b ~]# yum search nginx

2. 安装并查看

[root@ecs-c13b ~]# yum install nginx

[root@ecs-c13b ~]# rpm -qa | grep nginx

nginx-1.18.0-1.el7.ngx.x86_64

[root@ecs-c13b ~]# 



3. 启动nginx

[root@ecs-c13b ~]# systemctl start nginx

[root@ecs-c13b ~]# systemctl enable nginx

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

[root@ecs-c13b ~]# systemctl status nginx

● nginx.service - nginx - high performance web server

   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)

   Active: active (running) since Fri 2020-07-31 08:52:55 CST; 15s ago

     Docs: http://nginx.org/en/docs/

 Main PID: 21326 (nginx)

   CGroup: /system.slice/nginx.service

           ├─21326 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

           └─21327 nginx: worker process



Jul 31 08:52:55 ecs-c13b systemd[1]: Starting nginx - high performance web server...

Jul 31 08:52:55 ecs-c13b systemd[1]: Started nginx - high performance web server.

[root@ecs-c13b ~]# 



4. 从浏览器端查看

在这里插入图片描述

在这里插入图片描述

img
img
img

naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpbnNodXpoYW4=,size_16,color_FFFFFF,t_70)

[外链图片转存中…(img-yWIfzm19-1727251569279)]
[外链图片转存中…(img-O2uC0Fo6-1727251569279)]
[外链图片转存中…(img-KorLquyU-1727251569279)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值