티스토리 뷰
MTU SIZE 변경
아래와 같이 수동으로 설정은 되는데 뭔가 속도 변화는 모르겠다. ?
ifconfig eth0 mtu 9000 |
TCP 버퍼사이즈 조정 옵션
기본적으로 커널 / 시스템 자원에 따라 디폴트로 설정되는 값이 다 틀림
적용해도 실제 카운팅되는 값이나 세부정부를 볼수 없어 성능의 차이를 체감상 느끼지는 못하였음
DOS나 DDOS를 막을려고 커스터마이징을 하는건 비추. 어짜피 하나 안하나 못막음...
정상적인 서비스 요청을 처리하기 위한 커스터마이징을 효과 있을것 같음...
net.core / net.dev 이름으로 지칭되는 것은 모든 프로토콜을 의미하는듯 하며
tcp라고 붙는 명칭들만 tcp를 의미하는 듯함
This sets the max OS receive buffer size for all types of connections (모든 프로토콜에 사용되는 수신 버퍼의 최대 설정)
net.core.rmem_max=12582912 net.core.rmem_default=12582912 |
This sets the max OS send buffer size for all types of connections (모든 프로토콜에 사용되는 송신 버퍼의 최대 설정)
net.core.wmem_max=12582912 net.core.wmem_default=12582912 |
net.ipv4.tcp_mem (TCP 스택이 메모리를 어떻게 사용할것인지 메모리 페이지 단위 설정)
순서대로 min pressure max
net.ipv4.tcp_rmem / net.ipv4.tcp_wmem 에 값에 따라 적당한 크기로 잡아야 함 (성능의 많은 영향을 미치므로 주의해야 한다고 함)
IA32는 4KB 가 한페이지 (IA32는 Intel Architecture 32)
1G 메모리 net.ipv4.tcp_mem = 139008 185344 278016
4G 메모리 net.ipv4.tcp_mem = 80928 107904 161856 net.ipv4.tcp_mem = 67296 89728 134592
8G 메모리 net.ipv4.tcp_mem = 745440 993920 1490880 |
TCP 수신 버퍼
net.ipv4.tcp_rmem = 4096 87380 33554432
TCP 송신 버퍼
net.ipv4.tcp_wmem = 4096 65536 33554432
backlog (직접적으로 SYN 패킷을 처리하는데 결정적인 커널 파라미터 라는데 바꿔봐도 별 감흥없음)
SYN 공격을 해보면 죽기는 마찬가지...
10G 네트워크에서 추천 값
net.core.netdev_max_backlog = 30000 |
1G 네트워크에서는 아래값의 배수로 주면 될것 같다
net.core.netdev_max_backlog = 1024 |
1024보다 크게 할때는 /usr/src/linux/include/net/tcp.h 소스에서 TCP_SYNQ_SIZE 변수 수정후 커널재컴파일
TCP_SYNQ_HSIZE에 16을 곱한 값이 tcp_max_syn_backlog 보다는 작거야 같아야 한다고 함
/usr/src/linux/include/net/tcp.h 아래 구문인듯 함 (해봤는데 별 차이 못 느끼겠음...)
#if HZ >= 200 |
라우팅 관련 커널 파라미터
라우팅갯수 / 라우팅캐시 시간 = 초당인식가능한 라우팅 갯수
kernel : dst cache overflow 요런 메시지가 뜨면 초당인식 가능한 라우팅 갯수가 오버된듯??? 시스템이 멈출수도 있다고 함.
긴급하다면 ip route flush cache 명령어를 통해 라우트 캐시 초기화 시키고 아래 커널 파라미터 수정해보자
/proc/sys/net/ipv4/route/max_size (인식가능한 라우팅 갯수) /proc/sys/net/ipv4/route/secret_interval (라우팅 캐시하는 시간 리프레시 시간? 일듯) |
현재 라우팅 캐시 정보 확인
route -Cn |
cat /proc/sys/net/ipv4/route/max_size 디폴트 값이 아래와 같이 나오는걸로 봐서는 메모리와 연관성이 있을듯? 1기가 시스템 = 1048576 4기가 시스템 = 2097152 8기가 시스템 = 4194304 |
시스템에서 열수있는 최대 파일 갯수 지정 (squid 라던가 많은 파일 처리를 담당해야 한다면 커스터마이징 해보자
fs.file-max = 65535 |
ICMP 차단
net.ipv4.icmp_echo_ignore_all |
TTL 값 변경 (리눅스는 기본값 64이며 PING request 응답으로 상대방 OS 인지 가능함 이를 헷갈리게 하기 위함?)
값이 너무 작으면 네트워크 단절 예상됨
net.ipv4.ip_default_ttl = 64 |
Broadcast로부터 오는 핑을 차단 (Smurt 공격을 차단함)
net.ipv4.icmp_echo_ignore_broadcasts |
TCP / ICMP 중 헤더가 깨진 패킷들은 거부
net.ipv4.icmp_ignore_bogus_error_responses |
etc 기타 허접 설정들
net.ipv4.tcp_orphan_retries (TCP 연결을 끊기전에 확인하는 횟수) |
출처 : http://unixgameserver.springnote.com/pages/678492?print=1
아래 옵션들을 수정하면서 자기 시스템에서 최적의 성능을 찾아라네 ㅋ
/proc/sys/net/core/rmem_default
수신용 윈도우·사이즈의 디폴트 값을 정의합니다. BDP 값이 큰 경우 윈도우의 사이즈도 크게 합니다
/proc/sys/net/core/rmem_max
수신용 윈도우·사이즈의 최대치를 정의하는 옵션입니다. BDP 값이 큰 경우 윈도우의 사이즈도 크게 합니다
/proc/sys/net/core/wmem_default
송신용 윈도우·사이즈의 디폴트 값을 정의하는 옵션입니다. BDP 값이 큰 경우 윈도우의 사이즈도 크게 합니다
/proc/sys/net/core/wmem_max
송신용 윈도우·사이즈의 최대치를 정의하는 옵션입니다. BDP 값이 큰 경우 윈도우의 사이즈도 크게 합니다
/proc/sys/net/ipv4/tcp_window_scaling
RFC 1323의 정의에 따라서 윈도우·슬캘링을 유효하게 하는 옵션입니다. 64KB를 넘는 사이즈의 윈도우를 지원 하도록 설정할 필요가 있습니다
/proc/sys/net/ipv4/tcp_sack
SACK 기능을 유효하게 하는 옵션입니다. 무순서로 수신하는 패킷을 선택적으로 수신 확인하는 것으로써 송신원은 부족한 세그먼트(segment)만을 재발송신 하는 것만으로 좋아지기 때문에 결과적으로 시스템의 성능이 향상합니다. 이 옵션은(광범위하게 걸치는 네트워크 통신에 대해서) 유효하게 할 필요가 있습니다만 CPU 사용율이 높아지는 경우가 있습니다
/proc/sys/net/ipv4/tcp_fack
FACK 기능을 유효하게 하는 옵션입니다. FACK은 SACK 과 함께 기능해 네트워크의 혼잡을 완화합니다. 이 옵션은 유효하게 합니다
/proc/sys/net/ipv4/tcp_timestamps
재전송의 타임 아웃의 산출 방법보다 정확한 방법으로RTT를 산출하는 옵션입니다(RFC 1323 를 참조). 이 옵션은 시스템의 성능 향상을 위해서 유효하게 합니다
/proc/sys/net/ipv4/tcp_mem
메모리 사용량에 대한 TCP 스택의 동작을 결정하는 옵션입니다. 각각의 값은 메모리·페이지의 사이즈를 나타냅니다(통상은4KB ). 최초의 값은 메모리 사용량의 최소한의 값을 나타냅니다. 다음의 값은 메모리 압축 모드를 개시해 버퍼 사용량을 압축할 때의 한계 값을 나타냅니다. 마지막 값은 메모리 사용량의 최대 한계 값을 나타냅니다. 최대 한계 값에 이르면 메모리 사용량을 줄이기 위해서 패킷이 파기됩니다. BDP 값이 큰 경우는 이 값도 크게 합니다(다만 이 값은 메모리·페이지의 사이즈이며 메모리의 용량은 아닌 것에 주의해 주세요)
/proc/sys/net/ipv4/tcp_wmem
자동조정에 필요한1 소켓 근처의 메모리 사용량을 정의하는 옵션입니다. 최초의 값은 소켓의 송신용 버퍼에 할당할 수 있고 있는 최소 바이트 수를 나타냅니다. 다음의 값은 시스템에 과대한 부하가 걸리지 않은 상태로 버퍼의 사이즈를 어디까지 크게 할 수 있을까의 디폴트 값을 나타냅니다(wmem_default에 의해서 덧 쓰기 됩니다).마지막 값은 송신용 버퍼·스페이스의 최대 값을 나타냅니다(wmem_max에 의해서 덧쓰기 됩니다)
/proc/sys/net/ipv4/tcp_rmem
tcp_wmem와 같은 옵션입니다. 다만 tcp_wmem는 자동조정 시에 수신용 버퍼를 참조합니다.
/proc/sys/net/ipv4/tcp_low_latency
TCP/IP 스택에 대해서 짧은 대기 시간을 허가해 throughput를 향상시키는 옵션입니다.이 옵션은 무효로 합니다
/proc/sys/net/ipv4/tcp_westwood
송신측의 congestion 제어 알고리즘을 유효하게 하는 옵션입니다. 이 알고리즘은 throughput의 개산 값을 산출해 대역폭 전체의 가동률을 최적화합니다. 이 옵션은 WAN의 통신용으로 유효하게 합니다
/proc/sys/net/ipv4/tcp_bic
고속의 장거리 네트워크용에BIC 기능을 유효하게 하는 옵션입니다. 기가비트의 속도로 가동하고 있는 링크의 가동률을 올립니다. 이 옵션은WAN의 통신용으로 유효하게 합니다.
# Kernel sysctl configuration file for Red Hat Linux # # For binary values, 0 is disabled, 1 is enabled. See sysctl( and # sysctl.conf(5) for more details. # Controls IP packet forwarding net.ipv4.ip_forward = 0 # Controls source route verification net.ipv4.conf.default.rp_filter = 1 # Do not accept source routing net.ipv4.conf.default.accept_source_route = 0 # Controls the System Request debugging functionality of the kernel kernel.sysrq = 0 # Controls whether core dumps will append the PID to the core filename # Useful for debugging multi-threaded applications kernel.core_uses_pid = 1 # Controls the use of TCP syncookies net.ipv4.tcp_syncookies = 1 # Controls the maximum size of a message, in bytes kernel.msgmnb = 65536 # Controls the default maxmimum size of a mesage queue kernel.msgmax = 65536 # Controls the maximum shared segment size, in bytes kernel.shmmax = 68719476736 # Controls the maximum number of shared memory segments, in pages kernel.shmall = 4294967296 # Default max queues syatem wide = 1024 kernel.msgmni = 2048 #Maximum number of file descriptor allowed fs.file-max = 1048576 # The Linux autotuning TCP buffer limit # Defines per-socket memory usage for auto-tuning. The third value is the maximum send buffer space # (overridden by r/wmem_max). # The receive buffers for auto-tuning net.ipv4.tcp_rmem = 4096 87380 16777216 # The write (send) buffers for auto-tuning net.ipv4.tcp_wmem = 4096 65536 16777216 # Determines how the TCP stack should behave for memory usage; each count is in memory pages (typically 4KB). # Increase the count for large BDP (but remember, it's memory pages, not bytes). net.ipv4.tcp_mem = 8388608 8388608 8388608 # For 10G NIC net.core.netdev_max_backlog = 32768 net.ipv4.tcp_congestion_control = htcp # Recommended for hosts with jumbo frames enabled net.ipv4.tcp_mtu_probing = 1 # Enables window scaling as defined by RFC 1323. Must be enabled to support windows larger than 64KB. net.ipv4.tcp_window_scaling = 1 # Enables selective acknowledgment, which improves performance by selectively acknowledging packets received out of order # (causing the sender to retransmit only the missing segments), but it can increase CPU utilization. net.ipv4.tcp_sack = 1 # net.ipv4.tcp_fack = 1 net.ipv4.tcp_timestamps = 1 net.ipv4.tcp_low_latency = 1 net.ipv4.tcp_westwood = 1 net.ipv4.tcp_bic = 1 net.ipv4.tcp_max_tw_buckets = 1440000 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 5 # Limit of socket listen() backlog.Defaults to 128. See also tcp_max_syn_backlog for additional tuning net.ipv4.somaxconn = 4096 net.core.somaxconn = 4096 # Maximal number of remembered connection requests, which are still did not receive an acknowledgment from connecting client net.ipv4.tcp_max_syn_backlog = 4096 # net.ipv4.tcp_no_metrics_save = 1 net.ipv4.tcp_keepalive_intvl = 30 net.ipv4.tcp_keepalive_time = 400 net.ipv4.tcp_keepalive_probes = 5 vm.swappiness = 20 net.ipv4.tcp_max_orphans = 5 net.ipv4.tcp_orphan_retries = 2 |
TIME_WAIT 포트 재사용
/proc/sys/net/ipv4/tcp_tw_reuse
socket 옵션
SO_REUSEADDR
net.ipv4.ip_local_port_range = 1025 65535
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 3
/proc/sys/kernel/hung_task_timeout_secs
END
참고자료 및 URL
https://cs.uwaterloo.ca/~brecht/servers/ip-sysctl.txt
https://cs.uwaterloo.ca/~brecht/servers/tcp.html
http://www.redbooks.ibm.com/redbooks/pdfs/gg243376.pdf
http://fasterdata.es.net/host-tuning/linux/
http://fasterdata.es.net/fasterdata/host-tuning/linux/
http://www.cyberciti.biz/faq/linux-tcp-tuning/7
http://www.psc.edu/networking/projects/tcptune/
'Linux' 카테고리의 다른 글
DRBD for mysql (0) | 2015.06.10 |
---|---|
mysql 외부 접속 가능하게 하기 (0) | 2015.06.10 |
Mysql 3.23.58 Max 커넥션 튜닝 (0) | 2015.06.10 |
imuxsock begins to drop messages from pid, imuxsock lost 134 messages from pid (0) | 2015.06.10 |
리눅스 kernel BYPASS (0) | 2015.06.04 |
- Total
- Today
- Yesterday
- php
- 인증서
- NGINX
- glusterfs
- virtualbox
- MySQL
- Apache
- 리눅스
- yum
- kvm
- WAF
- IPSEC
- centos8
- gitlab
- SSL
- OpenVPN
- mariadb
- pptp
- iptables
- centOS7
- L2TP
- ntp
- GeoIP
- 베이어다이나믹
- HAProxy
- mod_security
- galera
- cURL
- ssh
- softether
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |