<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 1. 架構及主機 架構說明: 在Nginx 后面我們建好兩組 web,其中一組為PC-Servers,模擬某個網站給PC電腦訪問的;另外一組為M-Servers,模擬網站給手機和移動終端訪問。我們在設置一臺Nginx服務器實現訪問不通域名,在各自的組內實現負載均衡輪詢方式響應用戶的請求,同時Nginx自帶對后端服務器的健康檢測,后端服務器不可用的時候會自動停止調度到故障的服務器上,充分保障了用戶的體驗。 ![](https://img.kancloud.cn/ba/e7/bae7b7195396a3f7655ebb1531f80d1d_1184x652.png) # 六臺主機 ``` 1 4臺web服務器 : 主機名:PC-WebServer-IP18 CentOS 8.4 IP:192.168.250.18 httpd web服務 頁面內容 PC-WebServer-IP18 192.168.250.18 主機名:PC-WebServer-IP28 CentOS 8.4 IP:192.168.250.28 httpd web服務 頁面內容 PC-WebServer-IP28 192.168.250.28 主機名:PC-WebServer-IP58 CentOS 8.4 IP:192.168.250.58 httpd web服務 頁面內容 M-WebServer-IP58 192.168.250.58 主機名:PC-WebServer-IP68 CentOS 8.4 IP:192.168.250.68 httpd web服務 頁面內容 M-WebServer-IP68 192.168.250.68 2 1臺 Nginx 服務器 : 主機名: Nginx-IP08 CentOS 8.4 IP:192.168.250.8/24 nginx version: nginx/1.21.6 3 1臺client主機 : 主機名:Client-IP172-18 CentOS 8.4 IP:172.16.0.18/24 ``` # 2. 后端web主機的準備 基本思路:在兩組四臺服務器上分別安裝好Apache,并定義好首頁頁面,確保后面測試直觀顯示效果。 ``` # 基礎環境包括CentOS操作系統的優化、防火墻關閉、同步時間等都要做好,我們按照規劃的架構圖對四臺服務器進行分組并重新命名 # 修改服務器名稱 [root@CentOS84-IP18 ]#hostnamectl set-hostname PC-WebServer-IP18 [root@CentOS84-IP18 ]#exit [root@PC-WebServer-IP18 ]# # 安裝Apache 準備httpd服務 [root@PC-WebServer-IP18 ]#yum -y install httpd # 用命令自動生成Apache頁面文件,主機名寫入到 indexTmp.html臨時文件;IP地址追加到indexTmp.html臨時文件;最后將這個indexTmp.html臨時文件的內容合并到一行,并寫入到 /var/www/html/index.html 這個Apache首頁文件內。 [root@PC-WebServer-IP18 ]#hostname > /var/www/html/indexTmp.html [root@PC-WebServer-IP18 ]#hostname -I >> /var/www/html/indexTmp.html [root@PC-WebServer-IP18 ]#cat /var/www/html/indexTmp.html | xargs > /var/www/html/index.html # 驗證首頁內容 [root@PC-WebServer-IP18 ]#cat /var/www/html/index.html PC-WebServer-IP18 192.168.250.18 # 啟動并設定開啟自啟 httpd 服務 [root@PC-WebServer-IP18 ]#systemctl enable --now httpd [root@PC-WebServer-IP18 ]# ## 下面用將上面的命令合并到一條命令內完成整個httpd的部署工作 # PC-WebServer-IP28 主機部署 httpd [root@CentOS84-IP28 ]#hostnamectl set-hostname PC-WebServer-IP28 [root@CentOS84-IP28 ]#exit [root@PC-WebServer-IP28 ]#yum -y install httpd;hostname > /var/www/html/indexTmp.html;hostname -I >> /var/www/html/indexTmp.html;cat /var/www/html/indexTmp.html | xargs > /var/www/html/index.html;systemctl enable --now httpd [root@PC-WebServer-IP28 ]#cat /var/www/html/index.html PC-WebServer-IP28 192.168.250.28 [root@PC-WebServer-IP28 ]# # M-WebServer-IP58 主機部署 httpd [root@CentOS84-IP58 ]#hostnamectl set-hostname M-WebServer-IP58 [root@CentOS84-IP58 ]#exit [root@M-WebServer-IP58 ]#yum -y install httpd;hostname > /var/www/html/indexTmp.html;hostname -I >> /var/www/html/indexTmp.html;cat /var/www/html/indexTmp.html | xargs > /var/www/html/index.html;systemctl enable --now httpd [root@M-WebServer-IP58 ]#cat /var/www/html/index.html M-WebServer-IP58 192.168.250.58 [root@M-WebServer-IP58 ]# # M-WebServer-IP68 主機部署 httpd [root@CentOS84-IP68 ]#hostnamectl set-hostname M-WebServer-IP68 [root@CentOS84-IP68 ]#exit [root@M-WebServer-IP68 ]#yum -y install httpd;hostname > /var/www/html/indexTmp.html;hostname -I >> /var/www/html/indexTmp.html;cat /var/www/html/indexTmp.html | xargs > /var/www/html/index.html;systemctl enable --now httpd [root@M-WebServer-IP68 ]#cat /var/www/html/index.html M-WebServer-IP68 192.168.250.68 [root@M-WebServer-IP68 ]# ###################################################################################### # 在終端客戶端上不通過Nginx 反向道理功能直接訪問這四臺web服務器,確定網頁內容 [root@Client-IP172-18 ]#curl 192.168.250.18 PC-WebServer-IP18 192.168.250.18 [root@Client-IP172-18 ]#curl 192.168.250.28 PC-WebServer-IP28 192.168.250.28 [root@Client-IP172-18 ]#curl 192.168.250.58 M-WebServer-IP58 192.168.250.58 [root@Client-IP172-18 ]#curl 192.168.250.68 M-WebServer-IP68 192.168.250.68 [root@Client-IP172-18 ]# ``` # 3. Nginx 服務器基礎環境準備 ``` # 基礎環境包括CentOS操作系統的優化、防火墻關閉、同步時間等都要做好,我們按照規劃的架構圖對四臺服務器進行分組并重新命名 [root@CentOS84-IP08 ]# [root@CentOS84-IP08 ]#hostnamectl set-hostname Nginx-IP08 [root@CentOS84-IP08 ]#exit # 查看CentOS8默認的 nginx 版本1.14 比較低了,查詢網站已經到1.21,穩定版本1.20.2了 [root@Nginx-IP08 ]#yum info nginx Name : nginx Epoch : 1 Version : 1.14.1 Release : 9.module_el8.0.0+184+e34fea82 Architecture : x86_64 Size : 570 k Source : nginx-1.14.1-9.module_el8.0.0+184+e34fea82.src.rpm Repository : AppStream Summary : A high performance web server and reverse proxy server URL : http://nginx.org/ License : BSD Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and : IMAP protocols, with a strong focus on high concurrency, performance and low : memory usage. # 因為CentOS8自帶的版本太低,我們從nginx 官網上復制 repo 文件,并寫入到本機的相應目錄下,準備yum 安裝最新版本的nginx [root@Nginx-IP08 ]#vim /etc/yum.repos.d/nginx.repo [root@Nginx-IP08 ]#cat /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=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [root@Nginx-IP08 ]#yum info nginx nginx stable repo 23 kB/s | 36 kB 00:01 nginx mainline repo 50 kB/s | 95 kB 00:01 Available Packages Name : nginx Epoch : 1 Version : 1.21.6 Release : 1.el8.ngx Architecture : x86_64 Size : 827 k Source : nginx-1.21.6-1.el8.ngx.src.rpm Repository : nginx-mainline Summary : High performance web server URL : https://nginx.org/ License : 2-clause BSD-like license Description : nginx [engine x] is an HTTP and reverse proxy server, as well as : a mail proxy server. # yum安裝最新的 nginx [root@Nginx-IP08 ]#yum -y install nginx [root@Nginx-IP08 ]#rpm -qi nginx Name : nginx Epoch : 1 Version : 1.21.6 Release : 1.el8.ngx Architecture: x86_64 Install Date: Mon 28 Mar 2022 05:20:25 AM CST Group : System Environment/Daemons Size : 2949219 License : 2-clause BSD-like license Signature : RSA/SHA1, Tue 25 Jan 2022 11:45:07 PM CST, Key ID abf5bd827bd9bf62 Source RPM : nginx-1.21.6-1.el8.ngx.src.rpm Build Date : Tue 25 Jan 2022 11:25:23 PM CST Build Host : ip-10-1-17-168.eu-central-1.compute.internal Relocations : (not relocatable) Vendor : NGINX Packaging <nginx-packaging@f5.com> URL : https://nginx.org/ Summary : High performance web server Description : nginx [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server. # 默認的安裝包等信息 [root@Nginx-IP08 ]#rpm -ql nginx /etc/logrotate.d/nginx /etc/nginx /etc/nginx/conf.d /etc/nginx/conf.d/default.conf /etc/nginx/fastcgi_params /etc/nginx/mime.types /etc/nginx/modules /etc/nginx/nginx.conf /etc/nginx/scgi_params /etc/nginx/uwsgi_params /usr/lib/.build-id /usr/lib/.build-id/ae /usr/lib/.build-id/ae/80f1c107606755e59070162a192d5c7b250e37 /usr/lib/.build-id/ef /usr/lib/.build-id/ef/61e35830a566768e73e0c62909fafa180ee175 /usr/lib/systemd/system/nginx-debug.service /usr/lib/systemd/system/nginx.service /usr/lib64/nginx /usr/lib64/nginx/modules /usr/libexec/initscripts/legacy-actions/nginx /usr/libexec/initscripts/legacy-actions/nginx/check-reload /usr/libexec/initscripts/legacy-actions/nginx/upgrade /usr/sbin/nginx /usr/sbin/nginx-debug /usr/share/doc/nginx-1.21.6 /usr/share/doc/nginx-1.21.6/COPYRIGHT /usr/share/man/man8/nginx.8.gz /usr/share/nginx /usr/share/nginx/html /usr/share/nginx/html/50x.html /usr/share/nginx/html/index.html /var/cache/nginx /var/log/nginx [root@Nginx-IP08 ]#rpm -qc nginx /etc/logrotate.d/nginx /etc/nginx/conf.d/default.conf /etc/nginx/fastcgi_params /etc/nginx/mime.types /etc/nginx/nginx.conf /etc/nginx/scgi_params /etc/nginx/uwsgi_params # yum安裝后自動生成的service 文件,這個文件可以被編譯安裝借鑒,按照編譯安裝定義的內容修改即可被用于編譯安裝的啟動文件 [root@Nginx-IP08 ]#cat /usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)" ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)" [Install] WantedBy=multi-user.target # 啟動并設定開機啟動 [root@Nginx-IP08 ]#systemctl enable --now nginx Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service. [root@Nginx-IP08 ]# [root@Nginx-IP08 ]# [root@Nginx-IP08 ]#ss -ltn State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 511 0.0.0.0:80 0.0.0.0:* # 查看yum安裝的官網的版本編譯的參數信息,我們常用的反向代理、地址透傳、https等都編譯進去了 [root@Nginx-IP08 ]#nginx -V nginx version: nginx/1.21.6 built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC) built with OpenSSL 1.1.1k FIPS 25 Mar 2021 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' [root@Nginx-IP08 ]#nginx -v nginx version: nginx/1.21.6 [root@Nginx-IP08 ]# ``` # 4. 反向代理單臺web 基本內容:我們先完成反向代理至后端服務器組內的一臺WEB主機。 ``` # 查看yum安裝nginx的配置目錄結構 [root@Nginx-IP08 ]#tree /etc/nginx/ /etc/nginx/ ├── conf.d │ └── default.conf # server 默認配置文件 ├── fastcgi_params ├── mime.types ├── modules -> ../../usr/lib64/nginx/modules ├── nginx.conf # 主配置文件 ├── scgi_params └── uwsgi_params 2 directories, 6 files # 在/etc/nginx/conf.d/ 子配置目錄下創建兩個組的配置文件 [root@Nginx-IP08 ]#vim /etc/nginx/conf.d/pc.conf [root@Nginx-IP08 ]#cat /etc/nginx/conf.d/pc.conf server { listen 80; server_name www.shone.cn; location / { proxy_pass http://192.168.250.18; } } [root@Nginx-IP08 ]#vim /etc/nginx/conf.d/mobile.conf [root@Nginx-IP08 ]#cat /etc/nginx/conf.d/mobile.conf server { listen 80; server_name m.shone.cn; location / { proxy_pass http://192.168.250.58; } } # 重新引導Nginx,讓新配置文件生效 [root@Nginx-IP08 ]#nginx -s reload ###################################################################################### # 在終端客戶機上測試訪問 [root@Client-IP172-18 ]#curl www.shone.cn PC-WebServer-IP18 192.168.250.18 [root@Client-IP172-18 ]#curl m.shone.cn M-WebServer-IP58 192.168.250.58 [root@CentOS84-IP172-18 ]# ``` # 5. 反向代理多組web并實現各組內的web-rs的負載均衡 基本內容:在上面實現一臺反向代理的基礎上,完成后面每組多臺的反向代理,并在同一個組內實現負載均衡和自動的故障停止調度等 ``` # 首先要修改主配置文件 [root@Nginx-IP08 ]#cat /etc/nginx/nginx.conf user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { ###################### 下面這部分就是新增加的內容 ###################### # PC-Servers組的配置,注釋掉一些高級用法,用基礎的可以測試下 upstream PC-Servers { #hash $request_uri consistent; #hash $cookie_sessionid #ip_hash; #least_conn; server 192.168.250.18:80 weight=1 fail_timeout=5s max_fails=3; server 192.168.250.28:80 weight=1 fail_timeout=5s max_fails=3; #server 127.0.0.1:80 weight=1 fail_timeout=5s max_fails=3 backup; } # M-Servers組的配置,注釋掉一些高級用法,用基礎的可以測試下 upstream M-Servers { #hash $request_uri consistent; #hash $cookie_sessionid #ip_hash; #least_conn; server 192.168.250.58:80 weight=1 fail_timeout=5s max_fails=3; server 192.168.250.68:80 weight=1 fail_timeout=5s max_fails=3; #server 127.0.0.1:80 weight=1 fail_timeout=5s max_fails=3 backup; } ####################################################################### include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } [root@Nginx-IP08 ]# ######## 和上面主配置文件對應的是server子配置文件都要修改 ######## # PC-Servers組的server子配置文件 [root@Nginx-IP08 ]#cat /etc/nginx/conf.d/pc.conf server { listen 80; server_name www.shone.cn; location / { proxy_pass http://PC-Servers; } } # M-Servers組的server子配置文件 [root@Nginx-IP08 ]#cat /etc/nginx/conf.d/mobile.conf server { listen 80; server_name m.shone.cn; location / { proxy_pass http://M-Servers; } } [root@Nginx-IP08 ]# # 語法檢測沒錯誤 [root@Nginx-IP08 ]#nginx -t # 重新引導Nginx,讓新配置文件生效 [root@Nginx-IP08 ]#nginx -s reload ###################################################################################### # 在終端客戶機上測試訪問,看到符合設定的規則輪詢,我們確定測試停掉任何一個后端的web都會被停止調度 [root@Client-IP172-18 ]#curl www.shone.cn PC-WebServer-IP28 192.168.250.28 [root@Client-IP172-18 ]#curl www.shone.cn PC-WebServer-IP18 192.168.250.18 [root@Client-IP172-18 ]#curl www.shone.cn PC-WebServer-IP28 192.168.250.28 [root@Client-IP172-18 ]#curl www.shone.cn PC-WebServer-IP18 192.168.250.18 [root@Client-IP172-18 ]#curl www.shone.cn PC-WebServer-IP28 192.168.250.28 [root@Client-IP172-18 ]#curl www.shone.cn PC-WebServer-IP18 192.168.250.18 [root@Client-IP172-18 ]#curl m.shone.cn M-WebServer-IP58 192.168.250.58 [root@Client-IP172-18 ]#curl m.shone.cn M-WebServer-IP68 192.168.250.68 [root@Client-IP172-18 ]#curl m.shone.cn M-WebServer-IP58 192.168.250.58 [root@Client-IP172-18 ]#curl m.shone.cn M-WebServer-IP68 192.168.250.68 [root@Client-IP172-18 ]#curl m.shone.cn M-WebServer-IP58 192.168.250.58 [root@Client-IP172-18 ]#curl m.shone.cn M-WebServer-IP68 192.168.250.68 [root@Client-IP172-18 ]# ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看