簡介: PHP FastCGI 優點 1、PHP 腳本運行速度更快。PHP 解釋程式被載入記憶體而不用每次需要時從存儲器讀取,極大的提升了依靠腳本運行站點的性能。 2、需要使用的系統資源更少。由於伺服器不再每次需要時都載入 PHP 解釋程式,可以將站點的傳輸速度提升很多而不必增加 CPU 負擔。 3、 ...
簡介:
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