• LNMP 参数调优 ( 无注释 )



    简介:

    PHP FastCGI 优点

    1、PHP 脚本运行速度更快。PHP 解释程序被载入内存而不用每次需要时从存储器读取,极大的提升了依靠脚本运行站点的性能。
    2、需要使用的系统资源更少。由于服务器不再每次需要时都载入 PHP 解释程序,可以将站点的传输速度提升很多而不必增加 CPU 负担。
    3、不需要对现有的代码作任何改动。运行在 Apache + PHP 上的程序,无需修改即可适用于 PHP 的 FastCGI。

    LNMP 安装文档:http://www.cnblogs.com/wangxiaoqiangs/p/5336180.html

    1、nginx.conf

    user nginx nginx;
    worker_processes 4;
    error_log /usr/local/nginx/logs/nginx_error.log crit;
    pid /usr/local/nginx/logs/nginx.pid;
    
    worker_rlimit_nofile 51200;
    events
    {
      use epoll;
      worker_connections 51200;
    }
    
    http
    {
      include mime.types;
      default_type application/octet-stream;
    
      log_format access '$remote_addr - $remote_user [$time_local] "$request"'
                        '$status $body_bytes_sent "$http_referer"'
                        '"$http_user_agent" $http_x_forwarded_for';
    
      server_tokens off;
      server_names_hash_bucket_size 128;
      client_header_buffer_size 32k;
      large_client_header_buffers 4 32k;
      client_max_body_size 300m;
    
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 30;
    
      fastcgi_connect_timeout 300;
      fastcgi_send_timeout 300;
      fastcgi_read_timeout 300;
      fastcgi_buffer_size 64k;
      fastcgi_buffers 4 64k;
      fastcgi_busy_buffers_size 128k;
      fastcgi_temp_file_write_size 128k;
    
      gzip on;
      gzip_min_length 1k;
      gzip_buffers 4 16k;
      gzip_http_version 1.0;
      gzip_comp_level 2;
      gzip_types text/plain application/x-javascript text/css application/xml;
      gzip_vary on;
    
      server
      {
        listen 80;
        server_name localhost;
        index index.php index.html index.htm;
        root /usr/local/nginx/html;
    
        charset utf-8;
    
        access_log /usr/local/nginx/logs/access.log access;
    
        location ~ .*.(sh|bash)?$ { return 403; }
    
        location ~ .*.(php|php5)?$ {
          fastcgi_pass unix:/dev/shm/php-cgi.sock; # 127.0.0.1:9000
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
          include fastcgi_params;
        }
    
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
        {
          expires 30d;
        }
    
      # 该缓存配置,安装 Zabbix 中,网页上测试数据库连接时会出错 ( 测试数据库通过,跳转页面时,由于有 js 缓存,导致又跳回了没有验证时的页面,Zabbix 无法继续安装 ) 
      # location ~ .*.(js|css)?$
      # {
        # expires 1h;
      # }
      }
    
      server
      {
        listen 8000;
        server_name localhost;
    
        location / {
          stub_status on;
          access_log off;
        }
      }
    }

    2、my.cnf(详细:http://www.cnblogs.com/wangxiaoqiangs/p/5500675.html

    [client]
    default-character-set = utf-8
    port = 3306
    socket = /tmp/mysql.sock
    
    [mysqld]
    user = mysql
    port = 3306
    
    socket = /tmp/mysql.sock
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    
    open_files_limit = 10240
    back_log = 600
    max_connections = 3000
    max_connect_errors = 6000
    table_cache = 614
    external-locking = FALSE
    max_allowed_packet = 32M
    sort_buffer_size = 2M
    join_buffer_size = 2M
    therad_cache_size = 300
    thread_concurrency = 8
    
    query_cache_size = 32M
    query_cache_limit = 2M
    query_cache_min_res_unit = 2K
    
    default-storage-engine = MyISAM
    thread_stack = 192K
    transaction_isolation = READ-COMMITTED
    tmp_table_size = 246M
    max_heap_table_size = 246M
    long_query_time = 1
    log_long_format
    
    log-bin = mysql-bin
    binlog_cache_size = 4M
    binglog_format = MIXED
    max_binlog_cache_size = 8M
    max_binlog_size = 512M
    expire_logs_days = 7
    
    key_buffer_size = 256M
    read_buffer_size = 1M
    read_rnd_buffer_size = 16M
    bulk_insert_buffer_size = 64M
    myisam_sort_buffer_size = 128M
    myisam_max_sort_file_size = 10G
    myisam_max_extra_sort_file_size = 10G
    myisam_repair_threads = 1
    myisam_recover
    
    skip-name-resolve
    master-connect-retry = 10
    slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
    
    server-id = 1
    
    innodb_additional_men_pool_size = 16M
    innodb_buffer_pool_size = 2048M
    innodb_data_file_path = ibdata1:1024M:autoextend
    innodb_file_io_threads = 4
    innodb_thread_concurrency = 8
    innodb_flush_log_at_trx_commit = 2
    innodb_log_file_size = 128M
    innodb_log_files_in_group = 3
    innodb_max_dirty_pages_pct = 90
    innodb_lock_wait_timeout = 120
    innodb_file_per_table = 0
    
    [mysqldump]
    quick
    max_allowed_packet = 32M

    3、php-fpm.conf (详细:http://www.cnblogs.com/wangxiaoqiangs/p/5336579.html

    [global]
    pid = run/php-fpm.pid
    rlimit_files = 51200
    
    [www]
    user = nginx
    group = nginx
    ;listen = 127.0.0.1:9000
    listen = /dev/shm/php-cgi.sock
    ;listen.back_log = 65535
    listen.owner = nginx
    listen.group = nginx
    
    ; 进程数限制
    pm = dynamic
    pm.max_children = 128
    pm.start_servers = 20
    pm.min_spare_servers = 10
    pm.max_spare_servers = 30
    
    ; 开启慢查询日志 ( 排除原因后关闭 )
    request_slowlog_timeout = 3
    slowlog = var/log/$pool.slow.log

    4、/etc/sysctl.conf

    net.ipv4.tcp_max_syn_backlog = 65536
    net.core.netdev_max_backlog = 32768
    net.core.somaxconn = 32768
    
    net.core.wmem_default = 8388608
    net.core.rmem_default = 8388608
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216
    
    net.ipv4.tcp_timestamps = 0
    net.ipv4.tcp_synack_retries = 2
    net.ipv4.tcp_syn_retries = 2
    
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_tw_reuse = 1
    
    net.ipv4.tcp_mem = 94500000 915000000 927000000
    net.ipv4.tcp_max_orphans = 3276800
    
    net.ipv4.ip_local_port_range = 1024 65535

    5、/etc/security/limits.conf

    * soft nofile 65535
    * hard nofile 65535

    6、reboot

  • 相关阅读:
    序列化
    gdb core dump调试
    QT下使用QCustomPlot绘制曲线
    windows、linux通过ftp从ftp服务器上传和下载
    html、java、mysql数据交互之数据分页显示
    html、java、mysql数据交互
    使用纯C函数指针调用C++的类成员函数
    设计模式指六-Adapter模式
    设计模式之五-Facade模式
    设计模式之四-Factory模式
  • 原文地址:https://www.cnblogs.com/wangxiaoqiangs/p/5500709.html
Copyright © 2020-2023  润新知