Nginx的TCP UDP排程器

2021-08-27 18:59:48 字數 4206 閱讀 4909

使用nginx實現tcp/udp排程器功能,實現如下功能:

udp 協議是應用層:http dns nginx 

tcp  協議是傳輸層

使用4臺rhel7虛擬機器,其中一台作為nginx**伺服器,該伺服器需要配置兩塊網絡卡,ip位址分別為192.168.4.5和192.168.2.5,兩台ssh伺服器ip位址分別為192.168.2.100和192.168.2.200。客戶端測試主機ip位址為192.168.4.100。如圖-2所示。

部署nginx伺服器:

[root@proxy conf]# nginx  -s stop

[root@proxy conf]# rm -rf  /usr/local/nginx/

[root@proxy nginx-1.12.2]# ./configure  --user=nginx  --group=nginx   --with-http_ssl_module  --with-stream   //開啟ssl加密功能

//開啟4層反向**功能

[root@proxy nginx-1.12.2]# make && make install    //編譯並安裝

修改配置檔案:必須在http上面

客戶端訪問:

[root@clent ~]# ssh 192.168.4.5 -p 12345

[email protected]'s password: 

last login: tue jul 31 18:59:12 2018 from 192.168.2.254

[root@web2 ~]# connection to 192.168.4.5 closed by remote host.

connection to 192.168.4.5 closed.

[root@clent ~]# ssh 192.168.4.5 -p 12345

[email protected]'s password: 

last login: tue jul 31 18:58:57 2018 from 192.168.2.254

[root@web1 ~]# connection to 192.168.4.5 closed by remote host.

connection to 192.168.4.5 closed.

優化nginx併發量

[root@proxy ~]# ab -n 2000 -c 2000

this is apachebench, version 2.3

licensed to the apache software foundation,

benchmarking 192.168.4.5 (be patient)      ////提示開啟檔案數量過多

socket: too many open files (24)

2)修改nginx配置檔案,增加併發量

[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf

worker_processes  2;    //與cpu核心數量一致

events {

worker_connections  65535;  //每個worker最大併發連線數

use epoll;

2.優化linux核心引數(最大檔案數量)

[root@proxy ~]# ulimit -a     //檢視所有屬性值

[root@proxy ~]# ulimit  -hn 100000    //設定硬限制(臨時規則)

[root@proxy ~]# ulimit  -sn 100000     //設定軟限制(臨時規則)

[root@proxy ~]# vim  /etc/security/limits.conf 

4)優化後測試伺服器併發量(因為客戶端沒調核心引數,所以在proxy測試)

[root@proxy ~]# ab -n 2000 -c 2000

this is apachebench, version 2.3

licensed to the apache software foundation,

benchmarking 192.168.4.5 (be patient)

completed 200 requests

completed 400 requests

completed 600 requests

completed 800 requests

completed 1000 requests

completed 1200 requests

completed 1400 requests

completed 1600 requests

completed 1800 requests

completed 2000 requests

finished 2000 requests

server software:        nginx/1.12.2

server hostname:        192.168.4.5

server port:            80

document path:          /

document length:        612 bytes

concurrency level:      2000

time taken for tests:   0.298 seconds

complete requests:      2000

failed requests:        0

write errors:           0

total transferred:      1690000 bytes

html transferred:       1224000 bytes

requests per second:    6715.42 [#/sec] (mean)

time per request:       297.822 [ms] (mean)

time per request:       0.149 [ms] (mean, across all concurrent requests)

transfer rate:          5541.53 [kbytes/sec] received

connection times (ms)

min  mean[+/-sd] median   max

connect:        0   13  15.5      4      55

processing:     2   14  11.9      8     202

waiting:        0   10   9.8      5     202

total:          5   27  24.3     12     215

percentage of the requests served within a certain time (ms)

50%     12

66%     31

75%     53

80%     56

90%     65

95%     70

98%     73

99%     74

100%    215 (longest request)

Nginx之TCP UDP排程器 簡單

1 問題 使用nginx實現tcp udp排程器功能 四層 實現如下功能 2 方案 使用4臺rhel7虛擬機器,其中一台作為nginx 伺服器,該伺服器需要配置兩塊網絡卡,ip位址分別為192.168.4.5和192.168.2.5,兩台ssh伺服器ip位址分別為192.168.2.100和192....

Nginx的TCP UDP排程器 萬金油 新浪部落格

使用nginx實現tcp udp排程器功能,實現如下功能 udp 協議是應用層 http dns nginx tcp 協議是傳輸層 使用4臺rhel7虛擬機器,其中一台作為nginx 伺服器,該伺服器需要配置兩塊網絡卡,ip位址分別為192.168.4.5和192.168.2.5,兩台ssh伺服器i...

Nginx的排程演算法

hash key consistent hash key consistent 基於指定的 key 進行hash運算 若使用consistent引數,將使用ketama一致性hash演算法 適用於後端是cache伺服器 如varnish 時使用 範例 hash request uri consist...