July 21, 2016 11:17AM
Всем привет!

Пытаюсь настроить базовую защиту от DDOS, но не могу получить в тестах подтверждение того, что выставленные параметры работают как надо.

Имеется nginx/1.10.1.
Нагрузочные тесты запускаются с одной единственной машинки с IP 172.20.241.135:

(в nginx.conf прописано)

-----------------------------------------------------------------
geo $limited {
default 1;
192.168.45.56/32 0;
172.20.241.135/32 1;
}

map $limited $limit {
1 $binary_remote_addr;
0 "";
}

limit_req_zone $limit zone=1000reqpersec:10m rate=1000r/s;
limit_conn_zone $limit zone=conn_limit_per_ip:10m;

limit_req_status 429;
limit_conn_status 429;
limit_req_log_level notice;
-----------------------------------------------------------------


(в конфиге виртуального сервера, se-centos7.domain.com.conf)
-----------------------------------------------------------------
location /withlimits {

limit_req zone=1000reqpersec;
limit_conn conn_limit_per_ip 10;

root /usr/share/nginx/html;

}
-----------------------------------------------------------------



Хочу получить подтверждение, что 1000 запросов в секунду все таки проходит.

Пробую утилитку vegeta (https://github.com/tsenart/vegeta):

(вот такой заголовок запроса)
# cat plan.txt
GET http://se-centos7.domain.com/withlimits/test.html
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0
Host: se-centos7.domain.com
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8


(пробуем 800 запросов в секунду)
# vegeta attack -duration=30s -rate=800 -timeout=1s -workers=40 -targets=./plan.txt | vegeta report
Requests [total, rate] 24000, 800.03
Duration [total, attack, wait] 29.999213425s, 29.998749891s, 463.534µs
Latencies [mean, 50, 95, 99, max] 387.177µs, 354.506µs, 453.12µs, 1.155159ms, 11.057387ms
Bytes In [total, mean] 14434520, 601.44
Bytes Out [total, mean] 0, 0.00
Success [ratio] 99.12%
Status Codes [code:count] 429:212 200:23788
Error Set:
429


Видим, что 800 запросов не держит.. В error-логе вот что:

2016/07/21 17:56:46 [notice] 4881#4881: *399 limiting requests, excess: 1.000 by zone "1000reqpersec", client: 172.20.241.135, server: se-centos7.domain.com, request: "GET /withlimits/test.html HTTP/1.1", host: "se-centos7.domain.com"
2016/07/21 17:56:47 [notice] 4881#4881: *393 limiting requests, excess: 1.000 by zone "1000reqpersec", client: 172.20.241.135, server: se-centos7.domain.com, request: "GET /withlimits/test.html HTTP/1.1", host: "se-centos7.domain.com"



При использовании улититы wrk2 (https://github.com/giltene/wrk2) видим все то же, уже на 500 запросах в минуту (R500):

# ./wrk -t2 -c5 -d30s -R500 http://se-centos7.domain.com/withlimits/
Running 30s test @ http://se-centos7.domain.com/withlimits/
2 threads and 5 connections
Thread calibration: mean lat.: 1.076ms, rate sampling interval: 10ms
Thread calibration: mean lat.: 0.974ms, rate sampling interval: 10ms
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.03ms 374.32us 6.14ms 67.16%
Req/Sec 267.14 53.27 444.00 59.96%
15002 requests in 30.00s, 10.75MB read
Non-2xx or 3xx responses: 4019
Requests/sec: 500.03
Transfer/sec: 366.90KB

Видим, что "Non-2xx or 3xx responses: 4019", т.е. много 429ых ошибок.

Параметр limit_conn тоже не работает, не срабатывает ограничение в 10 коннекций с одного IP..

Что я делаю не так?

Как можно получить подтверждение того, что выставленные лимиты отрабатывают правильно.

--
s.
Subject Author Posted

Не понимаю как работает limit_req и limit_conn

siroco July 21, 2016 11:17AM

Re: Не понимаю как работает limit req и limit conn

Vasiliy P. Melnik July 21, 2016 11:36AM

Re: Не понимаю как работает limit req и limit conn

Валентин Бартенев July 21, 2016 11:30AM

Re: Не понимаю как работает limit req и limit conn

siroco July 22, 2016 04:30AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 272
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready