LNMP parameter optimization (without comments) and lnmp Optimization
Introduction:
PHP FastCGI advantages
1. PHP scripts run faster. The PHP interpreter program is loaded into the memory instead of reading from the memory every time it is needed, which greatly improves the performance of the website running by scripts.
2. Fewer system resources are required. Because the server no longer loads the PHP interpreter every time it needs it, it can increase the transmission speed of the site much without increasing the CPU burden.
3. Do not change the existing code. The program running on Apache + PHP can be applied to PHP FastCGI without modification.
LNMP installation documentation: http://www.cnblogs.com/wangxiaoqiangs/p/5336180.html
1. nginx. conf
User 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" $ ht Comment '; server_tokens off; Comment 128; Comment 32 k; Comment 4 32 k; Comment 300 m; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 30; fastcgi_connect_timeout 300; Comment 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64 k; fastcgi_buffers 4 64 k; fastcgi_busy_buffers_size 128 k; fastc Listen 128 k; gzip on; gzip_min_length 1 k; gzip_buffers 4 16 k; 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. 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 $ scheme; include fastcgi_params;} location ~. *\. (Gif | jpg | jpeg | png | bmp | swf) $ {expires 30d;} # This cache configuration is installed in Zabbix, an error occurs when the database connection is tested on the web page. (when the database passes the test, Zabbix cannot be installed because of the js cache when the page is redirected.) # location ~. * \. (Js | css )? $ #{# Expires 1 h ;#}} server {listen 8000; server_name localhost; location/{stub_status on; access_log off ;}}}
2, my. cnf (detailed: http://www.cnblogs.com/wangxiaoqiangs/p/5500675.html)
[client]default-character-set = utf-8port = 3306socket = /tmp/mysql.sock[mysqld]user = mysqlport = 3306socket = /tmp/mysql.sockbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataopen_files_limit = 10240back_log = 600max_connections = 3000max_connect_errors = 6000table_cache = 614external-locking = FALSEmax_allowed_packet = 32Msort_buffer_size = 2Mjoin_buffer_size = 2Mtherad_cache_size = 300thread_concurrency = 8query_cache_size = 32Mquery_cache_limit = 2Mquery_cache_min_res_unit = 2Kdefault-storage-engine = MyISAMthread_stack = 192Ktransaction_isolation = READ-COMMITTEDtmp_table_size = 246Mmax_heap_table_size = 246Mlong_query_time = 1log_long_formatlog-bin = mysql-binbinlog_cache_size = 4Mbinglog_format = MIXEDmax_binlog_cache_size = 8Mmax_binlog_size = 512Mexpire_logs_days = 7key_buffer_size = 256Mread_buffer_size = 1Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 10Gmyisam_max_extra_sort_file_size = 10Gmyisam_repair_threads = 1myisam_recoverskip-name-resolvemaster-connect-retry = 10slave-skip-errors = 1032,1062,126,1114,1146,1048,1396server-id = 1innodb_additional_men_pool_size = 16Minnodb_buffer_pool_size = 2048Minnodb_data_file_path = ibdata1:1024M:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_file_size = 128Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0[mysqldump]quickmax_allowed_packet = 32M
3, php-fpm.conf (detailed: http://www.cnblogs.com/wangxiaoqiangs/p/5336579.html)
[Global] pid = run/php-fpm.pidrlimit_files = 51200 [www] user = nginxgroup = nginx; listen = 127.0.0.1: 9000 listen =/dev/shm/php-cgi.sock; listen. back_log = 65535listen. owner = nginxlisten. group = nginx; number of processes Limit pm = dynamicpm. max_children = 128pm. start_servers = 20pm. min_spare_servers = 10 pm. max_spare_servers = 30; Enable slow query log (close after troubleshooting) request_slowlog_timeout = 3 slowlog = var/log/$ pool. slow. log
4./etc/sysctl. conf
net.ipv4.tcp_max_syn_backlog = 65536net.core.netdev_max_backlog = 32768net.core.somaxconn = 32768net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 2net.ipv4.tcp_syn_retries = 2net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_max_orphans = 3276800net.ipv4.ip_local_port_range = 1024 65535
5./etc/security/limits. conf
* soft nofile 65535* hard nofile 65535
6. reboot