1.文件句柄

  liunx 一切皆文件,文件句柄就是一个索引

2.设置方式

  系统全局性修改

  用户局部性修改

  进程局部性修改

3.用户的文件句柄限制

cat /etc/security/limits.conf


root soft nofile 65535   # root用户   soft 软连接
root hard nofile 65535  # root用户   hard  硬连接
* soft nofile 65535    # * 所有用户
* hard nofile 65535   # * 所有链接

4.进程文件句柄的限制

vim /etc/nginx/nginx.conf


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 65535;   # 进程的文件句柄限制

events {
    worker_connections  1024;
}

  

 

1.cpu 亲和

cat /proc/cpuinfo | grep 'physical id' | sort|uniq|wc -l  # 查看物理机有几个CPU
cat /proc/cpuinfo | grep 'cpu cores'|uniq    # 查看cup核数

2.查看nginx进程绑定的cpu

ps -eo pid,args,psr | grep [n]ginx

3.nginx.conf配置

user  nginx;
worker_processes  16;
#worker_cpu_affinity 0000000000000010 0000000000000010 0000000000000100 0000000000001000 0000000000010000 0000000000100000 0000000001000000 0000000010000000 0000000100000000 0000001000000000 0000010000000000 0000100000000000 0001000000000000 0010000000000000 0100000000000000 1000000000000000;
#worker_cpu_affinity 1010101010101010 0101010101010101;
worker_cpu_affinity auto;   # 自动绑定CPU


error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 35535;    # 进程的文件句柄

events {
    use epoll;
    worker_connections  10240;   # 限制每个worke进程处理多少个连接
}



http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    #######
    #Charset
    charset utf-8;    # 字符集编码

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$request_uri"';

    access_log  /var/log/nginx/access.log  main;
    access_log  off;  # 关闭日志
    
    #######
    #Core modlue
    sendfile        on;
    #tcp_nopush     on;
    #tcp_nodeny     on;
    keepalive_timeout  65;
    
    ########
    #Gzip module
    gzip  on;
    gzip_disable "MSIE [1-6]\.";  
    gzip_http_version 1.1; 
    
    ########
    #Virtal Server
    include /etc/nginx/conf.d/*.conf;
}