Nginx安装及Minio集群反向动态代理配置(二)


                                Nginx安装及Minio集群反向动态代理配置(二)_第1张图片


1. Nginx概述以及作用
Nginx同Apache,Tomcat一样,是一种服务器软件.他是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP代理服务器.因此,使用Nginx可以搭建网站,也可以实现负载均衡的功能,还可以作为邮件服务器来接受和发送邮件.Nginx1.9.0之后还可以作为通用的TCP/UDP代理服务器,也可以提供一定的缓存服务功能.

1.1 可以作为Web服务器
Nginx还是一个高性能的HTTP Web服务器(Web服务器还有Apache, IIS),它可以提供基本的HTTP功能和扩展功能,可以先通过动态/静态内容分离,而后为静态内容(Http/CSS/JS/甚至是资源服务器目录内容)提供HTTP访问功能;而动态内容可以整合代理模块,代理给上游服务器,以支持对外部程序的直接调用或者解析,如FASTCGI支持PHP
1.2作为反向代理服务器
反向代理服务器作用在服务器端,他在服务器端接收互联网中的链接请求,然后将请求转发给内部网络中的服务器,并且将从服务器中得到的结果返回给互联网中请求连接的客户端,如图所示

反向代理服务器对外是透明的,在客户端不需要任何的配置,所以访问者并不知道自己访问的是一个反向代理服务器,Nginx就是一个反向代理服务器
Nginx安装及Minio集群反向动态代理配置(二)_第2张图片

反向代理服务器针对Web服务器提供加速的功能,所有的外部网络要访问服务器的请求都要通过他.反向代理服务器负责接受客户端的请求,然后到资源服务器上获取内容,把内容返回给用户,并且把内容保存在在本地中,以便在日后收到同样的信息请求时可以把本地缓存中的内容直接发给用户,以减少后端Web的压力,提高响应速度,因此,Nginx还具有缓存功能.

1.3 反向代理服务器实现负载均衡
Nginx可以通过反向代理服务器实现负载均衡,以优化网站的负载,如图
Nginx安装及Minio集群反向动态代理配置(二)_第3张图片

1.4 可以作为邮件代理服务器

2. 为什么选择Nginx
Nginx有着高并发,性能好和占用内存少等特点,其安装简单,配合文件简介,启动容易,能够长时间运行,还可以在不间断服务的情况下升级软件版本,而且成本低,这些优点使得Nginx的应用越来越普遍

2.1 高并发,性能好,占用内存少和稳定
作为Web服务器,相比Apache,Nginx占用内存更少,支持的并发连接更多,使用效率更高,并且Nginx要比Apache更"轻量",性能更好
2.2 功能强大
可以作为Web服务器,反向代理服务器,也可以作为邮件服务器
2.3 扩展化高
Nginx的模块化设计极具扩展性,这种低耦合的配置,使得Nginx拥有数量庞大的第三方模块.当然那这些公开的模块和官方模块一样好用
2.4 其他优点
跨平台,占用内存小,配置操作简单,支持内置服务器检测

 [root@www nginx-1.9.9] ./configure --help

  --help                             print this message

  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname

  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

  --build=NAME                       set build name
  --builddir=DIR                     set build directory

  --with-select_module               enable select module
  --without-select_module            disable select module
  --with-poll_module                 enable poll module
  --without-poll_module              disable poll module

  --with-threads                     enable thread pool support

  --with-file-aio                    enable file AIO support
  --with-ipv6                        enable IPv6 support

  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_v2_module              enable ngx_http_v2_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_module

Nginx安装及Minio集群反向动态代理配置(二)_第4张图片



多台服务器间免密登录|免密拷贝

Cenos7 搭建Minio集群部署服务器(一)

Cenos7 搭建Minio集群Nginx统一访问入口|反向动态代理(二) 

Nginx正向代理与反向代理及Minio反向代理实操(三)

Spring Boot 与Minio整合实现文件上传与下载(三) 

CentOS7的journalctl日志查看方法

MySQL8.xx一主两从复制安装与配置


安装所需插件

1、安装gcc

gcc是linux下的编译器在此不多做解释,感兴趣的小伙伴可以去查一下相关资料,它可以编译 C,C++,Ada,Object C和Java等语言

命令:查看gcc版本

[root@www ~]# gcc -v
-bash: gcc: 未找到命令
说明没有安装: 

 那就直接yum安装

[root@www ~]# yum -y install gcc
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.qlu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.qlu.edu.cn
base                                                                                                                                                                                                                          | 3.6 kB  00:00:00     
extras                                                                                                                                                                                                                        | 2.9 kB  00:00:00     
updates                                                                                                                                                                                                                       | 2.9 kB  00:00:00     
updates/7/x86_64/primary_db                                                                                                                                                                                                   |  22 MB  00:00:02     
正在解决依赖关系
--> 正在检查事务
---> 软件包 gcc.x86_64.0.4.8.5-44.el7 将被 安装
--> 正在处理依赖关系 cpp = 4.8.5-44.el7,它被软件包 gcc-4.8.5-44.el7.x86_64 需要
--> 正在处理依赖关系 libmpfr.so.4()(64bit),它被软件包 gcc-4.8.5-44.el7.x86_64 需要
--> 正在处理依赖关系 libmpc.so.3()(64bit),它被软件包 gcc-4.8.5-44.el7.x86_64 需要
--> 正在检查事务
---> 软件包 cpp.x86_64.0.4.8.5-44.el7 将被 安装
---> 软件包 libmpc.x86_64.0.1.0.1-3.el7 将被 安装
---> 软件包 mpfr.x86_64.0.3.1.1-4.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决
..............................................................................................................................................

Nginx安装及Minio集群反向动态代理配置(二)_第5张图片


2、pcre、pcre-devel安装

pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库。

安装命令:

[root@www ~]# yum install -y pcre pcre-devel
Nginx安装及Minio集群反向动态代理配置(二)_第6张图片


3、zlib安装

zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装

安装命令:

[root@www ~]# yum install -y zlib zlib-devel

4、安装openssl

openssl是web安全通信的基石,没有openssl,可以说我们的信息都是在裸奔。。。。。。

安装命令:

[root@www ~]# yum install -y openssl openssl-devel
 


安装nginx

nginx 下载 :   Index of /download/

Nginx安装及Minio集群反向动态代理配置(二)_第7张图片

[root@www tools]#  wget http://nginx.org/download/nginx-1.9.9.tar.gz
[root@www tools]# mkdir -p /usr/local/nginx
解压到: /usr/local/nginx

[root@www tools]# tar -zxvf  nginx-1.9.9.tar.gz -C /usr/local/nginx/

Nginx安装及Minio集群反向动态代理配置(二)_第8张图片


[root@www nginx]# cd nginx-1.9.9/
[root@www nginx-1.9.9]# ./configure   # 执行该命令后生成一序列配置文件及模块

Nginx安装及Minio集群反向动态代理配置(二)_第9张图片

 [root@www nginx-1.9.9]# make 

[root@www nginx-1.9.9]# make install
执行意以上两个命令后,切换到/usr/local/nginx目录

Nginx安装及Minio集群反向动态代理配置(二)_第10张图片

配置nginx的配置文件nginx.conf文件,主要也就是端口

Nginx安装及Minio集群反向动态代理配置(二)_第11张图片


启动nginx服务

[root@www sbin]# ./nginx

[root@www sbin]# ./nginx
[root@www sbin]# ps -ef | grep nginx
root       5835      1  0 17:25 ?        00:00:00 nginx: master process ./nginx
nobody     5836   5835  0 17:25 ?        00:00:00 nginx: worker process
root       5838   3045  0 17:26 pts/0    00:00:00 grep --color=auto nginx

执行下面的命令,使修改的配置文件生效

[root@www sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@www sbin]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 一 2023-08-14 14:34:52 CST; 2h 56min ago
     Docs: man:firewalld(1)
 Main PID: 698 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─698 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

8月 14 14:34:51 www.yhchange.com systemd[1]: Starting firewalld - dynamic firewall daemon...
8月 14 14:34:52 www.yhchange.com systemd[1]: Started firewalld - dynamic firewall daemon.
8月 14 14:34:53 www.yhchange.com firewalld[698]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now.
[root@www sbin]# systemctl stop firewalld
[root@www sbin]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 一 2023-08-14 17:31:15 CST; 2s ago
     Docs: man:firewalld(1)
  Process: 698 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 698 (code=exited, status=0/SUCCESS)

8月 14 14:34:51 www.yhchange.com systemd[1]: Starting firewalld - dynamic firewall daemon...
8月 14 14:34:52 www.yhchange.com systemd[1]: Started firewalld - dynamic firewall daemon.
8月 14 14:34:53 www.yhchange.com firewalld[698]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now.
8月 14 17:31:13 www.yhchange.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
8月 14 17:31:15 www.yhchange.com systemd[1]: Stopped firewalld - dynamic firewall daemon.
 

直接访问: 

http://192.168.1.111:8877/

Nginx安装及Minio集群反向动态代理配置(二)_第12张图片


附录: 开机nginx服务启动脚本

[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
 


vi /usr/lib/systemd/system/nginx.service

[root@www ~]# cat /usr/lib/systemd/system/nginx.service

[Unit]
Description=Nginx Server- high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target


[Service] 
Type=forking
# 路径对应安装路径
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
 
[Install] 
WantedBy=multi-user.target


[root@www ~]# systemctl daemon-reload

[root@www ~]# systemctl enable nginx
[root@www ~]# systemctl start nginx
[root@www ~]# systemctl status nginx

● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2023-08-15 22:59:48 CST; 6s ago
  Process: 1863 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 1864 (nginx)
    Tasks: 2
   CGroup: /system.slice/nginx.service
           ├─1864 nginx: master process /usr/local/nginx/sbin/nginx
           └─1865 nginx: worker process

8月 15 22:59:48 www.yhchange.com systemd[1]: Starting nginx...
8月 15 22:59:48 www.yhchange.com systemd[1]: Started nginx.
[root@www ~]# systemctl restart nginx
[root@www ~]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2023-08-15 23:00:14 CST; 2s ago
  Process: 1881 ExecStop=/usr/local/nginx/sbin/nginx -s quit (code=exited, status=0/SUCCESS)
  Process: 1886 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 1887 (nginx)
    Tasks: 2
   CGroup: /system.slice/nginx.service
           ├─1887 nginx: master process /usr/local/nginx/sbin/nginx
           └─1888 nginx: worker process
 

Nginx安装及Minio集群反向动态代理配置(二)_第13张图片


favicon图标在线制作|ico图标在线转换|favicon.ico图标在线生成 - 技术狂在线工具

favicon图标在线生成 | favicon图标在线制作

至此,Nginx搭建基本完成, 后续.....方向动态代理Minio服务,统一访问入口.................................. 

Nginx安装及Minio集群反向动态代理配置(二)_第14张图片

你可能感兴趣的:(nginx,chrome,运维)