首页 > 系统相关 >Nginx

Nginx

时间:2024-08-20 14:27:00浏览次数:7  
标签:00 x86 nginx Nginx 64 1.20 el7

在CentOS上部署Nginx

yum install -y nginx 

详细命令:

[root@CentOS7 ~]# yum install nginx -y
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.20.1-10.el7 will be installed
--> Processing Dependency: nginx-filesystem = 1:1.20.1-10.el7 for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_1)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Running transaction check
---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed
---> Package nginx-filesystem.noarch 1:1.20.1-10.el7 will be installed
---> Package openssl11-libs.x86_64 1:1.1.1k-7.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================
 Package                                           Arch                                    Version                                             Repository                             Size
===========================================================================================================================================================================================
Installing:
 nginx                                             x86_64                                  1:1.20.1-10.el7                                     epel                                  588 k
Installing for dependencies:
 gperftools-libs                                   x86_64                                  2.6.1-1.el7                                         base                                  272 k
 nginx-filesystem                                  noarch                                  1:1.20.1-10.el7                                     epel                                   24 k
 openssl11-libs                                    x86_64                                  1:1.1.1k-7.el7                                      epel                                  1.5 M

Transaction Summary
===========================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 2.3 M
Installed size: 6.6 M
Downloading packages:
(1/4): nginx-filesystem-1.20.1-10.el7.noarch.rpm                                                                                                                    |  24 kB  00:00:00
(2/4): gperftools-libs-2.6.1-1.el7.x86_64.rpm                                                                                                                       | 272 kB  00:00:01
(3/4): nginx-1.20.1-10.el7.x86_64.rpm                                                                                                                               | 588 kB  00:00:02
(4/4): openssl11-libs-1.1.1k-7.el7.x86_64.rpm                                                                                                                       | 1.5 MB  00:00:04
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                      463 kB/s | 2.3 MB  00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:openssl11-libs-1.1.1k-7.el7.x86_64                                                                                                                                    1/4
  Installing : 1:nginx-filesystem-1.20.1-10.el7.noarch                                                                                                                                 2/4
  Installing : gperftools-libs-2.6.1-1.el7.x86_64                                                                                                                                      3/4
  Installing : 1:nginx-1.20.1-10.el7.x86_64                                                                                                                                            4/4
  Verifying  : gperftools-libs-2.6.1-1.el7.x86_64                                                                                                                                      1/4
  Verifying  : 1:nginx-filesystem-1.20.1-10.el7.noarch                                                                                                                                 2/4
  Verifying  : 1:nginx-1.20.1-10.el7.x86_64                                                                                                                                            3/4
  Verifying  : 1:openssl11-libs-1.1.1k-7.el7.x86_64                                                                                                                                    4/4

Installed:
  nginx.x86_64 1:1.20.1-10.el7

Dependency Installed:
  gperftools-libs.x86_64 0:2.6.1-1.el7                         nginx-filesystem.noarch 1:1.20.1-10.el7                         openssl11-libs.x86_64 1:1.1.1k-7.el7

Complete!
[root@CentOS7 ~]#

启动Nginx

systemctl start nginx

查看Nginx进程启动状态(显示有几个worker process就是几核CPU,我这里是8核CPU)

ps -ef | grep nginx

开机自启动Nginx

systemctl enable nginx

详细命令:

[root@CentOS7 ~]# systemctl start nginx
[root@CentOS7 ~]# ps -ef | grep nginx
root      1893     1  0 13:52 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx     1894  1893  0 13:52 ?        00:00:00 nginx: worker process
nginx     1895  1893  0 13:52 ?        00:00:00 nginx: worker process
nginx     1896  1893  0 13:52 ?        00:00:00 nginx: worker process
nginx     1897  1893  0 13:52 ?        00:00:00 nginx: worker process
nginx     1898  1893  0 13:52 ?        00:00:00 nginx: worker process
nginx     1899  1893  0 13:52 ?        00:00:00 nginx: worker process
nginx     1900  1893  0 13:52 ?        00:00:00 nginx: worker process
nginx     1901  1893  0 13:52 ?        00:00:00 nginx: worker process
root      1903  1716  0 13:52 pts/0    00:00:00 grep --color=auto nginx
[root@CentOS7 ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@CentOS7 ~]#

 查看TCP和UDP的监听端口

netstat -lntup

netstat -lntup 是一个用于显示网络连接状态的命令行工具,通常用于诊断网络问题和查看系统上运行的服务。下面是这个命令各部分的详细解释:

  • netstat: 这是命令本身,用来显示网络连接、路由表和其他网络相关信息。
  • -l: 显示所有监听中的套接字(sockets),即展示所有正在监听的网络服务。
  • -n: 显示数字形式的地址和端口,而不是尝试查找名称(如域名)。
  • -t: 显示 TCP 协议的连接。
  • -u: 显示 UDP 协议的连接。
  • -p: 显示每个连接对应的程序名或者进程ID(PID)。

当你运行 netstat -lntup 时,它会输出一个列表,其中包括以下信息:

  • Proto: 连接的协议类型(TCP 或 UDP)。
  • Recv-Q: 接收队列的长度,通常为0,除非有数据未被应用程序读取。
  • Send-Q: 发送队列的长度,通常为0,除非有数据正等待发送。
  • Local Address: 本地地址和端口。
  • Foreign Address: 远程地址和端口,如果是监听状态则可能显示为 *:*
  • State: 连接的状态(例如,LISTENESTABLISHEDTIME_WAIT 等)。
  • PID/Program name: 对应的进程ID和程序名。
[root@CentOS7 ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      854/rpcbind
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1893/nginx: master
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1253/sshd
tcp6       0      0 :::111                  :::*                    LISTEN      854/rpcbind
tcp6       0      0 :::80                   :::*                    LISTEN      1893/nginx: master
tcp6       0      0 :::22                   :::*                    LISTEN      1253/sshd
udp        0      0 0.0.0.0:600             0.0.0.0:*                           854/rpcbind
udp        0      0 0.0.0.0:111             0.0.0.0:*                           854/rpcbind
udp6       0      0 :::600                  :::*                                854/rpcbind
udp6       0      0 :::111                  :::*                                854/rpcbind
[root@CentOS7 ~]#

我们可以看到,Nginx 正确地在监听 80 端口(TCP 和 TCP6)

放行 firewall 的http端口

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

这条命令会打开 HTTP 服务所使用的标准端口,即 TCP 80 端口。这意味着它只针对标准的 HTTP 服务端口进行配置。如果您更改了 Nginx 的启动端口为 8080,那么这条命令将不再适用于您的情况,因为 8080 端口不是 HTTP 服务的标准端口。

因此你可以使用下面的命令放行指定端口:如 80

sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

检查防火墙的状态以确认 80 端口是否已经开放。

sudo firewall-cmd --list-all

 

标签:00,x86,nginx,Nginx,64,1.20,el7
From: https://www.cnblogs.com/Magiclala/p/18369383

相关文章

  • Docker compose 部署前后端-----采用nginx代理,支持一个端口部署多个前端
    Dockercompose部署前后端-----采用nginx代理,支持一个端口部署多个前端1、Linux服务器安装最新版docker,确保有dockercompose命令2、创建docker工作区目录mkdirdocker-workspace3、进入docker工作区目录,创建前端nginx目录,创建后端xxx目录mkdirnginxxxx4、创建confi......
  • 聊聊如何利用ingress-nginx实现应用层容灾
    前言容灾是一种主动的风险管理策略,旨在通过构建和维护异地的冗余系统,确保在面临灾难性事件时,关键业务能够持续运作,数据能够得到保护,从而最大限度地减少对组织运营的影响和潜在经济损失。因此容灾的重要性不言而喻,今天的话题主要是聊下如何利用ingress-nginx实现应用层容灾应用层......
  • ansible自动化之playbook剧本【nginx安装为例】
    一、简介roles则是ansible中,playbooks的目录组织结构。将代码或者文件进行模块化,成为roles的文件目录组织结构,易管理,易理解,代码可重用,层次清晰。二、准备目录结构创建所需目录:mkdir-proles/nginx/{files,handlers,tasks,templates,vars}创建所需文件:touchroles/......
  • nginx平滑升级
    一、概要nginx升级的原因有两种:1、nginx版本升级需要2、nginx新添新的模块二、nginx升级原理多进程模式:nginx分为主进程(master)和工作进程(work),主进程就是nginx本身,工作进程是看你电脑分配了多少核cpu,但是展示工作进程数还是nginx.conf配置文件种定义。主进程支持的信号TER......
  • nginx基础面试题
    1、破解密码:1、首先重启虚拟机,启动的时候马上按e键进入安全模式2、在有Linux那行的最后面加上rd.break3、ctrl+x将文件4、以读写的方式重新挂载:mount-oremount,rw/sysroot5、进入路径:chroot/sysroot6、改写密码:passwd6、打安全标签:touch/.autorelabel7、退......
  • 二进制下载部署Nginx
    一、通过Nginx官网并采取二进制方式部署Nginx官网二、具体步骤[[email protected]]#ll-dnginx.repo-rw-r--r--.1rootroot398Aug1722:01nginx.repo[[email protected]]#pwd/etc/yum.repos.d接下来可以直接使用yum-yinstallnginx则是直......
  • 国产操作系统 离线部署MYSQL、NGINX、redis、JDK1.8
    目录1.1、龙蜥操作系统8.4【AnolisOS8.4GA】1.2、安装关键步骤说明2.1、安装必要的系统组件2.2、配置JDK2.3、安装redis2.4、安装nginx2.5、安装mysql3.1、启用防火墙3.2、开放业务端口3.3、修改SSH端口号为100223.4、配置特定端口指定IP访问4.1、网络设置4.2......
  • WindowsServer系统下nginx代理问题
    部署vue打包后的dist文件夹后,重启nginx发现没生效,操作如下:1.停止redis,删除浏览器缓存并用无痕模式访问发现依然不生效,试着各种办法重新导入数据库数据也不行,nginx.exe-sstop依然能访问2.搜索发现可能是WindowsServer系统的问题,于是执行命令nginx-squit退出nginx......
  • 部署Nginx负载均衡+动静分离的群集
    目录一、Nginx应用二、正向代理与反向代理1.1正向代理1.2反向代理三、负载均衡1.轮询(RoundRobin)2.最小连接数3.IP  hash:4.加权轮询5.最少事件算法6.一致性hash一、Nginx应用Nginx是一款非常优秀的HTTP服务器软件支持高达50000个并发连接数的响应拥有强......
  • NGINX 封禁 IP(IP 段)访问方法:修改配置文件或 .htaccess 文件
    方法一:修改Nginx配置文件nginx.confNginx配置访问IP可以修改 nginx.conf 文件,只需要在 server 中添加 allow 和 deny 的IP即可,如下:server{listen80;server_namelocalhost;allowall;deny123.123.123.123;error_page500......