Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

NginxとOSカーネルの設定をチューニングしてパフォーマンスを上げる

Last updated at Posted at 2018-11-18

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 )

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?