成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Nginx這個功能厲害了!

系統 Linux
為了實現流量拷貝,Nginx提供了ngx_http_mirror_module模塊,來看一下吧。

 [[384247]]

1. 需求

將生產環(huán)境的流量拷貝到預上線環(huán)境或測試環(huán)境,這樣做有很多好處,比如:

  •  可以驗證功能是否正常,以及服務的性能;
  •  用真實有效的流量請求去驗證,又不用造數據,不影響線上正常訪問;
  •  這跟灰度發(fā)布還不太一樣,鏡像流量不會影響真實流量;
  •  可以用來排查線上問題;
  •  重構,假如服務做了重構,這也是一種測試方式;

 為了實現流量拷貝,Nginx提供了ngx_http_mirror_module模塊

2. 安裝Nginx

首頁,設置yum倉庫。為此,創(chuàng)建一個文件/etc/yum.repos.d/nginx.repo

將以下內容寫入文 

  1. [nginx-stable]  
  2. name=nginx stable repo  
  3. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/  
  4. gpgcheck=1  
  5. enabled=1  
  6. gpgkey=https://nginx.org/keys/nginx_signing.key  
  7. module_hotfixes=true  
  8. [nginx-mainline]  
  9. name=nginx mainline repo  
  10. baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/  
  11. gpgcheck=1  
  12. enabled=0  
  13. gpgkey=https://nginx.org/keys/nginx_signing.key  
  14. module_hotfixes=true 

yum安裝nginx 

  1. yum install nginx -y 

默認情況下,nginx配置文件是nginx.conf

一般情況下,nginx.conf文件在 /usr/local/nginx/conf  或者 /etc/nginx  或者 /usr/local/etc/nginx 目錄下

為了啟動nginx,直接在命令行里輸入nginx回車即可 

  1. # 啟動nginx  
  2. nginx  
  3. # fast shutdown  
  4. nginx -s stop  
  5. # graceful shutdown  
  6. nginx -s quit  
  7. # reloading the configuration file  
  8. nginx -s reload  
  9. # reopening the log files  
  10. nginx -s reopen  
  11. # list of all running nginx processes  
  12. ps -ax | grep nginx 

一旦master進程接收到重新加載配置的信號,它將檢查新配置文件的語法是否正確,并嘗試應用其中提供的配置。如果成功,master進程將啟動新的worker進程,并發(fā)送消息給舊的worker進程,要求他們shutdown。否則,master進程將回滾所做的更改,并繼續(xù)使用舊配置。舊的worker進程在接收到關閉命令后,停止接受新的連接,直到所有之前已經接受的連接全部處理完為止。之后,舊的worker進程退出。

nginx的master進程的進程ID,默認情況下,放在nginx.pid文件中,該文件所在的目錄一般是/usr/local/nginx/logs 或者 /var/run。

還可以這樣停止nginx

  1. kill -s QUIT 3997 

初始配置文件長這樣: 

  1. user  nginx;  
  2. worker_processes  1;  
  3. error_log  /var/log/nginx/error.log warn;  
  4. pid        /var/run/nginx.pid;  
  5. events {  
  6.     worker_connections  1024;  
  7.  
  8. http {  
  9.     include       /etc/nginx/mime.types;  
  10.     default_type  application/octet-stream;  
  11.     log_format  main '$remote_addr - $remote_user [$time_local] "$request" '  
  12.                       '$status $body_bytes_sent "$http_referer" '  
  13.                       '"$http_user_agent" "$http_x_forwarded_for"';   
  14.     access_log  /var/log/nginx/access.log main;  
  15.     sendfile        on;  
  16.     #tcp_nopush on;  
  17.     keepalive_timeout  65;  
  18.     #gzip on;  
  19.     include /etc/nginx/conf.d/*.conf;  

3. ngx_http_mirror_module

The ngx_http_mirror_module module (1.13.4) implements mirroring of an original request by creating background mirror subrequests. Responses to mirror subrequests are ignored.

我是這樣理解的,這里,mirror本意是鏡子、鏡像,這里可以理解就像一個鏡像站點一樣,將所有的請求都收集起來,這個鏡像就代表了所有真實有效的原始請求。有了這個鏡像,后續(xù)我們才可能用這個鏡像去做一些事情,比如重現一下所有的請求,這就實現了把線上的流程復制到別的地方。

官網給出的示例倒是很簡單,如下: 

  1. location / {  
  2.     mirror /mirror;  
  3.     proxy_pass http://backend;  
  4.  
  5. location = /mirror {  
  6.     internal;  
  7.     proxy_pass http://test_backend$request_uri;  

如果請求體被鏡像,那么在創(chuàng)建子請求之前會先讀取請求體。 

  1. location / {  
  2.     mirror /mirror;  
  3.     mirror_request_body off;  
  4.     proxy_pass http://backend;  
  5.  
  6. location = /mirror {  
  7.     internal;  
  8.     proxy_pass http://log_backend;  
  9.     proxy_pass_request_body off;  
  10.     proxy_set_header Content-Length "";  
  11.     proxy_set_header X-Original-URI $request_uri;  

前面我們安裝了Nginx,但是里面沒有包含我們所需的ngx_http_mirror_module模塊,因此,真正要使用的時候最好還是采用自定義安裝,即從源碼構建。

首先,下載源碼  http://nginx.org/en/download.html

接下來,編譯安裝,例如: 

  1. ./configure  
  2.     --sbin-path=/usr/local/nginx/nginx  
  3.     --conf-path=/usr/local/nginx/nginx.conf  
  4.     --pid-path=/usr/local/nginx/nginx.pid  
  5.     --with-http_ssl_module  
  6.     --without-http_limit_req_module  
  7.     --without-http_mirror_module  
  8.     --with-pcre=../pcre-8.43  
  9.     --with-zlib=../zlib-1.2.11  
  10.     --add-module=/path/to/ngx_devel_kit  
  11.     --add-module=/path/to/lua-nginx-module   
  12. make & make install 

配置 

  1. upstream api.abc.com {  
  2.   server 127.0.0.1:8080;  
  3.  
  4. upstream tapi.abc.com {  
  5.     server 127.0.0.1:8081;  
  6.  
  7. server {  
  8.     listen 80;  
  9.    # 源站點  
  10.     location /api {  
  11.         proxy_pass http://api.cjs.com;  
  12.         proxy_set_header Host $host;  
  13.         proxy_set_header X-Real-IP $remote_addr;  
  14.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  15.         # 流量復制  
  16.   mirror /newapi;  
  17.   mirror /mirror2;  
  18.   mirror /mirror3;  
  19.   # 復制請求體  
  20.   mirror_request_body on;  
  21.     }  
  22.     # 鏡像站點  
  23.     location /tapi {  
  24.         proxy_pass http://tapi.cjs.com$request_uri;  
  25.         proxy_pass_request_body on;  
  26.         proxy_set_header Host $host;  
  27.         proxy_set_header X-Real-IP $remote_addr;  
  28.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  29.     }  

4. 文檔

Nginx文檔

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

http://nginx.org/en/docs/http/ngx_http_mirror_module.html

http://nginx.org/en/docs/beginners_guide.html

http://nginx.org/en/docs/http/ngx_http_core_module.html#location 

http://nginx.org/en/docs/configure.html

第三方模板 

http://luajit.org/

https://www.nginx.com/resources/wiki/

https://www.nginx.com/resources/wiki/modules/lua/

https://www.nginx.com/resources/wiki/modules/index.html

https://github.com/openresty/lua-nginx-module  

補充 

  1. # 查看進程運行時間  
  2. ps -eo pid,user,lstart,etime,cmd | grep nginx  
  3. # 查看已經建立連接的數量  
  4. netstat -an | grep ESTABLISHED | wc -l  
  5. # 查看80端口的連接數  
  6. netstat -an | grep ":80" | wc -l  

 

責任編輯:龐桂玉 來源: 馬哥Linux運維
相關推薦

2021-09-17 12:18:53

NginxJavaScript前端

2020-04-27 09:40:43

開源項目 Bug

2018-05-14 22:58:14

戴爾

2018-04-11 14:30:33

2017-02-23 08:00:04

智能語音Click

2021-03-29 13:06:25

開源工具開源

2023-05-06 06:47:46

Bing聊天機器人

2021-12-27 07:59:50

ECMAScript JSON模塊Node.js

2021-11-01 07:50:44

TomcatWeb應用

2020-06-08 17:35:27

Redis集群互聯網

2022-01-11 12:13:33

JavaScript編程語言

2020-03-10 13:35:23

Gihub搜索開源

2022-04-08 08:11:28

Python代碼

2021-06-03 09:30:30

Python操作注冊表regedit

2019-11-25 21:53:48

代碼算法BUG

2017-07-27 16:51:19

數字化環(huán)衛(wèi)信息化

2022-05-03 23:44:21

Python動態(tài)鏈接庫Ctypes

2020-06-09 07:42:30

重命名文件 Linux

2018-01-24 10:48:34

神經網絡深度學習前端

2017-02-20 10:17:53

華為
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品视频97 | 免费观看一级特黄欧美大片 | 超碰在线97国产 | 国产精品日韩欧美一区二区三区 | 91av视频在线免费观看 | 成人一区二区视频 | 亚洲国产一区二区三区在线观看 | 高清视频一区二区三区 | 日本一区二区三区免费观看 | www.亚洲免费 | 色综合久久88色综合天天 | 精品国产乱码久久久久久蜜柚 | 97精品国产97久久久久久免费 | 91天堂网 | 欧美日韩电影一区二区 | 午夜成人在线视频 | 九九热精品视频 | 一区二区福利视频 | 中文字幕免费观看 | 日本人做爰大片免费观看一老师 | 天堂av资源 | 农夫在线精品视频免费观看 | 91精品国产高清久久久久久久久 | 精品国产一区二区在线 | 91精品国产自产在线老师啪 | 青青久久久 | 午夜三级视频 | 麻豆久久久| 91资源在线 | 亚洲一区二区 | 欧美日韩精品一区 | www.亚洲| 欧美日韩一区二区三区四区 | 一区二区av | 久久久免费毛片 | 欧美激情一区二区三区 | 天天插天天操 | 天天操网| 亚洲一区二区三区免费视频 | 亚洲精品888 | 久久国产美女视频 |