锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲人成电影网站,亚洲日韩v无码中文字幕,亚洲精品无码mv在线观看网站http://www.tkk7.com/Skynet/archive/2010/01/31/311426.html鍒樺嚡姣?/dc:creator>鍒樺嚡姣?/author>Sun, 31 Jan 2010 15:08:00 GMThttp://www.tkk7.com/Skynet/archive/2010/01/31/311426.htmlhttp://www.tkk7.com/Skynet/comments/311426.htmlhttp://www.tkk7.com/Skynet/archive/2010/01/31/311426.html#Feedback0http://www.tkk7.com/Skynet/comments/commentRss/311426.htmlhttp://www.tkk7.com/Skynet/services/trackbacks/311426.html

浣滆?NetSeek  http://www.linuxtone.org (IT榪愮淮涓撳緗憒闆嗙兢鏋舵瀯|鎬ц兘璋冧紭)
嬈㈣繋杞澆,杞澆鏃惰鍔″繀浠ヨ秴閾炬帴褰㈠紡鏍囨槑鏂囩珷鍘熷鍑哄鍜屼綔鑰呬俊鎭強(qiáng)鏈0鏄?
棣栧彂鏃墮棿: 2008-11-25     鏇存柊鏃墮棿:2009-1-14

鐩?褰?br /> 涓銆?nbsp;       Nginx 鍩虹鐭ヨ瘑
浜屻?nbsp;       Nginx 瀹夎鍙?qiáng)璋冭?/em>
涓夈?nbsp;       Nginx Rewrite
鍥涖?nbsp;       Nginx Redirect
浜斻?nbsp;       Nginx 鐩綍鑷姩鍔犳枩綰?
鍏?nbsp;       Nginx Location
涓冦?nbsp;       Nginx expires
鍏?nbsp;       Nginx 闃茬洍閾?/em>
涔?jié)銆?nbsp;       Nginx 璁塊棶鎺у埗
鍗併?nbsp;       Nginx鏃ュ織澶勭悊
鍗佷竴銆?nbsp;    Nginx Cache
鍗佷簩銆?nbsp;    Nginx璐熻澆鍧囪 
鍗佷笁銆?      Nginx綆鍗曚紭鍖?/em>      
鍗佸洓銆?nbsp;       濡備綍鏋勫緩楂樻ц兘鐨凩EMP鐜
鍗佷簲銆?nbsp;       Nginx鏈嶅姟鐩戞帶
鍗佸叚銆?nbsp;       甯歌闂涓庨敊璇鐞?
鍗佷竷銆?nbsp;       鐩稿叧璧勬簮涓嬭澆

銆愬墠璦銆戯細(xì)
緙栧啓姝ゆ妧鏈寚鍗楀湪浜庢帹騫挎櫘鍙?qiáng)NGINX鍦ㄥ浗鍐呯殑浣跨敤錛屾洿鏂逛究鐨勫府鍔╁ぇ瀹朵簡瑙e拰鎺屾彙NGINX鐨勪竴浜涗嬌鐢ㄦ妧宸с傛湰鎸囧崡寰堝鎶宸ф潵鑷簬緗戠粶鍜屽伐浣滀腑鎴栫綉緇滀笂鏈嬪弸浠棶鎴戠殑闂.鍦ㄦ瀵圭綉緇滀笂鎰挎剰鍒嗕韓鐨勬湅鍙嬩滑琛ㄧず鎰熻阿鍜岃嚧鎰忥紒嬈㈣繋澶у鍜屾垜涓璧蜂赴瀵屾湰鎶鏈寚鍗楁彁鍑烘洿濂界殑寤鴻錛佽鏈嬪弸浠叧娉? http://www.linuxtone.org 鎶鏈垎浜ぞ鍖? 浜掓兂瀛︿範(fàn)鍏卞悓榪涙!

涓銆?Nginx 鍩虹鐭ヨ瘑
1銆佺畝浠?br />    Nginx ("engine x") 鏄竴涓珮鎬ц兘鐨?HTTP 鍜?鍙嶅悜浠g悊 鏈嶅姟鍣紝涔熸槸涓涓?IMAP/POP3/SMTP 浠g悊鏈嶅姟鍣ㄣ?Nginx 鏄敱 Igor Sysoev 涓轟縿緗楁柉璁塊棶閲忕浜岀殑 Rambler.ru 绔欑偣寮鍙戠殑錛屽畠宸茬粡鍦ㄨ绔欑偣榪愯瓚呰繃涓ゅ勾鍗婁簡銆侷gor 灝嗘簮浠g爜浠ョ被BSD璁稿彲璇佺殑褰㈠紡鍙戝竷銆傚敖綆¤繕鏄祴璇曠増錛屼絾鏄紝Nginx 宸茬粡鍥犱負(fù)瀹冪殑紼沖畾鎬с佷赴瀵岀殑鍔熻兘闆嗐佺ず渚嬮厤緗枃浠跺拰浣庣郴緇熻祫婧愮殑娑堣楄岄椈鍚嶄簡銆?br /> 鏇村鐨勮瑙佸畼鏂箇iki: http://wiki.codemongers.com/

2銆?Nginx鐨勪紭鐐?br /> nginx鍋氫負(fù)HTTP鏈嶅姟鍣紝鏈変互涓嬪嚑欏瑰熀鏈壒鎬э細(xì)
1)        澶勭悊闈欐佹枃浠訛紝绱㈠紩鏂囦歡浠ュ強(qiáng)鑷姩绱㈠紩錛涙墦寮鏂囦歡鎻忚堪絎︾紦鍐詫紟
2)        鏃犵紦瀛樼殑鍙嶅悜浠g悊鍔犻燂紝綆鍗曠殑璐熻澆鍧囪 鍜屽閿欙紟
3)        FastCGI錛岀畝鍗曠殑璐熻澆鍧囪 鍜屽閿欙紟
4)        妯″潡鍖栫殑緇撴瀯銆傚寘鎷琯zipping, byte ranges, chunked responses, 浠ュ強(qiáng) SSI-filter絳塮ilter銆傚鏋滅敱FastCGI鎴栧叾瀹冧唬鐞嗘湇鍔″櫒澶勭悊鍗曢〉涓瓨鍦ㄧ殑澶氫釜SSI錛屽垯榪欓」澶勭悊鍙互騫惰榪愯錛岃屼笉闇瑕佺浉浜掔瓑寰呫?/span>
5)        鏀寔SSL 鍜?TLS SNI錛?br />
Nginx涓撲負(fù)鎬ц兘浼樺寲鑰屽紑鍙戯紝鎬ц兘鏄叾鏈閲嶈鐨勮冮噺, 瀹炵幇涓婇潪甯告敞閲嶆晥鐜?銆傚畠鏀寔鍐呮牳Poll妯″瀷錛岃兘緇忓彈楂樿礋杞界殑鑰冮獙, 鏈夋姤鍛婅〃鏄庤兘鏀寔楂樿揪 50,000 涓茍鍙戣繛鎺ユ暟銆?br /> Nginx鍏鋒湁寰堥珮鐨勭ǔ瀹氭с傚叾瀹僅TTP鏈嶅姟鍣紝褰撻亣鍒拌闂殑宄板鹼紝鎴栬呮湁浜烘伓鎰忓彂璧鋒參閫熻繛鎺ユ椂錛屼篃寰堝彲鑳戒細(xì)瀵艱嚧鏈嶅姟鍣ㄧ墿鐞嗗唴瀛樿楀敖棰戠箒浜ゆ崲錛屽け鍘誨搷搴旓紝鍙兘閲嶅惎鏈嶅姟鍣ㄣ備緥濡傚綋鍓峚pache涓鏃︿笂鍒?00涓互涓婅繘紼嬶紝web鍝? 搴旈熷害灝辨槑鏄鵑潪甯哥紦鎱簡銆傝孨ginx閲囧彇浜嗗垎闃舵璧勬簮鍒嗛厤鎶鏈紝浣垮緱瀹冪殑CPU涓庡唴瀛樺崰鐢ㄧ巼闈炲父浣庛俷ginx瀹樻柟琛ㄧず淇濇寔10,000涓病鏈夋椿鍔ㄧ殑榪? 鎺ワ紝瀹冨彧鍗?.5M鍐呭瓨錛屾墍浠ョ被浼糄OS榪欐牱鐨勬敾鍑誨nginx鏉ヨ鍩烘湰涓婃槸姣棤鐢ㄥ鐨勩傚氨紼沖畾鎬ц岃█, nginx姣攍ighthttpd鏇磋儨涓絳廣?br /> Nginx鏀寔鐑儴緗層傚畠鐨勫惎鍔ㄧ壒鍒鏄? 騫朵笖鍑犱箮鍙互鍋氬埌7*24涓嶉棿鏂繍琛岋紝鍗充嬌榪愯鏁頒釜鏈堜篃涓嶉渶瑕侀噸鏂板惎鍔ㄣ備綘榪樿兘澶熷湪涓嶉棿鏂湇鍔$殑鎯呭喌涓嬶紝瀵硅蔣浠剁増鏈繘琛岃繘琛屽崌綰с?br /> Nginx閲囩敤master-slave妯″瀷, 鑳藉鍏呭垎鍒╃敤SMP鐨勪紭鍔匡紝涓旇兘澶熷噺灝戝伐浣滆繘紼嬪湪紓佺洏I(yè)/O鐨勯樆濉炲歡榪熴傚綋閲囩敤select()/poll()璋冪敤鏃訛紝榪樺彲浠ラ檺鍒舵瘡涓繘紼嬬殑榪炴帴鏁般?br /> Nginx 浠g爜璐ㄩ噺闈炲父楂橈紝浠g爜寰堣鑼冿紝 鎵嬫硶鎴愮啛錛?妯″潡鎵╁睍涔熷緢瀹規(guī)槗銆傜壒鍒煎緱涓鎻愮殑鏄己澶х殑Upstream涓嶧ilter閾俱? Upstream涓鴻濡俽everse proxy, 涓庡叾浠栨湇鍔″櫒閫氫俊妯″潡鐨勭紪鍐欏瀹氫簡寰堝ソ鐨勫熀紜銆傝孎ilter閾炬渶閰風(fēng)殑閮ㄥ垎灝辨槸鍚勪釜filter涓嶅繀絳夊緟鍓嶄竴涓猣ilter鎵ц瀹屾瘯銆傚畠鍙互鎶婂墠涓涓? filter鐨勮緭鍑哄仛涓哄綋鍓峟ilter鐨勮緭鍏ワ紝榪欐湁鐐瑰儚Unix鐨勭綰褲傝繖鎰忓懗鐫錛屼竴涓ā鍧楀彲浠ュ紑濮嬪帇緙╀粠鍚庣鏈嶅姟鍣ㄥ彂閫佽繃鏉ョ殑璇鋒眰錛屼笖鍙互鍦ㄦā鍧楁帴鏀? 瀹屽悗绔湇鍔″櫒鐨勬暣涓姹備箣鍓嶆妸鍘嬬緝嫻佽漿鍚戝鎴風(fēng)銆?br /> Nginx閲囩敤浜嗕竴浜沷s鎻愪緵鐨勬渶鏂扮壒鎬у瀵箂endfile (Linux 2.2+)錛宎ccept-filter (FreeBSD 4.1+)錛孴CP_DEFER_ACCEPT (Linux 2.4+) 鐨勬敮鎸侊紝浠庤屽ぇ澶ф彁楂樹簡鎬ц兘

浜屻?Nginx 瀹夎鍙?qiáng)璋冭?/strong>
1銆丳cre 瀹夎

  1. ./configure
  2.   make && make install
  3.   cd ../
澶嶅埗浠g爜

2.        nginx 緙栬瘧瀹夎

  1. ./configure --user=www --group=www --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-openssl=/usr/local/openssl
  2. make && make install
澶嶅埗浠g爜

鏇磋緇嗙殑妯″潡瀹氬埗涓庡畨瑁呰鍙傜収瀹樻柟wiki.

3銆丯ginx 閰嶇疆鏂囦歡嫻嬭瘯錛?/p>

  1. # /usr/local/nginx/sbin/nginx -t  //Debug 閰嶇疆鏂囦歡鐨勫叧閿懡浠ら渶瑕侀噸鐐規(guī)拺鎻?
  2. 2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  3. 2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
澶嶅埗浠g爜

3銆丯ginx 鍚姩錛?/p>

  1. # /usr/local/nginx/sbin/nginx
澶嶅埗浠g爜

4銆丯ginx 閰嶇疆鏂囦歡淇敼閲嶆柊鍔犺澆錛?/p>

  1. # kill -HUP `cat /usr/local/nginx/logs/nginx.pid
澶嶅埗浠g爜

`
涓夈丯ginx Rewrite

1.  Nginx Rewrite 鍩烘湰鏍囪(flags)
last - 鍩烘湰涓婇兘鐢ㄨ繖涓狥lag銆?/em>
鈥葷浉褰撲簬Apache閲岀殑[L]鏍囪錛岃〃紺哄畬鎴恟ewrite錛屼笉鍐嶅尮閰嶅悗闈㈢殑瑙勫垯
break - 涓Rewirte錛屼笉鍐嶇戶緇尮閰?/em>
redirect - 榪斿洖涓存椂閲嶅畾鍚戠殑HTTP鐘舵?02
permanent - 榪斿洖姘鎬箙閲嶅畾鍚戠殑HTTP鐘舵?01
      鈥誨師鏈夌殑url鏀寔姝e垯  閲嶅啓鐨剈rl涓嶆敮鎸佹鍒?/strong>

2.  姝e垯琛ㄨ揪寮忓尮閰嶏紝鍏朵腑錛?br />     * ~         涓哄尯鍒嗗ぇ灝忓啓鍖歸厤
    * ~*       涓轟笉鍖哄垎澶у皬鍐欏尮閰?/em>
    * !~鍜?~*   鍒嗗埆涓哄尯鍒嗗ぇ灝忓啓涓嶅尮閰嶅強(qiáng)涓嶅尯鍒嗗ぇ灝忓啓涓嶅尮閰?/em>

3. 鏂囦歡鍙?qiáng)鐩綍鍖归厤锛屽叾涓Q?br />    * -f鍜?-f鐢ㄦ潵鍒ゆ柇鏄惁瀛樺湪鏂囦歡
    * -d鍜?-d鐢ㄦ潵鍒ゆ柇鏄惁瀛樺湪鐩綍
    * -e鍜?-e鐢ㄦ潵鍒ゆ柇鏄惁瀛樺湪鏂囦歡鎴栫洰褰?/em>
    * -x鍜?-x鐢ㄦ潵鍒ゆ柇鏂囦歡鏄惁鍙墽琛?/em>


3.  Nginx 鐨勪竴浜涘彲鐢ㄧ殑鍏ㄥ眬鍙橀噺錛屽彲鐢ㄥ仛鏉′歡鍒ゆ柇錛?/p>

  1. $args
  2. $content_length
  3. $content_type
  4. $document_root
  5. $document_uri
  6. $host
  7. $http_user_agent
  8. $http_cookie
  9. $limit_rate
  10. $request_body_file
  11. $request_method
  12. $remote_addr
  13. $remote_port
  14. $remote_user
  15. $request_filename
  16. $request_uri
  17. $query_string
  18. $scheme
  19. $server_protocol
  20. $server_addr
  21. $server_name
  22. $server_port
  23. $uri
澶嶅埗浠g爜

鍥涖?Nginx Redirect
灝嗘墍鏈塴inuxtone.org涓巒etseek.linuxtone.org鍩熷悕鍏ㄩ儴鑷煩杞埌http://www.linuxtone.org

  1. server
  2. {
  3. listen 80;
  4. server_name linuxtone.org netseek.linuxtone.org;
  5. index index.html index.php;
  6. root /data/www/wwwroot;
  7. if ($host !~ "^www.linxtone.org$") {
  8. rewrite ^(.*) http://www.linuxtone.org$1 redirect;
  9. }
  10. ........................
  11. }
澶嶅埗浠g爜

浜斻?Nginx 鐩綍鑷姩鍔犳枩綰?

  1. if (-d $request_filename){
  2.            rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  3.      }
澶嶅埗浠g爜

鍏?nbsp; Nginx Location

1錛庡熀鏈娉?[鍜屼笂闈ewrite姝e垯鍖歸厤璇硶鍩烘湰涓鑷碷
location [=|~|~*|^~] /uri/ { … }
    * ~  涓哄尯鍒嗗ぇ灝忓啓鍖歸厤
    * ~* 涓轟笉鍖哄垎澶у皬鍐欏尮閰?/em>
    * !~鍜?~*鍒嗗埆涓哄尯鍒嗗ぇ灝忓啓涓嶅尮閰嶅強(qiáng)涓嶅尯鍒嗗ぇ灝忓啓涓嶅尮閰?/em>

紺轟緥1:
location = / {
# matches the query / only.
# 鍙尮閰?/ 鏌ヨ銆?/em>
}
鍖歸厤浠諱綍鏌ヨ錛屽洜涓烘墍鏈夎姹傞兘宸?/ 寮澶淬備絾鏄鍒欒〃杈懼紡瑙勫垯鍜岄暱鐨勫潡瑙勫垯灝嗚浼樺厛鍜屾煡璇㈠尮閰?/strong>

紺轟緥2:
location ^~ /images/ {
# matches any query beginning with /images/ and halts searching,
# so regular expressions will not be checked.
# 鍖歸厤浠諱綍宸?/images/ 寮澶寸殑浠諱綍鏌ヨ騫朵笖鍋滄鎼滅儲銆備換浣曟鍒欒〃杈懼紡灝嗕笉浼?xì)琚珛箣璇曘?br />
紺轟緥3:
location ~* .(gif|jpg|jpeg)$ {
# matches any request ending in gif, jpg, or jpeg. However, all
# requests to the /images/ directory will be handled by
}
# 鍖歸厤浠諱綍宸?gif銆乯pg 鎴?jpeg 緇撳熬鐨勮姹傘?/strong>


涓冦?Nginx expires

1錛庢牴鎹枃浠剁被鍨媏xpires

  1. # Add expires header for static content
  2. location ~* .(js|css|jpg|jpeg|gif|png|swf)$ {
  3.     if (-f $request_filename) {
  4.        root /data/www/wwwroot/bbs;
  5.        expires      1d;
  6.        break;
  7.     }
  8. }
澶嶅埗浠g爜

2銆佹牴鎹垽鏂煇涓洰褰?/p>

  1. # serve static files
  2. location ~ ^/(images|javascript|js|css|flash|media|static)/  {
  3. root    /data/www/wwwroot/down;
  4.         expires 30d;
  5.   }
澶嶅埗浠g爜

鍏?nbsp; Nginx 闃茬洍閾?/strong>

1.        閽堝涓嶅悓鐨勬枃浠剁被鍨?/p>

  1. #Preventing hot linking of images and other file types
  2. location ~* ^.+.(gif|jpg|png|swf|flv|rar|zip)$ {
  3.         valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost baidu.com;
  4. if ($invalid_referer) {
  5.       rewrite   ^/   ;
  6.      # return   403;
  7.       }
  8. }
澶嶅埗浠g爜

2.        閽堝涓嶅悓鐨勭洰褰?/p>

  1. location /img/ {
  2.     root /data/www/wwwroot/bbs/img/;
  3.     valid_referers none blocked server_names *.linuxtone.org http://localhost baidu.com;
  4.     if ($invalid_referer) {
  5.                    rewrite  ^/  ;
  6.                    #return   403;
  7.     }
  8. }
澶嶅埗浠g爜

3.        鍚屽疄鐜伴槻鐩楅摼鍜宔xpires鐨勬柟娉?/p>

  1. #Preventing hot linking of images and other file types
  2. location ~* ^.+.(gif|jpg|png|swf|flv|rar|zip)$ {
  3.         valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost ;
  4. if ($invalid_referer) {
  5.       rewrite   ^/   ;
  6.                      }
  7.      access_log off;
  8.      root /data/www/wwwroot/bbs;
  9. expires 1d;
  10.      break;
  11. }
澶嶅埗浠g爜

涔?jié)銆?Nginx 璁塊棶鎺у埗

1.        Nginx 韜喚璇侀獙璇?/p>

  1. #cd /usr/local/nginx/conf
  2. #mkdir htpasswd
  3. /usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/tongji linuxtone
  4. #娣誨姞鐢ㄦ埛鍚嶄負(fù)linuxtone
  5. New password:   (姝ゅ杈撳叆浣犵殑瀵嗙爜)
  6. Re-type new password:   (鍐嶆杈撳叆浣犵殑瀵嗙爜)
  7. Adding password for user
  8. http://count.linuxtone.org/tongji/data/index.html(鐩綍瀛樺湪/data/www/wwwroot/tongji/data/鐩綍涓?
  9. 灝嗕笅孌甸厤緗斁鍒拌櫄鎷熶富鏈虹洰褰曪紝褰撹闂甴ttp://count.linuxtone/tongji/鍗蟲彁紺鴻瀵嗛獙璇?
  10. location ~ ^/(tongji)/  {
  11.                 root    /data/www/wwwroot/count;
  12.                         auth_basic              "LT-COUNT-TongJi";
  13.                         auth_basic_user_file  /usr/local/nginx/conf/htpasswd/tongji;
  14.                 }
澶嶅埗浠g爜

2.        Nginx 紱佹璁塊棶鏌愮被鍨嬬殑鏂囦歡.
濡傦紝Nginx涓嬬姝㈣闂?.txt鏂囦歡錛岄厤緗柟娉曞涓?

  1. location ~* .(txt|doc)$ {
  2.    if (-f $request_filename) {
  3.    root /data/www/wwwroot/linuxtone/test;
  4.    #rewrite …..鍙互閲嶅畾鍚戝埌鏌愪釜URL
  5.    break;
  6.    }
  7. }
澶嶅埗浠g爜

鏂規(guī)硶2:

  1. location ~* .(txt|doc)${
  2.         root /data/www/wwwroot/linuxtone/test;
  3.         deny all;
  4. }
澶嶅埗浠g爜

瀹炰緥:
紱佹璁塊棶鏌愪釜鐩綍

  1. location ~ ^/(WEB-INF)/ {
  2.             deny all;
  3. }  
澶嶅埗浠g爜

3.        浣跨敤ngx_http_access_module闄愬埗ip璁塊棶

  1. location / {
  2.     deny    192.168.1.1;
  3.     allow   192.168.1.0/24;
  4.     allow   10.1.1.0/16;
  5.     deny    all;
  6. }
澶嶅埗浠g爜

璇︾粏鍙傝wiki: http://wiki.codemongers.com/NginxHttpAccessModule#allow

4.        Nginx 涓嬭澆闄愬埗騫跺彂鍜岄熺巼

  1. limit_zone   linuxtone  $binary_remote_addr  10m;
  2. server
  3.        {
  4.                listen       80;
  5.                server_name  down.linuxotne.org;
  6.                index index.html index.htm index.php;
  7.                root   /data/www/wwwroot/down;
  8.                #Zone limit
  9.                location / {
  10.                    limit_conn   linuxtone  1;
  11.                    limit_rate  20k;
  12.                }
  13. ..........
  14.        }
澶嶅埗浠g爜

鍙厑璁稿鎴跨涓涓嚎紼?姣忎釜綰跨▼20k.
銆愭敞銆?span style="color: #008000;">limit_zone   linuxtone  $binary_remote_addr  10m; 榪欎釜鍙互瀹氫箟鍦ㄤ富鐨?/span>


5.        Nginx 瀹炵幇Apache涓鏍風(fēng)洰褰曞垪琛?/p>

  1. location  /  {
  2.     autoindex  on;
  3. }
澶嶅埗浠g爜

6.        涓婃枃浠跺ぇ灝忛檺鍒?br /> 涓婚厤緗枃浠墮噷鍔犲叆濡備笅錛屽叿浣撳ぇ灝忔牴鎹綘鑷繁鐨勪笟鍔″仛璋冩暣銆?br /> client_max_body_size 10m;                                                         

鍗併?nbsp;       Nginx 鏃ュ織澶勭悊

1.Nginx 鏃ュ織鍒囧壊
#contab -e
59 23 * * * /usr/local/sbin/logcron.sh /dev/null 2>&1
[root@count ~]# cat /usr/local/sbin/logcron.sh

  1. #!/bin/bash
  2. log_dir="/data/logs"
  3. time=`date +%Y%m%d`  
  4. /bin/mv  ${log_dir}/access_linuxtone.org.log ${log_dir}/access_count.linuxtone.org.$time.log
  5. kill -USR1 `cat  /var/run/nginx.pid`
澶嶅埗浠g爜

鏇村鐨勬棩蹇楀垎鏋愪笌澶勭悊灝卞叧娉?鍚屾椂嬈㈣繋浣犲弬鍔犺璁?:http://bbs.linuxtone.org/forum-8-1.html

2.鍒╃敤AWSTATS鍒嗘瀽NGINX鏃ュ織
  璁劇疆濂絅ginx鏃ュ織鏍煎紡,浠嶅悗鍒╃敤awstats榪涜鍒嗘瀽.
璇峰弬鑰? http://bbs.linuxtone.org/thread-56-1-1.html

3.        Nginx 濡備綍涓嶈褰曢儴鍒嗘棩蹇?br /> 鏃ュ織澶錛屾瘡澶╁ソ鍑犱釜G錛屽皯璁板綍涓浜涳紝涓嬮潰鐨勯厤緗啓鍒皊erver{}孌典腑灝卞彲浠ヤ簡
location ~ .*.(js|jpg|JPG|jpeg|JPEG|css|bmp|gif|GIF)$
{
     access_log off;
}

鍗佷竴銆丯ginx Cache鏈嶅姟閰嶇疆

濡傛灉闇瑕佸皢鏂囦歡緙撳瓨鍒版湰鍦幫紝鍒欓渶瑕佸鍔犲涓嬪嚑涓瓙鍙傛暟錛?/p>

  1. proxy_store on;
  2. proxy_store_access user:rw group:rw all:rw;
  3. proxy_temp_path 緙撳瓨鐩綍;
澶嶅埗浠g爜

鍏朵腑錛?br /> proxy_store on鐢ㄦ潵鍚敤緙撳瓨鍒版湰鍦扮殑鍔熻兘錛?br /> proxy_temp_path鐢ㄦ潵鎸囧畾緙撳瓨鍦ㄥ摢涓洰褰曚笅錛屽錛歱roxy_temp_path html;

鍦ㄧ粡榪囦笂涓姝ラ厤緗箣鍚庯紝铏界劧鏂囦歡琚紦瀛樺埌浜嗘湰鍦扮鐩樹笂錛屼絾姣忔璇鋒眰浠嶄細(xì)鍚戣繙绔媺鍙栨枃浠訛紝涓轟簡閬垮厤鍘昏繙绔媺鍙栨枃浠訛紝蹇呴』淇敼

  1. proxy_pass錛?/li>
  2. if ( !-e $request_filename) {
  3.     proxy_pass  http://mysvr;
  4. }
澶嶅埗浠g爜

鍗蟲敼鎴愭湁鏉′歡鍦板幓鎵цproxy_pass錛岃繖涓潯浠跺氨鏄綋璇鋒眰鐨勬枃浠跺湪鏈湴鐨刾roxy_temp_path鎸囧畾鐨勭洰褰曚笅涓嶅瓨鍦ㄦ椂錛屽啀鍚戝悗绔媺鍙栥?br />
   
鏇村鏇撮珮綰х殑搴旂敤鍙互鐮旂┒ncache,璇︾粏璇峰弬鐓?a target="_blank">http://bbs.linuxtone.org 閲宯cache鐩稿叧鐨勮創(chuàng)瀛?

鍗佷簩銆丯ginx 璐熻澆鍧囪 
1. Nginx 璐熻澆鍧囪 鍩虹鐭ヨ瘑
nginx鐨剈pstream鐩墠鏀寔4縐嶆柟寮忕殑鍒嗛厤
1)銆佽疆璇紙榛樿錛?/span>
姣忎釜璇鋒眰鎸夋椂闂撮『搴忛愪竴鍒嗛厤鍒頒笉鍚岀殑鍚庣鏈嶅姟鍣紝濡傛灉鍚庣鏈嶅姟鍣╠own鎺夛紝鑳借嚜鍔ㄥ墧闄ゃ?/span>
2)銆亀eight
鎸囧畾杞鍑犵巼錛寃eight鍜岃闂瘮鐜囨垚姝f瘮錛岀敤浜庡悗绔湇鍔″櫒鎬ц兘涓嶅潎鐨勬儏鍐點(diǎn)?/span>
2)銆乮p_hash
姣忎釜璇鋒眰鎸夎闂甶p鐨刪ash緇撴灉鍒嗛厤錛岃繖鏍鋒瘡涓瀹㈠浐瀹氳闂竴涓悗绔湇鍔″櫒錛屽彲浠ヨВ鍐硈ession鐨勯棶棰樸?/span>
3)銆乫air錛堢涓夋柟錛?/span>
鎸夊悗绔湇鍔″櫒鐨勫搷搴旀椂闂存潵鍒嗛厤璇鋒眰錛屽搷搴旀椂闂寸煭鐨勪紭鍏堝垎閰嶃?
4)銆乽rl_hash錛堢涓夋柟錛?/span>

2.        Nginx 璐熻澆鍧囪 瀹炰緥1

  1. upstream bbs.linuxtone.org {#瀹氫箟璐熻澆鍧囪 璁懼鐨処p鍙?qiáng)璁惧鐘舵?/li>
  2.     server 127.0.0.1:9090 down;
  3.     server 127.0.0.1:8080 weight=2;
  4.     server 127.0.0.1:6060;
  5.     server 127.0.0.1:7070 backup;
  6. }
澶嶅埗浠g爜

鍦ㄩ渶瑕佷嬌鐢ㄨ礋杞藉潎琛$殑server涓鍔?br /> proxy_pass http://bbs.linuxtone.org/;

姣忎釜璁懼鐨勭姸鎬佽緗負(fù):
a)        down 琛ㄧず鍗曞墠鐨剆erver鏆傛椂涓嶅弬涓庤礋杞?/span>
b)        weight 榛樿涓?.weight瓚婂ぇ錛岃礋杞界殑鏉冮噸灝辮秺澶с?/span>
c)        max_fails 錛氬厑璁歌姹傚け璐ョ殑嬈℃暟榛樿涓?.褰撹秴榪囨渶澶ф鏁版椂錛岃繑鍥瀙roxy_next_upstream 妯″潡瀹氫箟鐨勯敊璇?/span>
d)        fail_timeout:max_fails嬈″け璐ュ悗錛屾殏鍋滅殑鏃墮棿銆?/span>
e)        backup錛?鍏跺畠鎵鏈夌殑闈瀊ackup鏈哄櫒down鎴栬呭繖鐨勬椂鍊欙紝璇鋒眰backup鏈哄櫒銆傛墍浠ヨ繖鍙版満鍣ㄥ帇鍔涗細(xì)鏈杞匯?/span>

nginx鏀寔鍚屾椂璁劇疆澶氱粍鐨勮礋杞藉潎琛★紝鐢ㄦ潵緇欎笉鐢ㄧ殑server鏉ヤ嬌鐢ㄣ?br />
client_body_in_file_only 璁劇疆涓篛n 鍙互璁瞔lient post榪囨潵鐨勬暟鎹褰曞埌鏂囦歡涓敤鏉ュ仛debug
client_body_temp_path 璁劇疆璁板綍鏂囦歡鐨勭洰褰?鍙互璁劇疆鏈澶?灞傜洰褰?br /> location 瀵筓RL榪涜鍖歸厤.鍙互榪涜閲嶅畾鍚戞垨鑰呰繘琛屾柊鐨勪唬鐞?璐熻澆鍧囪 


3.        Nginx 璐熻澆鍧囪 瀹炰緥 2
鎸夎闂畊rl鐨刪ash緇撴灉鏉ュ垎閰嶈姹傦紝浣挎瘡涓猽rl瀹氬悜鍒板悓涓涓悗绔湇鍔″櫒錛屽悗绔湇鍔″櫒涓虹紦瀛樻椂姣旇緝鏈夋晥,涔熷彲浠ョ敤浣滄彁楂楽quid緙撳瓨鍛戒腑鐜?

綆鍗曠殑璐熻澆鍧囩瓑瀹炰緥:
#vi nginx.conf  //nginx涓婚厤緗枃浠舵牳蹇冮厤緗?/p>

  1. ……….
  2. #loadblance my.linuxtone.org
  3.        upstream  my.linuxtone.org  {
  4.        ip_hash;
  5.        server   127.0.0.1:8080;
  6.        server   192.168.169.136:8080;
  7.        server   219.101.75.138:8080;
  8.        server   192.168.169.117;
  9.        server   192.168.169.118;
  10.        server   192.168.169.119;
  11.      }
  12. …………..
  13. include          vhosts/linuxtone_lb.conf;
  14. ………
  15. # vi proxy.conf
  16. proxy_redirect off;
  17. proxy_set_header Host $host;
  18. proxy_set_header X-Real-IP $remote_addr;
  19. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  20. client_max_body_size 50m;
  21. client_body_buffer_size 256k;
  22. proxy_connect_timeout 30;
  23. proxy_send_timeout 30;
  24. proxy_read_timeout 60;
  25. proxy_buffer_size 4k;
  26. proxy_buffers 4 32k;
  27. proxy_busy_buffers_size 64k;
  28. proxy_temp_file_write_size 64k;
  29. proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
  30. proxy_max_temp_file_size 128m;
  31. proxy_store on;
  32. proxy_store_access   user:rw  group:rw  all:r;
  33. #nginx cache               
  34. #client_body_temp_path  /data/nginx_cache/client_body 1 2;
  35. proxy_temp_path /data/nginx_cache/proxy_temp 1 2;
澶嶅埗浠g爜

#vi  linuxtone_lb.conf

  1. server
  2.     {
  3.         listen  80;
  4.         server_name my.linuxtone.org;
  5.         index index.php;
  6.         root /data/www/wwwroot/mylinuxtone;
  7.         if (-f $request_filename) {
  8.             break;
  9.            }
  10.         if (-f $request_filename/index.php) {
  11.           rewrite (.*) $1/index.php break;
  12.         }
  13.         error_page 403 http://my.linuxtone.org/member.php?m=user&a=login;
  14.         location / {
  15.            if ( !-e $request_filename) {
  16.                proxy_pass http://my.linuxtone.org;
  17.                break;
  18.            }
  19.            include /usr/local/nginx/conf/proxy.conf;
  20.         }
  21. }
澶嶅埗浠g爜



鍗佷笁銆丯ginx綆鍗曚紭鍖?/strong>

1.        鍑忓皬nginx緙栬瘧鍚庣殑鏂囦歡澶у皬 (Reduce file size of nginx)
榛樿鐨刵ginx緙栬瘧閫夐」閲屽眳鐒舵槸鐢╠ebug妯″紡(-g)鐨勶紙debug妯″紡浼?xì)鎻掑叆寰堝璺燀t拰ASSERT涔嬬被錛夛紝緙栬瘧浠ュ悗涓涓猲ginx鏈夊ソ鍑犲厗銆傚幓鎺塶ginx鐨刣ebug妯″紡緙栬瘧錛岀紪璇戜互鍚庡彧鏈夊嚑鐧綤
鍦?auto/cc/gcc錛屾渶鍚庡嚑琛屾湁錛?br /> # debug

  1. CFLAGS=”$CFLAGS -g”
澶嶅埗浠g爜

娉ㄩ噴鎺夋垨鍒犳帀榪欏嚑琛岋紝閲嶆柊緙栬瘧鍗沖彲銆?br />
2.        淇敼Nginx鐨刪eader浼鏈嶅姟鍣?br /> 1)        淇敼nginx.h

  1. #vi nginx-0.7.30/src/core/nginx.h
  2. #define NGINX_VERSION      "1.8"
  3. #define NGINX_VER          "LTWS/" NGINX_VERSION
  4. #define NGINX_VAR          "NGINX"
  5. #define NGX_OLDPID_EXT     ".oldbin"
澶嶅埗浠g爜

2) 淇敼nginx_http_header_filter_module
#vi nginx-0.7.30/src/http/ngx_http_header_filter_module.c
灝嗗涓?/p>

  1. static char ngx_http_server_string[] = "Server: nginx" CRLF;
澶嶅埗浠g爜

淇敼涓?/p>

  1. static char ngx_http_server_string[] = "Server: LTWS" CRLF;
澶嶅埗浠g爜

a)        淇敼nginx_http_header_filter_module
#vi nginx-0.7.30/src/http/ngx_http_special_response.c
灝嗗涓嬶細(xì)

  1. static u_char ngx_http_error_full_tail[] =
  2. "<hr><center>" NGINX_VER "</center>" CRLF
  3. "</body>" CRLF
  4. "</html>" CRLF
  5. ;
澶嶅埗浠g爜
  1. static u_char ngx_http_error_tail[] =
  2. "<hr><center>nginx</center>" CRLF
  3. "</body>" CRLF
  4. "</html>" CRLF
  5. ;
澶嶅埗浠g爜

淇敼涓?

  1. static u_char ngx_http_error_full_tail[] =
  2. "<center> "NGINX_VER" </center>" CRLF
  3. "<hr><center>http://www.linuxtone.org</center>" CRLF
  4. "</body>" CRLF
  5. "</html>" CRLF
  6. ;
  7. static u_char ngx_http_error_tail[] =
  8. "<hr><center>LTWS</center>" CRLF
  9. "</body>" CRLF
  10. "</html>" CRLF
  11. ;
澶嶅埗浠g爜

淇敼鍚庨噸鏂扮紪璇戜竴涓嬬幆澧?
404閿欒鐨勬椂鍊欐樉紺烘晥鏋滃浘錛堝鏋滄病鏈夋寚瀹氶敊璇〉鐨勮瘽錛夛細(xì)
404.png

鍒╃敤curl鍛戒護(hù)鏌ョ湅鏈嶅姟鍣╤eader
curl.png



 

3.涓虹壒瀹氱殑CPU鎸囧畾CPU綾誨瀷緙栬瘧浼樺寲.
榛樿nginx浣跨敤鐨凣CC緙栬瘧鍙傛暟鏄?O
闇瑕佹洿鍔犱紭鍖栧彲浠ヤ嬌鐢ㄤ互涓嬩袱涓弬鏁?br /> --with-cc-opt='-O3'
--with-cpu-opt=opteron
浣垮緱緙栬瘧閽堝鐗瑰畾CPU浠ュ強(qiáng)澧炲姞GCC鐨勪紭鍖?
姝ゆ柟娉曚粎瀵規(guī)ц兘鏈夋墍鏀瑰杽騫朵笉浼?xì)鏈夊緢澶х殑鎬ц兘鎻愬崌錛屼緵鏈嬪弸浠弬鑰?
CPUD綾誨瀷紜畾: # cat /proc/cpuinfo | grep "model name"
緙栬瘧浼樺寲鍙傛暟鍙傝冿細(xì)http://en.gentoo-wiki.com/wiki/Safe_Cflags


4.Tcmalloc浼樺寲Nginx 鎬ц兘

  1. # wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
  2. # tar zxvf libunwind-0.99-alpha.tar.gz
  3. # cd libunwind-0.99-alpha/
  4. # CFLAGS=-fPIC ./configure
  5. # make CFLAGS=-fPIC
  6. # make CFLAGS=-fPIC install
  7. # wget http://google-perftools.googlecode.com/files/google-perftools-0.98.tar.gz
  8. # tar zxvf google-perftools-0.98.tar.gz
  9. # cd google-perftools-0.98/
  10. # ./configure
  11. # make && make install
  12. # echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  13. # ldconfig
  14. # lsof -n | grep tcmalloc
澶嶅埗浠g爜

緙栬瘧nginx 鍔犺澆google_perftools_module:
./configure --with-google_perftools_module
鍦ㄤ富閰嶇疆鏂囦歡鍔犲叆nginx.conf 娣誨姞:
google_perftools_profiles /path/to/profile;

5.鍐呮牳鍙傛暟浼樺寲
# vi /etc/sysctl.conf   #鍦ㄦ湯灝懼鍔犱互涓嬪唴瀹癸細(xì)

  1. net.ipv4.tcp_fin_timeout = 30
  2. net.ipv4.tcp_keepalive_time = 300
  3. net.ipv4.tcp_syncookies = 1
  4. net.ipv4.tcp_tw_reuse = 1
  5. net.ipv4.tcp_tw_recycle = 1
  6. net.ipv4.ip_local_port_range = 5000 65000
澶嶅埗浠g爜

#浣塊厤緗珛鍗崇敓鏁?br /> /sbin/sysctl -p

鍗佸洓銆佸浣曟瀯寤洪珮鎬х殑LEMP
璇峰弬瑙? http://www.linuxtone.org/lemp/lemp.pdf
1銆佹彁渚涘畬鏁寸殑閰嶇疆鑴氭湰涓嬭澆錛?a target="_blank">http://www.linuxtone.org/lemp/scripts.tar.gz
2銆佹彁渚汵GINX甯歌閰嶇疆鑼冧緥鍚?铏氭嫙涓繪満錛岄槻鐩楅摼錛孯ewrite,璁塊棶鎺у埗錛岃礋杞藉潎琛?br /> Discuz鐩稿叧紼嬪簭闈欐佸寲鍙?qiáng)绛壗{?,浣犲彧瑕佺◢紼嶄慨鏀瑰嵆鍙嚎涓婂簲鐢ㄣ?3銆佸皢鍘熺増鐨剎cache鏇挎崲鎴怑A錛屽茍鎻愪緵鐩稿叧綆鍗曡皟浼樿剼鏈強(qiáng)閰嶇疆鏂囦歡銆?br /> 鏇村鐨勫強(qiáng)鏇存柊璧勬枡璇峰叧娉? http://www.linuxtone.org

鍗佷簲銆丯ginx鐩戞帶
1銆?nbsp;       RRDTOOL+Perl鑴氭湰鐢誨浘鐩戞帶
鍏堝畨瑁呭ソrrdtool 錛屽叧浜巖rdtool鏈枃涓嶄綔浠嬬粛錛屽叿浣撳畨瑁呰鍙傜収linuxtone鐩戞帶鐗堝潡.
#cd /usr/local/sbnin
#wget http://blog.kovyrin.net/files/mrtg/rrd_nginx.pl.txt
#mv rrd_nginx.pl.txt rrd_nginx.pl
#chmod a+x rrd_nginx.pl

#vi rrd_nginx.pl   //閰嶇疆鑴氭湰鏂囦歡璁劇疆濂借礬寰?br /> #!/usr/bin/perl
use RRDs;
use LWP::UserAgent;

# define location of rrdtool databases
my $rrd = '/data/www/wwwroot/nginx/rrd';
# define location of images
my $img = '/data/www/wwwroot/nginx/html';
# define your nginx stats URL
my $URL = "http://219.232.244.13/nginx_status";
…………
銆愭敞銆戞牴鎹嚜宸卞叿浣撶殑鐘跺喌淇敼鐩稿簲鐨勮礬寰?
#crontab –e //鍔犲叆濡備笅
* * * * * /usr/local/sbin/rrd_nginx.pl
閲嶅惎crond鍚庯紝閫氳繃閰嶇疆nginx铏氭嫙涓繪満鎸囧埌/data/www/wwwroot/nginx/html鐩綍錛岄氳繃crond鑷姩鎵цperl鑴氭湰浼?xì)鐢熸垚寰堝鍥剧?
http://xxx/connections-day.png鍗沖彲鐪嬪埌鏈嶅姟鍣ㄧ姸鎬佸浘銆?br />
2銆?nbsp;       瀹樻柟Nginx-rrd 鐩戞帶鏈嶅姟錛堝铏氭嫙涓繪満錛夛紙鎺ㄨ崘錛?br /> 緗戝潃錛?a target="_blank">http://www.nginx.eu/nginx-rrd.html
姝よВ鍐蟲柟妗堝叾瀹炴槸鍩轟簬涓婅堪鐩戞帶鏂規(guī)鐨勪竴涓敼榪涘拰澧炲己錛屽悓鏍峰厛瀹夎濂絩rdtool榪欎釜鐢誨浘宸ュ叿鍜岀浉搴旂殑perl妯″潡鍐嶅仛濡備笅鎿嶄綔錛?br /> # yum install perl-HTML*
鍏堝緩绔嬪ソ鐢熸垚鐨勫簱瀛樺拰鍥劇墖瀛樻斁褰?/p>

  1. #mkdir -p /data/www/wwwroot/nginx/{rrd,html}
  2. #cd /usr/local/sbin
  3. #wget http://www.nginx.eu/nginx-rrd/nginx-rrd-0.1.4.tgz
  4. #tar zxvf nginx-rrd-0.1.4.tgz
  5. #cd nginx-rrd-0.1.4
  6. #cd etc/
  7. #cp nginx-rrd.conf /etc
  8. #cd etc/cron.d
  9. #cp nginx-rrd.cron /etc/cron.d
  10. #cd /usr/local/src/nginx-rrd-0.1.4/html
  11. # cp index.php /data/www/wwwroot/nginx/html/
  12. #cd /usr/local/src/nginx-rrd-0.1.4/usr/sbin
  13. #cp * /usr/sbin/
澶嶅埗浠g爜

#vi /etc/nginx-rrd.conf

  1. #####################################################
  2. #
  3. # dir where rrd databases are stored
  4. RRD_DIR="/data/www/wwwroot/nginx/rrd";
  5. # dir where png images are presented
  6. WWW_DIR="/data/www/wwwroot/nginx/html";
  7. # process nice level
  8. NICE_LEVEL="-19";
  9. # bin dir
  10. BIN_DIR="/usr/sbin";
  11. # servers to test
  12. # server_utl;server_name
  13. SERVERS_URL="http://219.32.205.13/nginx_status;219.32.205.13  http://www.linuxtone.org/nginx_status;www.linuxtone.org""
澶嶅埗浠g爜

//鏍規(guī)嵁浣犵殑鍏蜂綋鎯呭喌鍋氳皟鏁?
SEVERS_URL 鏍煎紡 http://domain1/nginx_status;domain1 http://domain2/nginx_status;domain2
榪欑鏍煎紡鐩戞帶澶氳櫄鎷熶富鏈鴻繛鎺ョ姸鎬侊細(xì)
閲嶇偣鍚痗rond鏈嶅姟錛屼粛鍚庨氳繃http://219.32.205.13/nginx/html/ 鍗沖彲璁塊棶銆傞厤緗繃紼嬪緢綆鍗曪紒

3銆?nbsp;       CACTI妯℃澘鐩戞帶Nginx
鍒╃敤Nginx_status鐘舵佹潵鐢誨浘瀹炵幇CACTI鐩戞帶
nginx緙栬瘧鏃跺厑璁竓ttp_stub_status_module

# vi /usr/local/nginx/conf/nginx.conf

  1. location /nginx_status {
  2. stub_status on;
  3. access_log off;
  4. allow 192.168.1.37;
  5. deny all;
  6. }
澶嶅埗浠g爜
  1. # kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
  2. # wget http://forums.cacti.net/download.php?id=12676
  3. # tar xvfz cacti-nginx.tar.gz
  4. # cp cacti-nginx/get_nginx_socket_status.pl /data/cacti/scripts/
  5. # cp cacti-nginx/get_nginx_clients_status.pl /data/cacti/scripts/
  6. # chmod 755 /data/cacti/scripts/get_nginx*
澶嶅埗浠g爜

媯嫻嬫彃浠?/p>

  1. # /data/cacti/scripts/get_nginx_clients_status.pl http://192.168.1.37/nginx_status
澶嶅埗浠g爜

鍦╟acti綆$悊闈㈡澘瀵煎叆
cacti_graph_template_nginx_clients_stat.xml
cacti_graph_template_nginx_sockets_stat.xml

鍗佸叚銆佸父瑙侀棶棰樹笌閿欒澶勭悊
1銆?00 bad request閿欒鐨勫師鍥犲拰瑙e喅鍔炴硶
閰嶇疆nginx.conf鐩稿叧璁劇疆濡備笅.
client_header_buffer_size 16k;
large_client_header_buffers 4 64k;
鏍規(guī)嵁鍏蜂綋鎯呭喌璋冩暣錛屼竴鑸傚綋璋冩暣鍊煎氨鍙互銆?br />
2銆丯ginx 502 Bad Gateway閿欒
proxy_next_upstream error timeout invalid_header http_500 http_503;
鎴栬呭皾璇曡緗?
large_client_header_buffers 4 32k;


3銆丯ginx鍑虹幇鐨?13 Request Entity Too Large閿欒
榪欎釜閿欒涓鑸湪涓婁紶鏂囦歡鐨勬椂鍊欎細(xì)鍑虹幇錛?br /> 緙栬緫Nginx涓婚厤緗枃浠禢ginx.conf錛屾壘鍒癶ttp{}孌碉紝娣誨姞
client_max_body_size 10m; //璁劇疆澶氬ぇ鏍規(guī)嵁鑷繁鐨勯渶姹備綔璋冩暣.
濡傛灉榪愯php鐨勮瘽榪欎釜澶у皬client_max_body_size瑕佸拰php.ini涓殑濡備笅鍊肩殑鏈澶у間竴鑷存垨鑰呯◢澶э紝榪欐牱灝變笉浼?xì)鍥犱负鎻愪氦鏁版嵁澶畯涓嶄竴鑷村嚭鐜扮殑閿欒銆?br /> post_max_size = 10M
upload_max_filesize = 2M

4銆佽В鍐?04 Gateway Time-out(nginx)
閬囧埌榪欎釜闂鏄湪鍗囩駭discuz璁哄潧鐨勬椂鍊欓亣鍒扮殑
涓鑸湅鏉? 榪欑鎯呭喌鍙兘鏄敱浜巒ginx榛樿鐨刦astcgi榪涚▼鍝嶅簲鐨勭紦鍐插尯澶皬閫犳垚鐨? 榪欏皢瀵艱嚧fastcgi榪涚▼琚寕璧? 濡傛灉浣犵殑fastcgi鏈嶅姟瀵硅繖涓寕璧峰鐞嗙殑涓嶅ソ, 閭d箞鏈鍚庡氨鏋佹湁鍙兘瀵艱嚧504 Gateway Time-out
鐜板湪鐨勭綉绔? 灝ゅ叾鏌愪簺璁哄潧鏈夊ぇ閲忕殑鍥炲鍜屽緢澶氬唴瀹圭殑, 涓涓〉闈㈢敋鑷蟲湁鍑犵櫨K銆?br /> 榛樿鐨刦astcgi榪涚▼鍝嶅簲鐨勭紦鍐插尯鏄?K, 鎴戜滑鍙互璁劇疆澶х偣
鍦╪ginx.conf閲? 鍔犲叆錛?fastcgi_buffers 8 128k
榪欒〃紺鴻緗甪astcgi緙撳啿鍖轟負(fù)8×128k
褰撶劧濡傛灉鎮(zhèn)ㄥ湪榪涜鏌愪竴欏瑰嵆鏃剁殑鎿嶄綔, 鍙兘闇瑕乶ginx鐨勮秴鏃跺弬鏁拌皟澶х偣錛屼緥濡傝緗垚60縐掞細(xì)send_timeout 60;
鍙槸璋冩暣浜嗚繖涓や釜鍙傛暟, 緇撴灉灝辨槸娌℃湁鍐嶆樉紺洪偅涓秴鏃? 鍙互璇存晥鏋滀笉閿? 浣嗘槸涔熷彲鑳芥槸鐢變簬鍏朵粬鐨勫師鍥? 鐩墠鍏充簬nginx鐨勮祫鏂欎笉鏄緢澶? 寰堝浜嬫儏閮介渶瑕侀暱鏈熺殑緇忛獙绱鎵嶆湁緇撴灉, 鏈熷緟鎮(zhèn)ㄧ殑鍙戠幇鍝?

5銆佸浣曚嬌鐢∟ginx Proxy
鏈嬪弸涓鍙版湇鍔″櫒榪愯tomcat 涓?080绔彛,IP:192.168.1.2:8080,鍙︿竴鍙版満鍣↖P:192.168.1.8. 鏈嬪弸鎯抽氳繃璁塊棶http://192.168.1.8鍗沖彲璁塊棶tomcat鏈嶅姟.閰嶇疆濡備笅:
鍦?92.168.1.8鐨刵ginx.conf涓婇厤緗涓?

  1. server {
  2. listen 80;
  3. server_name java.linuxtone.org
  4. location / {
  5. proxy_pass http://192.168.1.2:8080;
  6. include /usr/local/nginx/conf/proxy.conf;
  7. }
  8. }
澶嶅埗浠g爜

6銆佸浣曞叧闂璑ginx鐨凩OG
access_log /dev/null; error_log /dev/null;

鍗佷竷銆佺浉鍏寵祫婧愪笅杞?/strong>

1.nginx閰嶇疆紺轟緥鍙?qiáng)鑴氭湰涓嬭?
# wget http://www.linuxtone.org/lemp/scripts.tar.gz #姝よ剼鏈寖渚嬪畾鏈熸洿鏂?


鐩稿叧璇濋 錛?a >鏌ョ湅鏇村錛?a >鐭ヨ瘑搴撴悳绱?/a>錛?/strong>

鍏朵腑浠ヤ笅榪欓」鎸哄煎緱鐣欐剰鐨勩?br /> Tcmalloc 涓嶅崟鍙敤浜?Mysql 鐨勪紭鍖栵紝榪樿兘搴旂敤浜?Nginx
铏借 Nginx 鏈韓鐨勬ц兘璺熺郴緇熷崰鐢ㄥ凡緇忓仛鍒板緢浼樼銆?/p>

4.Tcmalloc浼樺寲Nginx 鎬ц兘

  1. # wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
  2. # tar zxvf libunwind-0.99-alpha.tar.gz
  3. # cd libunwind-0.99-alpha/
  4. # CFLAGS=-fPIC ./configure
  5. # make CFLAGS=-fPIC
  6. # make CFLAGS=-fPIC install
  7. # wget http://google-perftools.googlecode.com/files/google-perftools-0.98.tar.gz
  8. # tar zxvf google-perftools-0.98.tar.gz
  9. # cd google-perftools-0.98/
  10. # ./configure
  11. # make && make install
  12. # echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  13. # ldconfig
  14. # lsof -n | grep tcmalloc






]]>
libevent 瀛︿範(fàn)絎旇http://www.tkk7.com/Skynet/archive/2010/01/05/308249.html鍒樺嚡姣?/dc:creator>鍒樺嚡姣?/author>Tue, 05 Jan 2010 03:21:00 GMThttp://www.tkk7.com/Skynet/archive/2010/01/05/308249.htmlhttp://www.tkk7.com/Skynet/comments/308249.htmlhttp://www.tkk7.com/Skynet/archive/2010/01/05/308249.html#Feedback0http://www.tkk7.com/Skynet/comments/commentRss/308249.htmlhttp://www.tkk7.com/Skynet/services/trackbacks/308249.html 瀛︿範(fàn)錛?br /> http://blog.chinaunix.net/u1/59571/showart_2077664.html

涓漢瀵逛笂闈㈡枃绔犲仛鐨?絎旇鍏變韓鍑烘潵 鍜屽ぇ瀹跺垎浜紒




]]>
beanstalkd 娑堟伅闃熷垪鐨勭涓鎵嬭祫鏂?/title><link>http://www.tkk7.com/Skynet/archive/2009/10/30/300325.html</link><dc:creator>鍒樺嚡姣?/dc:creator><author>鍒樺嚡姣?/author><pubDate>Fri, 30 Oct 2009 04:05:00 GMT</pubDate><guid>http://www.tkk7.com/Skynet/archive/2009/10/30/300325.html</guid><wfw:comment>http://www.tkk7.com/Skynet/comments/300325.html</wfw:comment><comments>http://www.tkk7.com/Skynet/archive/2009/10/30/300325.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/Skynet/comments/commentRss/300325.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/Skynet/services/trackbacks/300325.html</trackback:ping><description><![CDATA[<br /> beanstalk 娑堟伅闃熷垪 灝忕粨 <br /> 鍗忚璇存槑鍜屽悇鐘舵佽漿鎹㈡儏鍐?br /> <br /> <br /> <strong>鍩烘湰鐭ヨ瘑鐐?</strong><br />   1. 瀵逛簬beanstalk 娑堟伅闃熷垪涓瘡鏉℃暟鎹兘涓?job<br />   2. beanstalk service绔?錛屼細(xì)緇存姢 tubes[澶氫釜綆¢亾]<br />   3. client绔彲浠ョ洃鍚?浣跨敤澶?tube<br />   4. client绔彲浠ユ寚瀹?use 綆¢亾[ client鐢熸垚涓涓柊鐨刯ob鏃朵細(xì)鎶婃job鎻愪氦鍒?鎸囧畾綆¢亾]<br />   5. client绔彲浠ユ寚瀹?watch 綆¢亾 [ client鎺ユ敹澶勭悊job鏃朵細(xì)鍒?鎸囧畾綆¢亾寰楀埌寰呭鐞嗙殑job]<br /> <br /> <br /> <strong>瀹樻柟紺烘剰鍥?</strong><br /> put            reserve               delete<br /> -----> [READY] ---------> [RESERVED] --------> *poof*<br /> <br /> <strong>涓鑸儏鍐?</strong><br /> 1. 浠誨姟鎻愪氦鍒皊ervice绔?job 綆$悊鏀懼叆鍐呭瓨絀洪棿騫朵負(fù)鍏舵爣璁扮姸鎬?[READY] <br /> 2. client閫氳繃杞绔炰簤寰楀埌嬈$姸鎬? job 鏀逛負(fù)  [RESERVED]<br />    2.1 褰撳湪榛樿鏃墮棿 120 縐掑唴娌″鐞嗗畬 , job.stats.timeouts 灝變細(xì)澶т簬 0 <br />       鍚屾椂鍏朵粬 杞绔炰簤client浼?xì)鎷垮埌杩欎釜job銆?娉ㄦ剰浜?姣忔timeouts鏃?鍦ㄨ疆璁殑瀹㈡埛绔氨浼?xì)寰楀埌娆ob錛岀姸鎬侀兘涓?ready,timeouts>0 銆?br /> 3. 闅忎究鍏朵腑涓鍙癱lient澶勭悊瀹?job.delete   , 鍏朵粬 client 涓殑姝ob 閮戒細(xì)    *poof*  <br /> <br /> <br /> <br /> <br /> <strong>deom - python beanstalkc 涓?job.stats 鍙傝?</strong><br /> <strong>浣跨敤 easy_install beanstalkc </strong><br /> <strong>API 鍙傝?: http://github.com/earl/beanstalkc/blob/master/TUTORIAL</strong><br /> 鍒氱敓鎴愮殑 beanstalk<br /> {'buries': 0, 'releases': 0, 'tube': 'default', 'timeouts': 0, 'ttr': 120, <br /> 'age': 6, 'pri': 2147483648L, 'delay': 0, '<strong>state</strong>': '<strong>reserved</strong>', '<strong>time-left</strong>': <strong>114</strong>, <br /> 'kicks': 0, 'id': 2}<br /> <br /> 浠imeout浜嗙殑 beanstalk,騫朵笖鍦ㄥ叾浠朿lient杞鍒?job<br /> {'buries': 0, 'releases': 0, 'tube': 'default', 'timeouts': 1, 'ttr': 120, <br /> 'age': 417, 'pri': 2147483648L, 'delay': 0, '<strong>state</strong>': '<strong>reserved</strong>', '<strong>time-left</strong>': <strong>110</strong>, <br /> 'kicks': 0, 'id': 2}<br /> {'buries': 0, 'releases': 0, 'tube': 'default', 'timeouts': 1, 'ttr': 120, 'age': 415, <br /> 'pri': 2147483648L, 'delay': 0, '<strong>state</strong>': '<strong>reserved</strong>', '<strong>time-left</strong>': <strong>4294967163L</strong>, <br /> 'kicks': 0, 'id': 2}<br /> <br /> 褰撴病鎵鏈塩lient 鐨?job 閮藉埌鏈?浜?鐘舵?br /> {'buries': 0, 'releases': 0, 'tube': 'default', 'timeouts': 2, 'ttr': 120, <br /> 'age': 417, 'pri': 2147483648L, 'delay': 0, '<strong>state</strong>': '<strong>ready</strong>', '<strong>time-left</strong>': <strong>4294967161L</strong>, <br /> 'kicks': 0, 'id': 2}<br /> {'buries': 0, 'releases': 0, 'tube': 'default', 'timeouts': 2, 'ttr': 120, 'age': 415, <br /> 'pri': 2147483648L, 'delay': 0, '<strong>state</strong>': '<strong>ready</strong>', '<strong>time-left</strong>': <strong>4294967163L</strong>, <br /> 'kicks': 0, 'id': 2}<br /> <br /> 鍏朵腑 client1 job.delete<br /> client1 job.stats  *poof*<br /> client2 job.stats  *poof*<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> 姣旇緝鍏ㄧ殑鐘舵佽鏄?- [瀹樻柟鏂囨。]<br /> http://github.com/kr/beanstalkd/blob/v1.1/doc/protocol.txt?raw=true<br /> <br /> 瀹樻柟紺烘剰鍥?<br />   <img src="http://www.tkk7.com/images/blogjava_net/skynet/beanstalk.jpg" alt="" border="0" /><br /> <br /> <br /> <strong>鍏堢畝鍗曡鏄庝笅錛堝畬鍏ㄨ嚜宸辯悊瑙g殑錛屾榪庢媿鐮栥傛湰浜篍浜哄お宸畘鐪嬪畼妗h垂鍔詫紝璋呰В涓嬶級: </strong><br /> job.stats鐘舵?= [READY] 寰呭鐞?  [RESERVED] 姝e鐞? [DELAYED]寤惰繜鐘舵?,  [BURIED] 闅愯棌鐘舵?br /> <br /> <strong>1. 寤惰繜鎻愪氦</strong><br /> py.client1.put>>> beanstalk.put('yes!', delay=10)<br /> py.client3.reserve>>> job = beanstalk.reserve()<br /> # 絳夊緟 10  縐?br /> <br /> <strong>2. 綆¢亾嫻嬭瘯</strong><br /> put-job鍒皊ervice绔?鍙互鎸囧畾 put鐨則ube綆¢亾<br /> 濡? <br /> <br /> py.client1.put>>> beanstalk.use('foo') <br /> py.client1.put>>> beanstalk.put('hey!')<br /> <br /> py.client2.reserve>>> job = beanstalk.reserve()<br /> # 涓鐩存嫢濉烇紝搴斾負(fù) 浠?watch 綆¢亾 'default'<br /> <br /> py.client3.reserve>>> beanstalk.watch('foo')<br /> # beanstalk.ignore('bar') 鏀懼純鐩戝惉 bar<br /> py.client3.reserve>>> job = beanstalk.reserve()<br /> py.client3.reserve>>> job.body #杈撳嚭 'hey!' <br /> <br /> <br /> <br /> <strong>3. 闅愯棌鐘舵?鐜板湪鍚?client 1/2/3 鐨?use watch 鐨勭閬撻兘璋冨洖 default</strong><br /> py.client2.reserve>>> job = beanstalk.reserve()<br /> py.client3.reserve>>> job = beanstalk.reserve()<br /> py.client1.put>>> beanstalk.put('闅愯棌鐘舵?')<br /> py.client2.reserve>>> job.bury() #2 杞寰楀埌 騫朵笖 淇敼 job 涓洪殣钘忕姸鎬?br /> # 120 縐掑悗 client3 娌℃湁杞寰楀埌 姝ob <br /> py.client2.reserve>>> job.stats() <br /> {'buries': 1, 'releases': 0, 'tube': 'default', 'timeouts': 0, 'ttr': 120, <br /> 'age': 188, 'pri': 2147483648L, 'delay': 0, 'state': 'buried',<br /> 'time-left': 4294967228L, 'kicks': 0, 'id': 11}<br /> py.client2.reserve>>> beanstalk.kick( job.stats()['id'] ) #淇敼鐘舵佷負(fù) reserved<br /> # 绔嬪埢 client3 寰楀埌 job<br /> py.client3.reserve>>> job.stats()<br /> {'buries': 1, 'releases': 0, 'tube': 'default', 'timeouts': 0, 'ttr': 120, 'age': 313, <br /> 'pri': 2147483648L, 'delay': 0, 'state': 'reserved', <br /> 'time-left': 110, 'kicks': 1, 'id': 11}<br /> # 榪欐椂鍊?client2 / 3 鍚屾椂 鏈?job 11 鐘舵?'buries': 1,'timeouts': 0,'state': 'reserved'<br /> <br /> <strong>4. peek 紿ヨ</strong><br />   鍙互寰楀埌 涓涓?stats - read 鐨?job 錛屽叾浠?client 鍙互 job = beanstalk.reserve() <br />   鍚庨┈涓?job.stats 浼?xì)鍙樻?nbsp; [RESERVED] <br />   py.client2.reserve>>> job = beanstalk.peek_ready()<br />   鍙栧緱 job 騫剁湅 鏈?client 鑳?澶勭悊鑳?br /> >>> job = beanstalk.peek(3)<br /> >>> job.body<br />     'yes!'<br /> >>> job.stats()['state']<br />     'ready'<br /> 榪欑褰㈠紡瑗?job 涓嶈兘 bury 絳変慨鏀圭姸鎬侊紝浣?鍙互 delete<br /> <br /> peek 緋葷被<br />  peek_buried<br />  peek_ready<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <img src ="http://www.tkk7.com/Skynet/aggbug/300325.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/Skynet/" target="_blank">鍒樺嚡姣?/a> 2009-10-30 12:05 <a href="http://www.tkk7.com/Skynet/archive/2009/10/30/300325.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>娑堟伅闃熷垪 beanstalkd 浠嬬粛http://www.tkk7.com/Skynet/archive/2009/10/28/300097.html鍒樺嚡姣?/dc:creator>鍒樺嚡姣?/author>Wed, 28 Oct 2009 11:21:00 GMThttp://www.tkk7.com/Skynet/archive/2009/10/28/300097.htmlhttp://www.tkk7.com/Skynet/comments/300097.htmlhttp://www.tkk7.com/Skynet/archive/2009/10/28/300097.html#Feedback0http://www.tkk7.com/Skynet/comments/commentRss/300097.htmlhttp://www.tkk7.com/Skynet/services/trackbacks/300097.html 棣栧厛 濂戒笢瑗?
  http://kr.github.com/beanstalkd/


鍏舵 鐪熺殑鏄ソ涓滆タ 鏀寔 java , python ,perl,ruby,erlang 鍜屾垜涓嶇煡閬撶殑 璇█
  瀹樻柟鐨勫師鏂囦粙緇嶏細(xì)
$ ./beanstalkd -d -l 10.0.1.5 -p 11300

This starts up beanstalkd as a daemon listening on address 10.0.1.5, port 11300.

Use It

Here’s an example in Ruby (see the client libraries to find your favorite language).

First, have one process put a job into the queue:

beanstalk = Beanstalk::Pool.new(['10.0.1.5:11300'])

beanstalk.put('hello')

Then start another process to take jobs out of the queue and run them:

beanstalk = Beanstalk::Pool.new(['10.0.1.5:11300'])

loop do

job = beanstalk.reserve

puts job.body # prints "hello"

job.delete

end





Thanks

Many thanks to memcached for providing inspiration for simple protocol design and for the structure of the documentation. Not to mention a fantastic piece of software!




]]>
hadoop streaming( hadoop + perl )灝忚瘯http://www.tkk7.com/Skynet/archive/2009/09/25/296420.html鍒樺嚡姣?/dc:creator>鍒樺嚡姣?/author>Fri, 25 Sep 2009 06:33:00 GMThttp://www.tkk7.com/Skynet/archive/2009/09/25/296420.htmlhttp://www.tkk7.com/Skynet/comments/296420.htmlhttp://www.tkk7.com/Skynet/archive/2009/09/25/296420.html#Feedback0http://www.tkk7.com/Skynet/comments/commentRss/296420.htmlhttp://www.tkk7.com/Skynet/services/trackbacks/296420.html   http://hadoop.apache.org/common/docs/r0.15.2/streaming.html

娉ㄦ剰
  鐩墠 streaming 瀵?linux pipe #涔熷氨鏄?cat |wc -l 榪欐牱鐨勭閬?涓嶆敮鎸侊紝浣嗕笉濡ㄧ鎴戜滑浣跨敤perl,python 琛屽紡鍛戒護(hù)錛侊紒
  鍘熻瘽鏄?錛?br />   Can I use UNIX pipes? For example, will -mapper "cut -f1 | sed s/foo/bar/g" work?
    Currently this does not work and gives an "java.io.IOException: Broken pipe" error.
    This is probably a bug that needs to be investigated.
  浣嗗鏋滀綘鏄己鐑堢殑 linux shell pipe 鍙戠儳鍙?錛?鍙傝冧笅闈?br />   $> perl -e 'open( my $fh, "grep -v null tt |sed -n 1,5p |");while ( <$fh> ) {print;} '
     #涓嶈繃鎴戞病嫻嬭瘯閫氳繃 錛侊紒

鐜 錛歨adoop-0.18.3
$> find . -type f -name "*streaming*.jar"
./contrib/streaming/hadoop-0.18.3-streaming.jar


嫻嬭瘯鏁版嵁錛?br />
-bash-3.00$ head tt 
null    false    3702    208100
6005100    false    70    13220
6005127    false    24    4640
6005160    false    25    4820
6005161    false    20    3620
6005164    false    14    1280
6005165    false    37    7080
6005168    false    104    20140
6005169    false    35    6680
6005240    false    169    32140
......


榪愯錛?br />
c1="  perl -ne  'if(/.*\t(.*)/){\$sum+=\$1;}END{print \"\$sum\";}'  "
# 娉ㄦ剰 榪欓噷 $ 瑕佸啓鎴?\$    " 鍐欐垚 \"
echo $c1; # 鎵撳嵃杈撳嚭  perl -ne 'if(/.*"t(.*)/){$sum+=$1;}END{print $sum;}'
hadoop jar hadoop-0.18.3-streaming.jar
  
-input file:///data/hadoop/lky/jar/tt 
   -
mapper   "/bin/cat" 
   -
reducer "$c1" 
  
-output file:///tmp/lky/streamingx8


緇撴灉:
cat /tmp/lky/streamingx8/*
1166480

鏈湴榪愯杈撳嚭:
perl -ne 'if(/.*"t(.*)/){$sum+=$1;}END{print $sum;}' < tt
1166480

緇撴灉姝g‘!!!!


鍛戒護(hù)鑷甫鏂囨。錛?br />
-bash-3.00$ hadoop jar hadoop-0.18.3-streaming.jar -info
09/09/25 14:50:12 ERROR streaming.StreamJob: Missing required option -input
Usage: $HADOOP_HOME
/bin/hadoop [--config dir] jar \
          $HADOOP_HOME
/hadoop-streaming.jar [options]
Options:
  
-input    <path>     DFS input file(s) for the Map step
  
-output   <path>     DFS output directory for the Reduce step
  
-mapper   <cmd|JavaClassName>      The streaming command to run
  
-combiner <JavaClassName> Combiner has to be a Java class
  
-reducer  <cmd|JavaClassName>      The streaming command to run
  
-file     <file>     File/dir to be shipped in the Job jar file
  
-dfs    <h:p>|local  Optional. Override DFS configuration
  
-jt     <h:p>|local  Optional. Override JobTracker configuration
  
-additionalconfspec specfile  Optional.
  
-inputformat TextInputFormat(default)|SequenceFileAsTextInputFormat|JavaClassName Optional.
  
-outputformat TextOutputFormat(default)|JavaClassName  Optional.
  
-partitioner JavaClassName  Optional.
  
-numReduceTasks <num>  Optional.
  
-inputreader <spec>  Optional.
  
-jobconf  <n>=<v>    Optional. Add or override a JobConf property
  
-cmdenv   <n>=<v>    Optional. Pass env.var to streaming commands
  
-mapdebug <path>  Optional. To run this script when a map task fails 
  
-reducedebug <path>  Optional. To run this script when a reduce task fails 
  
-cacheFile fileNameURI
  
-cacheArchive fileNameURI
  
-verbose




]]>
hadoop jython ( windows )http://www.tkk7.com/Skynet/archive/2009/09/04/293914.html鍒樺嚡姣?/dc:creator>鍒樺嚡姣?/author>Fri, 04 Sep 2009 09:14:00 GMThttp://www.tkk7.com/Skynet/archive/2009/09/04/293914.htmlhttp://www.tkk7.com/Skynet/comments/293914.htmlhttp://www.tkk7.com/Skynet/archive/2009/09/04/293914.html#Feedback0http://www.tkk7.com/Skynet/comments/commentRss/293914.htmlhttp://www.tkk7.com/Skynet/services/trackbacks/293914.htmlhadoop window 鎼緩 鍚?鐢變簬瀵?py 鐨勮娉曞枩嬈?錛屼竴鐩存兂 鎶奾adoop,鏀規(guī)垚jython 鐨?
榪欐 鍦?鑷繁鐢?shù)鑴戜?nbsp; 緇堜簬 瀹屾垚,涓嬮潰浠嬬粛榪囩▼:

嫻嬭瘯鐜錛?br /> 渚濈劧鐨?windows + cygwin
hadoop 0.18  # C:/cygwin/home/lky/tools/java/hadoop-0.18.3
jython 2.2.1 # C:/jython2.2.1

鍙傝? PythonWordCount

鍚姩 hadoop 騫跺埌 hdoop_home 涓?br />
# 鍦ㄤ簯鐜涓垱寤?input 鐩綍
$>bin/hadoop dfs -mkdir input

# 鍦?鍖?hadoop 鐨?NOTICE.txt 鎷瘋礉鍒?input 鐩綍涓?/strong>
$>bin/hadoop dfs -copyFromLocal c:/cygwin/home/lky/tools/java/hadoop-0.18.3/NOTICE.txt  hdfs:///user/lky/input

$>cd
src/examples/python

# 鍒涘緩 涓?鑴氭湰 ( jy->jar->hd run  ) 涓姝ュ畬鎴?
# 褰撶劧 鍦?linux 鍐欎釜鑴氭湰姣旇繖 濂界湅 鍛靛懙錛?br />
$>vim run.bat
"C:\Program Files\Java\jdk1.6.0_11\bin\java.exe"  -classpath "C:\jython2.2.1\jython.jar;%CLASSPATH%" org.python.util.jython C:\jython2.2.1\Tools\jythonc\jythonc.py   -p org.apache.hadoop.examples -d -j wc.jar -c %1

sh C:\cygwin\home\lky\tools\java\hadoop-
0.18.3\bin\hadoop jar wc.jar  %2 %3 %4 %5 %6 %7 %8 %9

# 淇敼 jythonc 鎵撳寘 鐜 銆?+hadoop jar
$>vim C:\jython2.2.1\Tools\jythonc\jythonc.py
# Copyright (c) Corporation for National Research Initiatives
# Driver script for jythonc2.  See module main.py for details
import sys,os,glob

for fn in glob.glob('c:/cygwin/home/lky/tools/java/hadoop-0.18.3/*.jar') :sys.path.append(fn)
for fn in glob.glob('c:/jython2.2.1/*.jar') :sys.path.append(fn)
for fn in glob.glob('c:/cygwin/home/lky/tools/java/hadoop-0.18.3/lib/*.jar'
) :sys.path.append(fn)

import main
main.main()

import os
os._exit(0)


# 榪愯
C:/cygwin/home/lky/tools/java/hadoop-0.18.3/src/examples/python>
  run.bat WordCount.py  hdfs:///user/lky/input  file:///c:/cygwin/home/lky/tools/java/hadoop-0.18.3/tmp2




緇撴灉杈撳嚭錛?/strong>
cat c:/cygwin/home/lky/tools/java/hadoop-0.18.3/tmp2/part-00000
(http://www.apache.org/).       1
Apache  1
Foundation      1
Software        1
The     1
This    1
by      1
developed       1
includes        1
product 1
software        1

涓嬮潰閲嶅ご鏉ヤ簡 錛氾紙綆媧佺殑 jy hdoop 浠g爜錛?/strong>
#
#
 Licensed to the Apache Software Foundation (ASF) under one
#
 or more contributor license agreements.  See the NOTICE file
#
 distributed with this work for additional information
#
 regarding copyright ownership.  The ASF licenses this file
#
 to you under the Apache License, Version 2.0 (the
#
 "License"); you may not use this file except in compliance
#
 with the License.  You may obtain a copy of the License at
#
#
     http://www.apache.org/licenses/LICENSE-2.0
#
#
 Unless required by applicable law or agreed to in writing, software
#
 distributed under the License is distributed on an "AS IS" BASIS,
#
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
 See the License for the specific language governing permissions and
#
 limitations under the License.
#

from org.apache.hadoop.fs import Path
from org.apache.hadoop.io import *
from org.apache.hadoop.mapred import *

import sys
import getopt

class WordCountMap(Mapper, MapReduceBase):
    one 
= IntWritable(1)
    
def map(self, key, value, output, reporter):
        
for w in value.toString().split():
            output.collect(Text(w), self.one)

class Summer(Reducer, MapReduceBase):
    
def reduce(self, key, values, output, reporter):
        sum 
= 0
        
while values.hasNext():
            sum 
+= values.next().get()
        output.collect(key, IntWritable(sum))

def printUsage(code):
    
print "wordcount [-m <maps>] [-r <reduces>] <input> <output>"
    sys.exit(code)

def main(args):
    conf 
= JobConf(WordCountMap);
    conf.setJobName(
"wordcount");
 
    conf.setOutputKeyClass(Text);
    conf.setOutputValueClass(IntWritable);
    
    conf.setMapperClass(WordCountMap);        
    conf.setCombinerClass(Summer);
    conf.setReducerClass(Summer);
    
try:
        flags, other_args 
= getopt.getopt(args[1:], "m:r:")
    
except getopt.GetoptError:
        printUsage(
1)
    
if len(other_args) != 2:
        printUsage(
1)
    
    
for f,v in flags:
        
if f == "-m":
            conf.setNumMapTasks(int(v))
        
elif f == "-r":
            conf.setNumReduceTasks(int(v))
    conf.setInputPath(Path(other_args[0]))
    conf.setOutputPath(Path(other_args[
1]))
    JobClient.runJob(conf);

if __name__ == "__main__":
    main(sys.argv)







]]>
hadoop cascading demo http://www.tkk7.com/Skynet/archive/2009/07/22/287807.html鍒樺嚡姣?/dc:creator>鍒樺嚡姣?/author>Wed, 22 Jul 2009 02:01:00 GMThttp://www.tkk7.com/Skynet/archive/2009/07/22/287807.htmlhttp://www.tkk7.com/Skynet/comments/287807.htmlhttp://www.tkk7.com/Skynet/archive/2009/07/22/287807.html#Feedback0http://www.tkk7.com/Skynet/comments/commentRss/287807.htmlhttp://www.tkk7.com/Skynet/services/trackbacks/287807.html Java 浠g爜錛?br />
package com.xunjie.dmsp.olduser;

import java.util.Properties;

import cascading.flow.Flow;
import cascading.flow.FlowConnector;
import cascading.operation.regex.RegexSplitter;
import cascading.pipe.Each;
import cascading.pipe.Pipe;
import cascading.scheme.TextLine;
import cascading.tap.Hfs;
import cascading.tap.Tap;
import cascading.tuple.Fields;

/**
 * test.txt錛?nbsp;
 * 1    a
 * 2    b
 * 3    c
 * 
 * /data/hadoop/hadoop/bin/hadoop jar 
 *         dmsp_test_jar-1.0-SNAPSHOT-dependencies.jar 
 *             hdfs:/user/hadoop/test/lky/test.txt
 *             file:///data/hadoop/test/lky/output
 
*/
public class Test2 {
    
public static void main(String[] args) {
        
        
//璁懼畾杈撳叆鏂囦歡
        String sourcePath= args[0];
        
//璁劇疆杈撳嚭鏂囦歡澶?/span>
        String sinkPath = args[1];

        
//瀹氫箟璇誨彇鍒?/span>
        Fields inputfields = new Fields("num""value");
        
//瀹氫箟鍒嗚В姝e垯錛岄粯璁?nbsp;\t
        RegexSplitter spliter = new RegexSplitter(inputfields);
        
        
        
//綆¢亾瀹氫箟
        Pipe p1 = new Pipe( "test" );
        
//綆¢亾宓屽錛?br />         //鍒嗚В鏃ュ織婧愭枃浠訛紝杈撳嚭緇欏畾瀛楁
        p1 = new Each(p1,new Fields("line") ,spliter);
        
        
        
//璁懼畾杈撳叆鍜岃緭鍑?nbsp;錛屼嬌鐢?nbsp;娉涘瀷Hfs
        Tap source = new Hfs( new TextLine(),  sourcePath );
        Tap sink 
= new Hfs( new TextLine() , sinkPath );
        
        
        
        
//閰嶇疆job
        Properties properties = new Properties();
        properties.setProperty(
"hadoop.job.ugi""hadoop,hadoop");
        
        FlowConnector.setApplicationJarClass( properties, Main.
class );
        FlowConnector flowConnector 
= new FlowConnector(properties);
        
        Flow importFlow 
= flowConnector.connect( "import flow", source,sink,p1);
        
        importFlow.start();
        importFlow.complete();
        

    }
}




]]>
hadoop window 鎼緩http://www.tkk7.com/Skynet/archive/2009/07/08/285919.html鍒樺嚡姣?/dc:creator>鍒樺嚡姣?/author>Wed, 08 Jul 2009 03:07:00 GMThttp://www.tkk7.com/Skynet/archive/2009/07/08/285919.htmlhttp://www.tkk7.com/Skynet/comments/285919.htmlhttp://www.tkk7.com/Skynet/archive/2009/07/08/285919.html#Feedback0http://www.tkk7.com/Skynet/comments/commentRss/285919.htmlhttp://www.tkk7.com/Skynet/services/trackbacks/285919.html hadoop 鍘熺悊鍙傝冿細(xì)windows ssh 鎼緩
2. 鎼緩hadoop  Cygwin涓嬬殑Hadoop蹇熷叆闂?浼垎甯冨紡妯″紡鐨勬煡緙鴻ˉ婕?/a>
    榪欓噷榪樻湁 cygwin putty 鎺у埗鍙版柟娉曡緗?br /> 3. 寮鍙戠幆澧冨拰 demo
hadoop-site.xml 銆?br />    鍦ㄨ繖涓増鏈凡緇忓湪conf涓嬫壘涓嶅埌浜嗭紝鎴戣繖灝濊瘯淇敼鐨?hdfs-site.xml 銆傛祴璇曠殑鏃跺欑珶鐒墮氳繃浜嗐?br />  
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>
  
<property>
    
<name>fs.default.name</name>
    
<value>hdfs://localhost:9000</value>
  
</property>

  
<property>
    
<name>mapred.job.tracker</name>
    
<value>localhost:9001</value>
  
</property>

  
<property>
    
<name>dfs.data.dir</name>
    
<!--linux -->
    
<!--<value>/home/lky/tools/java/hadoop-0.18.3/dfs</value>-->
    
<value>C:\\cygwin\\home\\lky\\tools\\java\\hadoop-0.18.3\\dfs\\</value>
  
</property>


  
<property>
    
<name>hadoop.tmp.dir</name>
    
<value>/tmp</value>
  
</property>



  
<property>
    
<name>dfs.replication</name>
    
<value>1</value>
  
</property>


<property>
  
<name>fs.trash.interval</name>
  
<value>60</value>
  
<description>Number of minutes between trash checkpoints.
  If zero, the trash feature is disabled.
  
</description>
</property>
  
</configuration>



]]>
svn 綆鍗曚嬌鐢?/title><link>http://www.tkk7.com/Skynet/archive/2009/05/19/271570.html</link><dc:creator>鍒樺嚡姣?/dc:creator><author>鍒樺嚡姣?/author><pubDate>Tue, 19 May 2009 09:37:00 GMT</pubDate><guid>http://www.tkk7.com/Skynet/archive/2009/05/19/271570.html</guid><wfw:comment>http://www.tkk7.com/Skynet/comments/271570.html</wfw:comment><comments>http://www.tkk7.com/Skynet/archive/2009/05/19/271570.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/Skynet/comments/commentRss/271570.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/Skynet/services/trackbacks/271570.html</trackback:ping><description><![CDATA[<br /> <br /> svn 甯姪鏂囨。錛屽ぇ浣撲笂嫻忚浜嗕笅 涓浜涙瘮杈冨ソ鐨勭壒鎬?鏈夛細(xì)<br /> <strong><a target="_blank">http://www.subversion.org.cn/<wbr>svnbook/</a></strong><br /> <br /> <br /> <span style="border-collapse: separate; color: #000000; font-family: arial; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><a style="background-color: #c0c0ff; color: purple; text-decoration: underline;" target="_blank">鍒嗘敮涓庡悎騫?/a><br /> </span><span style="border-collapse: separate; color: #000000; font-family: arial; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><a style="color: purple; text-decoration: underline;" target="_blank">閿佸畾</a></span><br /> <span style="border-collapse: separate; color: #000000; font-family: arial; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><a style="background-color: #c0c0ff; color: purple; text-decoration: underline;" target="_blank"><span style="font-family: 'courier new',courier,fixed; font-style: normal; font-weight: normal;"><strong>svnsync</strong></span></a></span><br /> <span style="border-collapse: separate; color: #000000; font-family: arial; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><a style="background-color: #c0c0ff; color: blue; text-decoration: underline;" target="_blank">鐗堟湰搴撻挬瀛?/a><br /> </span><span style="border-collapse: separate; color: #000000; font-family: arial; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><a style="color: purple; text-decoration: underline;" target="_blank">涓涓猄VN  Python鐘舵佺埇铏?/a></span><br /> <br /> <br /> <strong style="color: #cc0000;">娉ㄦ剰 浣跨敤鐢ㄦ埛 (sysmen)  錛?/strong><br /> <strong>#鎸囧畾鏂扮増鏈?/strong><br /> vim ~.bashrc #娣誨姞浜?br /> alias svn="/usr/local/subversion/ <div class="39hr99r" id=":c6" class="ii gt"><wbr>bin/svn"<br /> alias svnadmin="/usr/local/<wbr>subversion/bin/svnadmin"<br /> alias svnserve="/usr/local/<wbr>subversion/bin/svnserve"<br /> <br /> <strong>#鏈綆鍗?svn 鏈嶅姟鍣ㄦ惌寤?/strong><br /> cd /home/sysman/src/svn/<br /> svnadmin create test<br /> svnserve -d -r /home/sysman/src/svn/test/<br /> <br /> <strong>#鏈綆鍗曢厤緗?/strong><br /> #vim svnserve.conf<br /> [general]<br /> password-db = passwd<br /> realm = test<br /> <br /> anon-access = <strong>read</strong><br /> auth-access = <strong>write</strong><br /> <br /> <br /> <br /> <strong>#鏌ョ湅 </strong><br /> cd /home/sysman/src/svn/testsrc<br /> svn <strong>list  </strong>svn://<a target="_blank">127.0.0.1/test</a> <br /> <br /> <br /> <strong>#榪佸嚭</strong><br /> cd /home/sysman/src/svn/testsrc<br /> svn <strong>checkout  </strong>svn://<a target="_blank">127.0.0.1/test</a><br /> <br /> <br /> <strong>#榪佸叆</strong><br /> cd test <br /> echo "google - baidu " > baidu<br /> svn <strong>add </strong>baidu svn://<a target="_blank">127.0.0.1/test</a> <br /> svn <strong>commit </strong>-m 'add ok'<br /> svn list  svn://<a target="_blank">127.0.0.1/test</a> <br /> # baidu<br /> # tt<br /> <br /> <br /> #璇︾粏鍙傝?錛?br /> <strong><a target="_blank">http://www.subversion.org.cn/<wbr>svnbook/</a></strong><br /> 鍦ㄦ枃妗d腑鏈夊叧鏈夋剰鎬濈殑浠嬬粛 錛坰vnsync錛夛細(xì)<br /> <strong><a target="_blank">http://www.subversion.org.cn/<wbr>svnbook/1.4/svn.ref.svnsync.<wbr>html</a></strong><br /> <br /> <br /> 鍏朵粬璇存槑 錛?br /> <br /> 1.甯姪<br /> svn help<br /> 鎴?<br /> svn help add<br /> <br /> 2.涓鑸搷浣?br /> 鏇存柊浣犵殑宸ヤ綔鎷瘋礉<br />     svn update<br /> <br /> 鍋氬嚭淇敼<br />     svn add<br />     svn delete<br />     svn copy<br />     svn move<br /> <br /> 媯楠屼慨鏀?br />     svn status<br />     svn diff<br /> <br /> 鍙兘浼?xì)鍙栨秷涓浜涗慨鏀?br />     svn revert<br /> <br /> 瑙e喅鍐茬獊錛堝悎騫跺埆浜虹殑淇敼錛?br />     svn update<br />     svn resolved<br /> <br /> 鎻愪氦浣犵殑淇敼<br />     svn commit<br /> <br /> <br /> </div> <br /> <br /> <img src ="http://www.tkk7.com/Skynet/aggbug/271570.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/Skynet/" target="_blank">鍒樺嚡姣?/a> 2009-05-19 17:37 <a href="http://www.tkk7.com/Skynet/archive/2009/05/19/271570.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title> soap (java,perl,瑕佸啓浠g爜 榪樹笉榪?100 char) http://www.tkk7.com/Skynet/archive/2009/03/02/257264.html鍒樺嚡姣?/dc:creator>鍒樺嚡姣?/author>Sun, 01 Mar 2009 16:00:00 GMThttp://www.tkk7.com/Skynet/archive/2009/03/02/257264.htmlhttp://www.tkk7.com/Skynet/comments/257264.htmlhttp://www.tkk7.com/Skynet/archive/2009/03/02/257264.html#Feedback0http://www.tkk7.com/Skynet/comments/commentRss/257264.htmlhttp://www.tkk7.com/Skynet/services/trackbacks/257264.html 鍙兘鏈綆鍗曠殑 soap 鍝︼紒
鏈嶅姟鍣ㄤ負(fù) java tomcat
涓嬭澆鏈嶅姟鍣細(xì)http://www.apache.org/dist/ws/
   axis/ 涓簀ava
   axis-c/    涓?c

1.鎴戣繖涓嬭澆鐨?axis 1_4 鐗堟湰 錛岃В鍘?/webapps/axis  鏀懼埌 tomcat 鐨剋ebapps
鍚姩tomcat錛堣繖灝變笉淇敼浠諱綍錛屽鏈夐渶瑕?璇?web.xml 絳夐厤緗簡錛?a style="font-size: 12px;" onclick="NEBlog.gPrevBlog.oBlogList._oUpdownMenu.openBlog('blog/static/307422712007552499407', event);return false;"> 鍙傝?>>
    blog 涓?榪樻湁寰堝浠嬬粛 axis 澶у鍙互 鐪嬬湅  鏃ュ織 > 鍏朵笅鐨?"瀛︿範(fàn)"

鐩存帴鍐欎釜鏂囦歡 HelloWorld.jws 鏀懼埌 %TOMCAT_HOME%"webapps"axis
public class HelloWorld {   
     
public String sayHello()   {   
     
return "HELLO soap!";    
 }    


絳変笉鍙?鍙互浣跨敤 鐪嬬湅
http://127.0.0.1:8080/axis/HelloWorld.jws?method=sayHello
緇撴灉 錛?br />
<soapenv:Envelope>
<soapenv:Body>
<sayHelloResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sayHelloReturn xsi:type="xsd:string">HELLO soap!</sayHelloReturn>
</sayHelloResponse>
</soapenv:Body>
</soapenv:Envelope>


瀹㈡埛孌?br /> perl cpan >> install  SOAP::Lite
#!perl -w
use SOAP::Lite;
print SOAP::Lite
    
-> proxy('http://127.0.0.1:8080/axis/HelloWorld.jws')
    
-> uri('http://127.0.0.1:8080/axis/HelloWorld.jws')
    
-> sayHello()
    
-> result;
緇撴灉錛?HELLO soap錛?/span>






]]>
主站蜘蛛池模板: 黄色a级片免费看| 亚洲免费网站在线观看| 免费国产va在线观看| 免费久久精品国产片香蕉| 69视频免费观看l| 一级毛片在线播放免费| 亚洲欧美日韩一区二区三区| 91精品国产亚洲爽啪在线观看| 亚洲综合色视频在线观看| 永久黄网站色视频免费| 在线观看av永久免费| 永久在线免费观看| 久久国产乱子免费精品| 中文字幕无码免费久久9一区9 | 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 亚洲国产精品成人久久蜜臀 | 亚洲无限乱码一二三四区| 亚洲国产精品特色大片观看完整版 | 中文字幕亚洲图片| vvvv99日韩精品亚洲| 国产一级做a爱免费视频| 日本不卡高清中文字幕免费| 中字幕视频在线永久在线观看免费| 十九岁在线观看免费完整版电影| 免费看黄的成人APP| 中国国产高清免费av片| 国产免费人成视频在线播放播 | 亚洲精品国产精品乱码不卞 | 色老头综合免费视频| 美女被吸屁股免费网站| 在线精品自拍亚洲第一区| 亚洲1区2区3区精华液| 亚洲国产成人AV网站| 亚洲精品无码专区| 456亚洲人成影院在线观| 亚洲国产成a人v在线观看| 亚洲精品人成网在线播放影院| 日韩亚洲不卡在线视频中文字幕在线观看 | 无码人妻一区二区三区免费手机 | 四虎影视在线永久免费看黄| 卡一卡二卡三在线入口免费|