[리눅스]커널 파라메터
## 산업은행 아파치 설정
MaxClients 8192
Timeout 150
KeepAlive On
MaxKeepAliveRequests 0
KeepAliveTimeout 3
## openfile 개수
open files 65535
## 산업은행 OS 커널 튜닝 설정
네트웍 보안을 위한 sysctl.conf 설정
# icmp redirects를 보내지 않는다.
net.ipv4.conf.eth0.accept_redirects=0
net.ipv4.conf.lo.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.eth0.send_redirects = 0
net.ipv4.conf.lo.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.send_redirects = 0
# proxy arp를 설정하지 않는다.
net.ipv4.conf.eth0.proxy_arp=0
net.ipv4.conf.lo.proxy_arp=0
net.ipv4.conf.default.proxy_arp=0
net.ipv4.conf.all.proxy_arp=0
# 게이트웨이로부터의 redirect를 허용하지 않음으로써 스푸핑을 막기 위해 설정한다.
net.ipv4.conf.eth0.secure_redirects=0
net.ipv4.conf.lo.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv4.conf.all.secure_redirects=0
# 스푸핑을 막기 위해 source route 패킷을 허용하지 않는다.
# 소스 라우팅을 허용할 경우 악의적인 공격자가 IP 소스 라우팅을 사용해서 목적지의
# 경로를 지정할 수도 있고, 원래 위치로 돌아오는 경로도 지정할 수 있다. 이러한 소스 라우팅이
# 가능한 것을 이용해 공격자가 마치 신뢰받는 호스트나 클라이언트인 것처럼 위장할 수 있는 것이다.
net.ipv4.conf.eth0.accept_source_route=0
net.ipv4.conf.lo.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_source_route=0
# Broadcast로부터 오는 핑을 차단함(Smurt 공격을 차단함).
net.ipv4.icmp_echo_ignore_broadcasts=1
# IP 나 TCP 헤더가 깨진 bad icmp packet을 무시한다.
net.ipv4.icmp_ignore_bogus_error_responses = 1
# 자신의 네트워크가 스푸핑된 공격지의 소스로 쓰이는 것을 차단한다.
# 모든 인터페이스에서 들어오는 패킷에 대해 reply를 하여 들어오는 인터페이스로 나가지 못하는 패킷을 거부한다.
net.ipv4.conf.eth0.rp_filter=2
net.ipv4.conf.lo.rp_filter=2
net.ipv4.conf.default.rp_filter=2
net.ipv4.conf.all.rp_filter=2
# bootp 패킷을 허용하지 않는다.
net.ipv4.conf.eth0.bootp_relay=0
net.ipv4.conf.lo.bootp_relay=0
net.ipv4.conf.default.bootp_relay=0
net.ipv4.conf.all.bootp_relay=0
# 스푸핑된 패킷이나 소스라우팅, Redirect 패킷에 대해 로그파일에 정보를 남긴다.
net.ipv4.conf.eth0.log_martians=1
net.ipv4.conf.lo.log_martians=1
net.ipv4.conf.default.log_martians=1
net.ipv4.conf.all.log_martians=1
# 1/100초에 받아들이는 igmp "memberships"의 수
net.ipv4.igmp_max_memberships=1
# 매우 복잡한 사이트에서는 이 값을 늘리는 것도 가능하지만 64로 두는 것이 적당하며
# 더 늘렸을 경우에는 큰 문제가 발생할 수도 있다.
net.ipv4.ip_default_ttl=64
# 게이트웨이 서버가 아닌 이상 패킷을 포워딩 할 필요는 없다.
net.ipv4.ip_forward=0
# fragmented packet이 메모리에 존재하는 시간을 15초로 설정한다.
net.ipv4.ipfrag_time=15
# SYN_Flooding 공격에 대한 대비로 백로그큐(Backlog Queue)가 가득차면 다른 접속 요구를 받아들이지 못한다.
net.ipv4.tcp_max_syn_backlog = 1024
# TCP 연결에서 Three-way Handshake가 성공적으로 이루어지지 않으면 더 이상 소스 경로를 거슬러 올라가지 않도록한다.
# 따라서 적절한 연결 요청에 대해서만 연결을 맺는다.
# syncookies가 작동할 때 SYN Flooding 공격이 있으면 messages 파일에 아래와 같은 내용이 출력된다.
# possible SYN flooding on port 80. Sending cookies.
net.ipv4.tcp_syncookies = 1
# 일정한 시간과 IP별로 보내고 받는 SYN 재시도 횟수를 3회로 제한한다.
# 이 옵션은 스푸핑된(위조된) 주소로 오는 SYN 연결의 양을 줄여준다.
# 기본 값은 5(180 초에 대응)이며 255를 넘지 않아야 한다.
net.ipv4.tcp_syn_retries = 3
# passive TCP 접속시도가 재접속을 하기 위한 SYNACKs의 값을 정한다. 255 보다 높
# 게 지정할 수 없다. 기본값은 5이며, 180초에 대응이 된다.
net.ipv4.tcp_synack_retries = 3
# 무언가 문제가 있을 때 연결을 위해 재시도 할 횟수, 최소 값과 기본 값은 3이다.
net.ipv4.tcp_retries1=3
# TCP 연결을 끊기 전에 재시도할 횟수.
net.ipv4.tcp_retries2=7
# 연결을 종료시 소요되는 시간을 줄여준다(기본 설정값: 60).
net.ipv4.tcp_fin_timeout=20
# 동시에 유지 가능한 timewait 소켓의 수이다.
# 만약 지정된 숫자를 초과하였을 경우에는 timewait 소켓이 없어지며 경고 메시지가 출력된다.
# 이 제한은 단순한 DoS 공격을 차단하기 위해 존재하는데, 임의로 이 값을 줄여서는 안되며
# 메모리가 충분하다면 적절하게 늘려주는 것이 좋은데, 64M 마다 180000으로 설정하면 된다.
# 따라서 256M일 경우에는 256/4=4 4*180000=720000
# 64M -> 180000
# 128M -> 360000
# 256M -> 720000
# 512M -> 1440000
# 1G -> 2880000
# 2G -> 5760000
# 4G -> 11520000
# 8G -> 23040000
#net.ipv4.tcp_max_tw_buckets = 23040000
# 연결이 끊어졌다고 판단할 때까지, 얼마나 keepalive probe 를 보낼지 결정. 기본값 9회
# 간단한 DoS 공격을 막아준다.
net.ipv4.tcp_keepalive_probes=2
# keepalive 가 활성되 되어 있을 경우, 얼마나 자주 TCP 가 keepalive 메세지를 보
# 내게 할 것인지를 설정.
net.ipv4.tcp_keepalive_time=30
# keepalive_probes 를 보낼 간격을 정함. probe 를 보낸 후, probes * intvl 의 시
# 간이 지나도록 응답이 없으면 연결이 해제된 것으로 간주하게 됨. 기본 값의 사용
# 시 11분 15초 동안 재시도를 하고 연결을 취소함. 값은 초단위
net.ipv4.tcp_keepalive_intvl = 10
# 서버 쪽에서 닫은 TCP 연결을 끊기 전에 확인하는 횟수를 정한다. 기본 값은 7 로
# RTO 50 초에서 16 분 사이에 해당한다. 웹 서버가 운영 중 이라면 이 값을 줄여서
# 소켓 등이 귀한 리소스를 소비하지 않도록 할 수도 있다.
net.ipv4.tcp_orphan_retries = 2
# SYN 패킷을 전송한 후에 로스가 발생을 하여 ACK 를 일부 받지 못했을 경우, 선택
# 적으로 (selected) 받지못한 ACK 만 받도록 요청하는 것을 허락한다. 로스가 많은
# 네트워크에서는 상당히 중요한 역할을 한다.
net.ipv4.tcp_sack = 1
<< 리눅스 5.5. 설정 >> ## 광주은행 테스트 적용
# 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 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
# icmp redirects를 보내지 않는다.
net.ipv4.conf.eth0.accept_redirects=0
net.ipv4.conf.lo.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.eth0.send_redirects = 0
net.ipv4.conf.lo.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.send_redirects = 0
# proxy arp를 설정하지 않는다.
net.ipv4.conf.eth0.proxy_arp=0
net.ipv4.conf.lo.proxy_arp=0
net.ipv4.conf.default.proxy_arp=0
net.ipv4.conf.all.proxy_arp=0
# 게이트웨이로부터의 redirect를 허용하지 않음으로써 스푸핑을 막기 위해 설정한다.
net.ipv4.conf.eth0.secure_redirects=0
net.ipv4.conf.lo.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv4.conf.all.secure_redirects=0
# 스푸핑을 막기 위해 source route 패킷을 허용하지 않는다.
# 소스 라우팅을 허용할 경우 악의적인 공격자가 IP 소스 라우팅을 사용해서 목적지의
# 경로를 지정할 수도 있고, 원래 위치로 돌아오는 경로도 지정할 수 있다. 이러한 소스 라우팅이
# 가능한 것을 이용해 공격자가 마치 신뢰받는 호스트나 클라이언트인 것처럼 위장할 수 있는 것이다.
net.ipv4.conf.eth0.accept_source_route=0
net.ipv4.conf.lo.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_source_route=0
# Broadcast로부터 오는 핑을 차단함(Smurt 공격을 차단함).
net.ipv4.icmp_echo_ignore_broadcasts=1
# IP 나 TCP 헤더가 깨진 bad icmp packet을 무시한다.
net.ipv4.icmp_ignore_bogus_error_responses = 1
# 자신의 네트워크가 스푸핑된 공격지의 소스로 쓰이는 것을 차단한다.
# 모든 인터페이스에서 들어오는 패킷에 대해 reply를 하여 들어오는 인터페이스로 나가지 못하는 패킷을 거부한다.
net.ipv4.conf.eth0.rp_filter=2
net.ipv4.conf.lo.rp_filter=2
net.ipv4.conf.default.rp_filter=2
net.ipv4.conf.all.rp_filter=2
# bootp 패킷을 허용하지 않는다.
net.ipv4.conf.eth0.bootp_relay=0
net.ipv4.conf.lo.bootp_relay=0
net.ipv4.conf.default.bootp_relay=0
net.ipv4.conf.all.bootp_relay=0
# 스푸핑된 패킷이나 소스라우팅, Redirect 패킷에 대해 로그파일에 정보를 남긴다.
net.ipv4.conf.eth0.log_martians=1
net.ipv4.conf.lo.log_martians=1
net.ipv4.conf.default.log_martians=1
net.ipv4.conf.all.log_martians=1
# 1/100초에 받아들이는 igmp "memberships"의 수
net.ipv4.igmp_max_memberships=1
# 매우 복잡한 사이트에서는 이 값을 늘리는 것도 가능하지만 64로 두는 것이 적당하며
# 더 늘렸을 경우에는 큰 문제가 발생할 수도 있다.
net.ipv4.ip_default_ttl=64
# 게이트웨이 서버가 아닌 이상 패킷을 포워딩 할 필요는 없다.
net.ipv4.ip_forward=0
# fragmented packet이 메모리에 존재하는 시간을 15초로 설정한다.
net.ipv4.ipfrag_time=15
# SYN_Flooding 공격에 대한 대비로 백로그큐(Backlog Queue)가 가득차면 다른 접속 요구를 받아들이지 못한다.
net.ipv4.tcp_max_syn_backlog = 1024
# TCP 연결에서 Three-way Handshake가 성공적으로 이루어지지 않으면 더 이상 소스 경로를 거슬러 올라가지 않도록한다.
# 따라서 적절한 연결 요청에 대해서만 연결을 맺는다.
# syncookies가 작동할 때 SYN Flooding 공격이 있으면 messages 파일에 아래와 같은 내용이 출력된다.
# possible SYN flooding on port 80. Sending cookies.
net.ipv4.tcp_syncookies = 1
# 일정한 시간과 IP별로 보내고 받는 SYN 재시도 횟수를 3회로 제한한다.
# 이 옵션은 스푸핑된(위조된) 주소로 오는 SYN 연결의 양을 줄여준다.
# 기본 값은 5(180 초에 대응)이며 255를 넘지 않아야 한다.
net.ipv4.tcp_syn_retries = 3
# passive TCP 접속시도가 재접속을 하기 위한 SYNACKs의 값을 정한다. 255 보다 높
# 게 지정할 수 없다. 기본값은 5이며, 180초에 대응이 된다.
net.ipv4.tcp_synack_retries = 3
# 무언가 문제가 있을 때 연결을 위해 재시도 할 횟수, 최소 값과 기본 값은 3이다.
net.ipv4.tcp_retries1=3
# TCP 연결을 끊기 전에 재시도할 횟수.
net.ipv4.tcp_retries2=7
# 연결을 종료시 소요되는 시간을 줄여준다(기본 설정값: 60).
net.ipv4.tcp_fin_timeout=20
# 동시에 유지 가능한 timewait 소켓의 수이다.
# 만약 지정된 숫자를 초과하였을 경우에는 timewait 소켓이 없어지며 경고 메시지가 출력된다.
# 이 제한은 단순한 DoS 공격을 차단하기 위해 존재하는데, 임의로 이 값을 줄여서는 안되며
net.ipv4.tcp_max_tw_buckets = 23040000
# 연결이 끊어졌다고 판단할 때까지, 얼마나 keepalive probe 를 보낼지 결정. 기본값 9회
# 간단한 DoS 공격을 막아준다.
net.ipv4.tcp_keepalive_probes=2
# keepalive 가 활성되 되어 있을 경우, 얼마나 자주 TCP 가 keepalive 메세지를 보
# 내게 할 것인지를 설정.
net.ipv4.tcp_keepalive_time=30
# keepalive_probes 를 보낼 간격을 정함. probe 를 보낸 후, probes * intvl 의 시
# 간이 지나도록 응답이 없으면 연결이 해제된 것으로 간주하게 됨. 기본 값의 사용
# 시 11분 15초 동안 재시도를 하고 연결을 취소함. 값은 초단위
net.ipv4.tcp_keepalive_intvl = 10
# 서버 쪽에서 닫은 TCP 연결을 끊기 전에 확인하는 횟수를 정한다. 기본 값은 7 로
# RTO 50 초에서 16 분 사이에 해당한다. 웹 서버가 운영 중 이라면 이 값을 줄여서
# 소켓 등이 귀한 리소스를 소비하지 않도록 할 수도 있다.
net.ipv4.tcp_orphan_retries = 2
# SYN 패킷을 전송한 후에 로스가 발생을 하여 ACK 를 일부 받지 못했을 경우, 선택
# 적으로 (selected) 받지못한 ACK 만 받도록 요청하는 것을 허락한다. 로스가 많은
# 네트워크에서는 상당히 중요한 역할을 한다.
net.ipv4.tcp_sack = 1
Linux TCP Tuning |
There are a lot of differences between Linux version 2.4 and 2.6, so first we'll cover the tuning issues that are the same in both 2.4 and 2.6. To change TCP settings in, you add the entries below to the file /etc/sysctl.conf, and then run "sysctl -p". Like all operating systems, the default maximum Linux TCP buffer sizes are way too small. I suggest changing them to the following settings: # increase TCP max buffer size setable using setsockopt() net.core.rmem_max = 33554432 net.core.wmem_max = 33554432 # increase Linux autotuning TCP buffer limits # min, default, and max number of bytes to use # set max to at least 4MB for 1G, and 32M for 10G net.ipv4.tcp_rmem = 4096 87380 33554432 net.ipv4.tcp_wmem = 4096 65536 33554432 You should also verify that the following are all set to the default value of 1 sysctl net.ipv4.tcp_window_scaling sysctl net.ipv4.tcp_timestamps sysctl net.ipv4.tcp_sack Note: you should leave tcp_mem alone. The defaults are fine. You can achieve increases in bandwidth of up to 10x by doing this on some long, fast paths. This is only a good idea for Gigabit Ethernet connected hosts, and may have other side effects such as uneven sharing between multiple streams. Also, I've been told that for some network paths, using the Linux 'tc' (traffic control) system to pace traffic out of the host can help improve total throughput.
Linux 2.6 Starting in Linux 2.6.7 (and back-ported to 2.4.27), linux includes alternative congestion control algorithms beside the traditional 'reno' algorithm. These are designed to recover quickly from packet loss on high-speed WANs. Linux 2.6 also includes and both send and receiver-side automatic buffer tuning (up to the maximum sizes specified above). There is also a setting to fix the ssthresh caching weirdness described below. There are a couple additional sysctl settings for 2.6: # don't cache ssthresh from previous connection net.ipv4.tcp_no_metrics_save = 1 # recommended to increase this for 10G NICS net.core.netdev_max_backlog = 30000 Starting with version 2.6.13, Linux supports pluggable congestion control algorithms . The congestion control algorithm used is set using the sysctl variable net.ipv4.tcp_congestion_control, which is set to bic/cubic or reno by default, depending on which version of the 2.6 kernel you are using. To get a list of congestion control algorithms that are available in your kernel, run: sysctl net.ipv4.tcp_available_congestion_control The choice of congestion control options is selected when you build the kernel. The following are some of the options are available in the 2.6.23 kernel:
If cubic and/or htcp are not listed when you do 'sysctl net.ipv4.tcp_available_congestion_control', try the following, as most distributions include them as loadable kernel modules: /sbin/modprobe tcp_htcp /sbin/modprobe tcp_cubic For long fast paths, we highly recommend using cubic or htcp. Cubic is the default for a number of Linux distributions, but if is not the default on your system, you can do the following: sysctl -w net.ipv4.tcp_congestion_control=cubic On systems supporting RPMS, You can also try using the ktune RPM, which sets many of these as well. More information on each of these algorithms and some results can be found here . More information on tuning parameters and defaults for Linux 2.6 are available in the file ip-sysctl.txt, which is part of the 2.6 source distribution. Warning on Large MTUs: If you have configured your Linux host to use 9K MTUs, but the connection is using 1500 byte packets, then you actually need 9/1.5 = 6 times more buffer space in order to fill the pipe. In fact some device drivers only allocate memory in power of two sizes, so you may even need 16/1.5 = 11 times more buffer space! And finally a warning for both 2.4 and 2.6: for very large BDP paths where the TCP window is > 20 MB, you are likely to hit the Linux SACK implementation problem. If Linux has too many packets in flight when it gets a SACK event, it takes too long to located the SACKed packet, and you get a TCP timeout and CWND goes back to 1 packet. Restricting the TCP buffer size to about 12 MB seems to avoid this problem, but clearly limits your total throughput. Another solution is to disable SACK.
Linux 2.4 Starting with Linux 2.4, Linux implemented a sender-side autotuning mechanism, so that setting the optimal buffer size on the sender is not needed. This assumes you have set large buffers on the receive side, as the sending buffer will not grow beyond the size of the receive buffer. However, Linux 2.4 has some other strange behavior that one needs to be aware of. For example: The value for ssthresh for a given path is cached in the routing table. This means that if a connection has has a retransmission and reduces its window, then all connections to that host for the next 10 minutes will use a reduced window size, and not even try to increase its window. The only way to disable this behavior is to do the following before all new connections (you must be root): sysctl -w net.ipv4.route.flush=1 Another thing you can to help increase TCP throughput in 2.4 with 1000BT NICs is to increase the size of the interface queue. To do this, do the following: ifconfig eth0 txqueuelen 1000 More information on various tuning parameters for Linux 2.4 are available in the Ipsysctl tutorial . |
'02.서버-Linux' 카테고리의 다른 글
[리눅스]커널 튜닝 관련 내용 (0) | 2012.12.19 |
---|---|
[리눅스]오픈 파일 개수 수정 (0) | 2012.12.19 |
[리눅스]아파치 사설 인증서 설치 (0) | 2012.12.19 |
[리눅스]아파치 번역 (0) | 2012.12.19 |
[리눅스]하드디스크 점검 (0) | 2012.12.19 |