LoginSignup
49
64

More than 5 years have passed since last update.

以前会社で使っていたsysctlとさらに改良

Last updated at Posted at 2017-03-05

私が商用に作った環境で入れていた設定。
全部自分で調べて設定したため
参考にしたサイトも含め公開します。
CentOS6を想定。
それ以降は別途カーネル3.0以降の機能を見てください。

sysctl以外の設定は
CentOSユーザがUbuntu16.04にMySQL構築してドツボにはまる(徹底チューニング編)
を参考にしてください

サーバ関係なくいれる設定

IPv6無効

# How do I disable IPv6? - FAQ/CentOS6 - CentOS Wiki

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

極力スワップさせない

# OOM relation to vm.swappiness=0 in new kernel; kills MySQL server process

vm.swappiness = 1

kernel4.6からは0で問題ないかもしれないが未調査

メモリの使用量制御をコントロールする

# About vm.overcommit_memory

vm.overcommit_memory=1

きちんと制御できるなら1がベスト
複数アプリが稼働しているなら2にせざるを得ない

TCP再送回数

# ウェブ広告のインフラについて(第5回) LinuxのTCP再送アルゴリズムとモバイルネットワークの相性の悪さ | 多脚.com

net.ipv4.tcp_orphan_retries = 3

keepalive先の通信状況確認

# High Performance Browser Networking - 愛と勇気と缶ビール

net.ipv4.tcp_slow_start_after_idle = 0

SYN Flood攻撃対策

# listen backlog 【3.6】 - Linuxカーネルメモ

net.ipv4.tcp_syncookies = 1

相手がいないのにESTABLISHEDになる

# 相手がいないのに ESTABLISHED になってる TCP ポート - @tmtms のメモ

net.ipv4.tcp_abort_on_overflow=1

TCPのオプションを無効

# net.ipv4.tcp_tw_recycle は廃止されました ― その危険性を理解する
net.ipv4.tcp_tw_recyclは4.12から廃止

net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0

Oracleの設定がいいんじゃないかとそのまま入れた部分

# Installing the Oracle Database Software

kernel.sem = 250 32000 100 128
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
fs.file-max = 681574

NoSQLや1Gbps以上のトラフィックがあるならCassandraをベースに

# Recommended production settings for Apache Cassandra

net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.rmem_default = 16777216
net.core.wmem_default = 16777216
net.core.optmem_max = 40960
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
vm.max_map_count = 1048575

その他設定

# @IT:Linuxでは表示できないWebサイトがある

net.ipv4.tcp_ecn = 1

# あまり知られていない設定 - Linux Advanced Routing & Traffic Control HOWTO

net.ipv4.tcp_rfc1337 = 1

# Linux におけるソケット機能の向上

net.ipv4.tcp_sack = 1
net.ipv4.tcp_fack = 1

送信用TCPポート範囲

#NAT、リバースプロクシ用
#net.ipv4.ip_local_port_range = 1024 65000

サーバの種類で変えた方がいい設定

TCP再送回数の設定

フェイルオーバーのかかる時間で設計、
フェイルオーバーしなくていいなら2回までとする。
# LinuxのTCP SYNの再送間隔の初期値が3秒から1秒に変更されていた - 元RX-7乗りの適当な日々

net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2

KEEPALIVEの設定

# CLOSE_WAITのセッションを早く消す方法 – Hiro Fukami's Blog

#フロント用サーバ(PC)
#net.ipv4.tcp_keepalive_time = 5
#net.ipv4.tcp_keepalive_intvl = 2
#net.ipv4.tcp_keepalive_probes = 5

#フロント用サーバ(mobile)
#net.ipv4.tcp_keepalive_time = 10
#net.ipv4.tcp_keepalive_intvl = 2
#net.ipv4.tcp_keepalive_probes = 10

#それ以外のサーバ
#net.ipv4.tcp_keepalive_time = 60
#net.ipv4.tcp_keepalive_intvl = 2
#net.ipv4.tcp_keepalive_probes = 60

FINで強制的に接続を切る

# ぜんぶTIME_WAITのせいだ! - Qiita

net.ipv4.tcp_fin_timeout = 30

高負荷時の動作安定

# DSAS開発者の部屋:高負荷サイトのボトルネックを見つけるには
# LinuxのTCP/IPの実装について調べてみた - nyantの日記

net.core.netdev_max_backlog = 4096
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 4096

スループット重視(未検証)

# Linux におけるソケット機能の向上

net.ipv4.tcp_low_latency = 0

ディスク性能で変わるミドルウェアの場合いじると効果がある(未検証)

# Better Linux Disk Caching & Performance with vm.dirty_ratio

#vm.dirty_background_ratio = 5
#vm.dirty_ratio = 80
49
64
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
49
64