ç§ãã¡ã®å€ãã«ãšã£ãŠããµã€ãã®èŠèŽè ãæ¥éã«æé·ãå§ããåŸ æã®æ¥ãæ¥ãŠããŸãã æ¯æãç§ãã¡ã¯æ¯ãåãããŠåŒåžããã°ãŒã°ã«ã®ã¢ããªãã£ãã¯ã¹ãã£ãŒããèŠãŠãäžæ¥ã«æ¬¡ã®1000人ã®èšªåè ã«ç·ãåŒããããšç¬é¡ã§ãŒãããŸãã ååãšããŠããã©ãã£ãã¯ã®å¢å ã¯æè¡ããŒã¹ã®æé·ãšäžèŽããããµã€ãã®é床ã¯äœäžãå§ããŸãã ããã§ãã·ã¹ãã 管çè ãã²ãŒã ã«å ¥ããŸã...
ã©ã®ãããžã§ã¯ãã«ãåžžã«æé©åãããã®ããããŸããwebo.inã§æé©åã®ãã³ããèªãã§ãããŒã¿ããŒã¹ã«eaccelerator ãmemcacheãã€ã³ããã¯ã¹æ€çŽ¢ãã£ãŒã«ããã€ã³ã¹ããŒã«ã§ããŸãã ããã¯ãã¹ãŠå®äºããŠãããšæããŸããããµã€ãã¯ãŸã é ãã§ãã
nginxãæé©åãããšãã§ã...
Nginxã®ã³ã³ãã€ã«
çµã¿ç«ãŠããšããç§ã¯éåžžããèªåã䜿çšããŠããªããã®ããã¹ãŠåãé¢ãããšããã«ãŒã«ã«åŸããŸãã ãã®ããã圹ã«ç«ããªãå¯èœæ§ã®ãããã£ãã«äœ¿çšãããªãã¢ãžã¥ãŒã«ïŒ mailãmail_ssl_moduleãhttp_perl_moduleãhttp_flv_moduleãhttp_dav_module ã å°æ¥ãããã€ãã®MSã¢ãžã¥ãŒã«ãå¿ èŠãªå Žåãåã³ã³ãã€ã«ã«æ°åããããŸãã
ã³ã³ãã€ã«æã«å«ããããšãæãŸããã¢ãžã¥ãŒã«ïŒ http_gzip_static_moduleãhttp_stub_status_module ã
nginx ïŒïŒ nginx_datadirã... specãã¡ã€ã«å€æ°ïŒ ãã³ã³ãã€ã«ããããã®specãã¡ã€ã«ã®äžéšã¯æ¬¡ã®ãšããã§ãã
./configure \ --prefix=%nginx_datadir \ --conf-path=%nginx_etc/nginx.conf \ --sbin-path=%{_sbindir}/%{name} \ --error-log-path=%nginx_log/nginx.error.log \ --http-log-path=%nginx_log/nginx.log \ --http-client-body-temp-path=%nginx_spool/tmp/client \ --http-proxy-temp-path=%nginx_spool/tmp/proxy \ --http-fastcgi-temp-path=%nginx_spool/tmp/fastcgi \ --pid-path=%_var/run/nginx.pid \ --user=%nginx_user \ --group=%nginx_group \ --with-cc-opt="-I %_includedir/pcre/" \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-http_perl_module
Nginx config-ã·ã³ãã«ã§æ確
Nginxã¯ç®¡çè åãã®ç®¡çè ãäœæããŸããã ãã®äºå®ã¯ãæ§æã®æ§æãšæ§æã®å®¹æãã«ãã©ã¹ã®åœ±é¿ãäžããŸããã
åçŽãªèšå®ã®æŠèŠã説æãããã®ãã£ã¬ã¯ãã£ããåæããŸãã
user nginx; # , worker_processes 8; # gettimeofday(), timer_resolution 100ms; # RLIMIT_NOFILE . worker_rlimit_nofile 8192; # -20 20 ( ). worker_priority -5; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 2048; # use kqueue; freebsd ( ) use epoll; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; # sendfile(). sendfile() , , # . sendfile on; keepalive_timeout 65; gzip on; gzip_min_length 1100; gzip_buffers 64 8k; gzip_comp_level 3; gzip_http_version 1.1; gzip_proxied any; gzip_types text/plain application/xml application/x-javascript text/css; # Load config files from the /etc/nginx/conf.vs directory include /etc/nginx/conf.vs/*.conf; }
åçŽãªä»®æ³ãµãŒããŒæ§æã®äŸïŒ
server { listen 80; server_name _; location / { gzip_static on; root /var/nginx/html; index index.html index.htm; } error_page 404 /404.html; location = /404.html { root /var/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/nginx/html; } }
ããã€ãã®æ什ã«ã€ããŠã³ã¡ã³ãããŸããããããã€ãã¯åŸã§æ€èšããŸãã 泚æãã¹ãäž»ãªããšã¯ãã»ãšãã©ã®å Žåãããã¥ã¡ã³ãããªããŠãæ§æãç解ã§ããããšã§ãã
NginxãµãŒããŒã®ç£èŠ
nginx configã§ã¯ãã»ã¯ã·ã§ã³ãèŠå®ããŸã
location = /stat { stub_status on; access_log off; allow xx.xx.xx.xx; deny all; }
çŸåšãnginxã®çµ±èšã¯http://simple.com/statã§è¡šç€ºã§ããŸãã
䟿å®äžãnginxã«ãã£ãŠãã¹ããããŠããapacheã®çµ±èšãæ§æããããšããå§ãããŸãã ãããè¡ãã«ã¯ããŸãmod_rpafã¢ãžã¥ãŒã«ãã€ã³ã¹ããŒã«ããŸããããã«ãããApacheã¯IP nginxã§ã¯ãªãã¯ã©ã€ã¢ã³ãã®IPã¢ãã¬ã¹ããèŠãã ããšãã§ããŸã ïŒ ããã§ã¯ãç§ã®ããŒãžã§ã³ã®rpaf srpmãããŠã³ããŒãããŠã³ã³ãã€ã«ã§ããŸã ïŒã
LoadModule rpaf_module modules/mod_rpaf-2.0.so # # Mod rpaf # RPAFenable On RPAFsethostname On RPAFproxy_ips 127.0.0.1 xx.xx.xx.xx RPAFheader X-Forwarded-For
åæ§ã®æ©èœãæäŸãã代æ¿ã¢ãžã¥ãŒã«mod_extract_forwardedããããŸãïŒFedoraãªããžããªã§å©çšå¯èœïŒã ïŒ ãã£ã¢ã·ã£ã«æè¬ïŒ
çµ±èšè¡šç€ºã¢ãžã¥ãŒã«ãæ¥ç¶ããŸãã
ExtendedStatus On SetHandler server-status Deny from all Allow from xx.xx.xx.xx
çŸåšãApacheã®çµ±èšã¯http://simple.com/apache-statã§è¡šç€ºã§ããŸãã
éçã³ã³ãã³ãã®çš®é¡
æ¡ä»¶ä»ãã§éçã2ã€ã®ã«ããŽãªã«åå²ããŸãã
ãµã€ãã®é床ãäœäžãå§ãããã©ãããã
ãŸãããŸãããããã¯ã«ãªããªãã§ãã ããã ãããããããªãã®ãµã€ãã§äººæ°ãåºãã®ã¯ãã®ç¬éã§ã:)
ååãšããŠãã¹ããŒããŠã³ããã®ã¯nginxã§ã¯ãªããããã¯ãšã³ãïŒåçã³ã³ãã³ããçæãããµãŒããŒïŒããŸãã¯ããããããšã§ãããããŒã¿ããŒã¹ãµãŒããŒããã£ã¹ã¯é åãäžè¶³ããã¹ãŒããŒãã¥ããŒã¢ãã©ã€ã¶ãŒãèµ·åããŠãã¹ãŠã®ãªãœãŒã¹ãååŸããŸãã
ãã®èšäºã§ã¯ãnginxãçãããå Žåã«ã€ããŠæ€èšããŸãã ãµãŒããŒã®åé¡ãäžæçã«ç·©åããããã«ãäœã匷åã§ããŸããïŒ
- worker_processesã®æ°ãå¢ãããŠã¿ãŠãã ãããnginxã®äœæè ã¯ãã³ã¢ã®æ°ã«å¿ããŠããããã€ã³ã¹ããŒã«ããããšããå§ãããŸãã ãã®æ°ã¯ããã³ã¢ã®æ°ãããã³ã¢ã®æ°x 2ãã®ç¯å²ã§ã»ãŒå€åããŸããããæ¥ç¶ã®ç¢ºç«ã¯é«éã«ãªããŸããããhttp-requestã®åŠçã¯åžžã«å¹ççã§ã¯ãããŸããã worker_connectionsïŒ1人ã®ã¯ãŒã«ãŒã®ã³ãã¯ã·ã³ã®æ倧æ°ïŒããŸã ããããšãå¿ããªãã§ãã ãã
- worker_priorityã-5以äžã«èšå®ãããšåœ¹ç«ã¡ãŸãïŒæ倧-20ïŒã ä»ã®ãµãŒãã¹ãèããé ããªãå§ããå¯èœæ§ããããããããã§æ³šæããŠãã ããã ãµãŒããŒã§ã¯ããã®ãªãã·ã§ã³ã¯-5ã«èšå®ãããŠããŸãã å€ãäœãã»ã©ãnginxã®åªå 床ãé«ããªããŸã
- å°ããªãã¡ã€ã«ã®å€§éã®åºåãšäœéã®ããŒããã©ã€ãã䜿çšãããšãaccess_log offãã°ã®äžæçãªã·ã£ããããŠã³ã圹ç«ã¡ãŸãã
- UPDïŒnoatimeãªãã·ã§ã³ã䜿çšããŠãé åžå ã®ãã£ã¹ã¯ãããŠã³ãããŸããããã«ããããã£ã¹ã¯ãžã®æžã蟌ã¿æäœã®åæ°ãæžããŸãã ïŒ coolspot ã pwlnw ã alfaã®ã¢ã€ãã¢ãããããšãïŒ
- ããã«ããã¯ãæ¢ããŠãä¿®æ£ã§ããŸãã ã³ãã³ãã圹ç«ã¡ãŸãïŒtopãiostatãdf -hãiptraf
- RAMãè¿œå ãããããã£ã¹ã¯ã·ã¹ãã ãã¢ããã°ã¬ãŒãããŸãïŒããšãã°ãRAIDã¢ã¬ã€ãã€ã³ã¹ããŒã«ããSSDããŒããã©ã€ããè©Šãããšãã§ããŸãïŒ
æé©åãã¯ããã¯
軜éã³ã³ãã³ã
- ä»®æ³ãã£ã¹ã¯ã
ä»®æ³ãã£ã¹ã¯ïŒtmpfsãŸãã¯ramfsïŒããã©ã«ããŒjsãcssãã€ã¡ãŒãžïŒã³ã³ãã³ãã§ã¯ãªããã¶ã€ã³ã«é¢é£ããç»åãå°éããå ŽåïŒãäœæããããã«è»¢éããnginx configã«åå¥ã«æžã蟌ã¿ãŸãå Žæ/ js / {
åèµ·åæã«ä»®æ³ãã£ã¹ã¯ãèªåçã«äœæãããããã«ããã«ã¯ã / etc / fstabã«è¿œå ããŸã
ã«ãŒã/var/www/img_virtual/auto.ria.ua/js
}
...
ãªã/ var / www / img_virtual tmpfsãµã€ãº= 1gãã¢ãŒã= 1777 0 0
ïŒèµ·åæã«ã1Gãã£ã¹ã¯ãèªåçã«äœæãããŸãïŒ
ããã§ã¯ã次ã®ç¶æ³ã«æ³šæããå¿ èŠããããŸããéçãã¡ã€ã«ãã·ã¹ãã ãã£ãã·ã¥ã«èœã¡ãå Žåãã·ã¹ãã ãã£ãã·ã¥ããã®æ»ãé床ã¯ä»®æ³ãã£ã¹ã¯ããã®æ»ãé床ã«çãããªããŸãã èšãæãããšãé åžããããã¹ãŠã®ã軜ããéçã®ç·éãå°ãªãå Žåãä»®æ³ãã£ã¹ã¯ã®å¿ èŠã¯ãããããŸããïŒãã¹ããå®è¡ããŠããã確èªããããã«ä¿ããŠãããmaxpã«æè¬ããŸãïŒ
- Gzipã³ã³ãã³ãã®å§çž®
ä»®æ³ãã©ã«ããŒã§å®è¡ããfor i in `find ./* -type f -name '* .js'`; ãšã³ãŒ$ i; gzip -c -9 $ i> $ i.gz; å®äº;
nginxæ§æã§ã次ã®è¡ã«gzip_staticãè¿œå ããŸãã
for i in `find ./* -type f -name '* .css'`; ãšã³ãŒ$ i; gzip -c -9 $ i> $ i.gz; å®äº;
å Žæ/ js / {
åçãã¡ã€ã«ã®ãªã³ã©ã€ã³ããã±ãŒãžãæå¹ã«ããããšãã§ããŸãã
gzip_static on;
ã«ãŒã/var/www/img_virtual/auto.ria.ua/js
}
å Žæ/ {
gzip on;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_comp_level 3;
gzip_typesããã¹ã/ãã¬ãŒã³ã¢ããªã±ãŒã·ã§ã³/ xmlã¢ããªã±ãŒã·ã§ã³/ x-javascriptããã¹ã/ css;
ã«ãŒã/var/www/auto.ria.ua/
}
- ã³ã³ãã³ããããã·ããããŒ
ããããŒã§éçã³ã³ãã³ãã®æå¹æéãæå®ãããšãè² è·ã軜æžãããŸãã ãã®ããã«ã expiresãã£ã¬ã¯ãã£ãã䜿çšããŸã ã ã³ã³ãã³ããå€æŽãããªãå Žåãexpires maxã䜿çšã§ããŸãã 1dãæéåãã«ããŠããè¯ãçµæãåŸãããŸãã - ãã¡ã€ã«èšè¿°åãã£ãã·ã¥
ããã«ããããã£ã¬ã¯ããªéå±€ãæ¡åŒµãããå°ããªãã¡ã€ã«ãå€æ°ããå Žåã«ããã©ãŒãã³ã¹ãåäžããŸãã ååšããªããã¡ã€ã«ãžã®ã¢ã¯ã»ã¹ããã£ãã·ã¥ããããšãã§ããŸãã 次ã®ããã«ãªããŸããå Žæ/ {
root / var / www /;
open_file_cache max = 1024éã¢ã¯ãã£ã= 600s;
open_file_cache_valid 2000s;
open_file_cache_min_uses 1;
open_file_cache_errors on;
}
éãã³ã³ãã³ã
- ãŸããã³ã³ãã³ãã®é
ä¿¡æã«ã¹ã¯ããã䜿çšãããŠãããã©ããã«æ³šæããå¿
èŠããããŸãã ã¹ã¯ããã䜿çšãããŠããå Žåã ã¹ã¯ãããéåžžã®SATAããŒããã©ã€ãã«ããå Žåã¯åé¡ã«ãªããŸãã Swingã¯sendfileã«ãŒãã«ã®æ¹æ³ã奜ãã§ã確ãã«ããã°ã¬ãã·ããã¯ãããžãŒã§ããã swapã䜿çšãããšãªã¿ãŒã³ã«å€§ãã圱é¿ãã sendfileãã£ã¬ã¯ãã£ãã§sendfileãç¡å¹ã«ãã output_buffers 2 64kãªã©ã®æé©ãªåºåãéžæããããšããŸãã
sendfileããªãã«ããæ§æäŸïŒsendfile off;
å€ãã¯ã·ã¹ãã ã§äœ¿çšãããã«ãŒãã«ã«äŸåãããšããäºå®ã«æ³šæãåèµ·ããŸããããã¯kernels = 2.6.27ã§å©ãã«ãªããŸããã
tcp_nodelay on;
output_buffers 2 64k;
- RAMãèš±ãã°ãæãèŠæ±ã®å€ããã¡ã€ã«ãé
眮ããä»®æ³ãã£ã¹ã¯ãäœæããŸããããšãã°ã10åããšã«ããããã®ãã¡ã€ã«ã®ãªã¹ãã調æŽã§ããŸãã ããã§ã try_filesãã£ã¬ã¯ãã£ããé©çšã§ããŸãã
å Žæ/ {
ãã¡ã€ã«ãèŠã€ãããªãå Žåãããã¯ãšã³ãã¯ä»®æ³ãã£ã¹ã¯äžã§ã¢ã¯ã»ã¹ãããŸãã
root / var / www /;
try_files / img_virtual / hot / $ uri ã¹ãã¬ãŒãž ;
}
ãã±ãŒã·ã§ã³ã¹ãã¬ãŒãž {
proxy_pass httpïŒ//ããã¯ãšã³ã;
proxy_set_header Host $ host;
}
éåžžãããããã³ã³ãã³ããã¯å šäœã®10ïŒ æªæºã§ãã
ãã£ãã·ã¥åœ¢æããã°ã©ã ãäœæã§ããªãå Žåã¯ã proxy_storeãã£ã¬ã¯ãã£ãã䜿çšããŸããã±ãŒã·ã§ã³ã¹ãã¬ãŒãž {
ãã®æ§æã§ã¯ãèŠæ±ãããåãã¡ã€ã«ããã£ãã·ã¥ãããŸãã
proxy_pass httpïŒ//ããã¯ãšã³ã;
proxy_set_header Host $ host;
proxy_store on;
proxy_store_accessãŠãŒã¶ãŒïŒrwã°ã«ãŒãïŒrw allïŒr;
proxy_temp_path / var / www / img_virtual / hot /;
root / var / www / img_virtual / hot /;
}
æéãçµã€ã«ã€ããŠãã¯ã©ãŠã³ãå®è¡ããæãç°¡åãªæ¹æ³ã§ãããã£ãã·ã¥ãäœããã®æ¹æ³ã§ã¯ãªãŒã³ã¢ããããå¿ èŠããããŸããcd / var / www / img_virtual / hot /
ïŒãã¡ã€ã«ããã£ãã·ã¥ãã60å以äžèŠæ±ãããªãå Žåãåé€ããŸãïŒ
find ./ -type f -amin +60 -delete
- ã¹ãã¬ãŒãžã倧ããå Žåããã©ãã€ããããããŸã-åé¡ã¯éçšäžè§£æ±ºã§ããŸããã ããã³ããšã³ãã§RAIDãæ§ç¯ã§ããŸãã ãã§ã€ã¯ã¬ã€ãã䜿çšããããšã¯ãå§ãããŸãããããã¯ã¢ããã°ã¬ãŒãæãå ãæ¶ãããšãã«é çã®çš®ã§ãïŒ SASããžãå¢ãããæ¬æ ŒçãªRAIDã³ã³ãããŒã©ãŒã䜿çšããŸãïŒhostraidã¯ãããŸããïŒïŒã ã¹ã¯ãããã¹ããŒã«ãããã³ãã£ãã·ã¥ãããã«ããŠã³ãããã³ã³ãã³ããé »ç¹ã«å€æŽããããã£ãã·ã¥ãé »ç¹ã«æžãæããªãããã«ããã«ã¯ãSSDããŒããã©ã€ãã䜿çšã§ããŸãã ããã¯ããã«åäœããŸãããã®ãããªããŒããã©ã€ãã«ã¯ãã·ãŒã¯ããŒã·ãŒã¯ãäœæ¶è²»é»åïŒIntel X25-M 0.15Wãªã©ïŒãè¯å¥œãªè»¢éé床ïŒæ倧250 MB / sïŒãªã©ã®ç¹æ§ããããŸããã
- ãããã·ããããªã¯ãšã¹ãããã£ãã·ã¥ããŸãã
2009幎3æ23æ¥ã«ã次ã®ããŒã¿çnginx 0.7.44ããªãªãŒã¹ãããŸããããã®ãªãªãŒã¹ã§ã¯ããããã·ããããªã¯ãšã¹ãããã£ãã·ã¥ããããã®å®éšçãªãµããŒããç»å ŽããŸããã nginxãŠãŒã¶ãŒã«ãšã£ãŠãã®ã€ãã³ãã®éèŠæ§ãé倧è©äŸ¡ããããšã¯å°é£ã§ãã èè nginxã¯ã倧éã®éé»æ°ã®ååžã管çãã匷åãªããŒã«ãæäŸããŠãããŸãã
ãªããã®ãããªãã£ãã·ã¥ãå¿ èŠãªã®ã§ããïŒ ãã®è³ªåã«å¯Ÿããçãã¯ãäž»ã«ãã£ã¹ã¯æäœãšãããã¯ãŒã¯æäœã®ç°ãªããã³ã¹ããã«é¢é£ããŠããŸãã å€ãã®å Žåããã£ã¹ã¯ã«ãè¡ããããšã¯ããããã¯ãŒã¯ã«ã¢ã¯ã»ã¹ãããããã¯ããã«ãå®ãããªããŸãã ãã®ãããªãã£ãã·ã³ã°ã®äž»ãªç®çã¯ãå¿ èŠãªæå°éã®ãããã¯ãŒã¯æäœãšãã£ã¹ã¯ãã£ãã·ã¥ã®ãã€ã³ããªãžã§ã³ã管çããåæžããããšã§ãã
ãããã·èŠæ±ã®ãã£ãã·ã¥èšå®ã®è©³çŽ°ãã芧ãã ããã