Ubuntu 18 でサーバーを立てているという前提で。
OSカーネルチューニング
sysctl.conf
を nano で開く。
sudo cp /etc/sysctl.conf /etc/sysctl.conf_copy
sudo nano /etc/sysctl.conf
下記の記述を加える。
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.nf_conntrack_max = 1053616
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.tcp_rmem = 4096 349520 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_fin_timeout = 5
net.ipv4.tcp_syn_retries = 3
net.ipv4.tcp_synack_retries = 3
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 10000 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_rfc1337 = 1
net.ipv4.tcp_fin_timeout = 5
net.ipv4.tcp_max_tw_buckets = 65536
net.ipv4.tcp_orphan_retries = 0
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_slow_start_after_idle = 0
net.core.netdev_max_backlog = 65536
net.ipv4.tcp_max_syn_backlog = 65536
net.ipv4.conf.eth180.arp_ignore = 1
net.ipv4.conf.eth180.arp_announce = 2
net.core.somaxconn = 65535
vm.swappiness = 0
vm.overcommit_memory = 2
vm.overcommit_ratio = 99
kernel.shmall = 68719476736
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.sysrq = 0
反映させる。
sudo sysctl -p
(参考にしたもの https://qiita.com/sion_cojp/items/c02b5b5586b48eaaa469 )
Nginxチューニング
nginx.conf
を nano で開く。
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf_copy
sudo nano /etc/nginx/nginx.conf
下記のように追加変更する。
/etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
worker_rlimit_nofile 100000; ## 追加
events {
worker_connections 4000; ## 変更
multi_accept on; ## 変更
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log off; ## 変更
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
反映させる。
sudo service nginx restart
(参考にしたもの https://gist.github.com/denji/8359866 )