<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Rising Sun

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      148 隨筆 :: 0 文章 :: 22 評論 :: 0 Trackbacks

    #

    官網(wǎng):http://lucene.apache.org/solr/index.html 
    http://wiki.apache.org/solr/ 
    http://wiki.apache.org/solr/UpdateXmlMessages 
    教程 
    http://lucene.apache.org/solr/api/doc-files/tutorial.html 
    http://www.ibm.com/developerworks/cn/java/j-solr1/ 
    http://www.ibm.com/developerworks/cn/java/j-solr2/ 
    Apache Solr 初級教程 
    一些博客 
    http://www.cnblogs.com/wycg1984/category/238032.html 
    http://www.cnblogs.com/ibook360/tag/Solr/ 
    http://blog.chenlb.com/category/solr-search 
    http://www.webguo.com/?s=solr 
    http://www.kafka0102.com/2010/08/319.html 
    posted @ 2012-07-25 19:13 brock 閱讀(246) | 評論 (0)編輯 收藏

    在 Response-Header 中加上這幾項(xiàng):

    Last-Modified: Wed, 18 Jun 2008 14:22:27 GMT
    Cache-Control: max-age=600
    Expires: Wed, 18 Jun 2008 14:48:39 GMT
    Date: Wed, 18 Jun 2008 14:38:39 GMT


    其中 Last-Modified 后面的日期是上次更新 config 的時(shí)間,Date 后面是當(dāng)前時(shí)間,Expires 后面是當(dāng)前時(shí)間 + 10分鐘,10分鐘就是 Cache-Control 后面的 max-age,單位是秒。因?yàn)榭吹?GAE 對 static 文件的 Cache 時(shí)間也是10分鐘,所以我使用了這個(gè)數(shù)字。

    Last-Modified

    如果客戶端收到的 Response 中包含 Last-Modified,那么下次 request 的時(shí)候就會(huì)在 Request Header 中包含 If-Modified-Since 字段,值就是上次服務(wù)器發(fā)送的 Last-Modified,服務(wù)器端會(huì)判斷上次的 config 時(shí)間是否比 If-Modified-Since 晚。如果自上次 request 之后又更新了 config,那么服務(wù)器就會(huì)返回完整的內(nèi)容;如果期間沒有更新 config,那么服務(wù)器就沒必要返回完整的內(nèi)容,只需要向客戶端發(fā)送一個(gè) 304 Not Modified 狀態(tài)碼就可以了。

    Cache-Control、Date 和 Expires

    這幾個(gè)參數(shù)的組合,表示告訴瀏覽器:這個(gè)文件在多長時(shí)間之內(nèi)不會(huì)更改,在這個(gè)時(shí)間內(nèi)不需要再 request,保守起見,我設(shè)置了10分鐘。

    瀏覽器行為

    如果只是在網(wǎng)站的鏈接之間 click click click,那么瀏覽器會(huì)完全遵守上述行為。這樣可以盡可能地減少請求次數(shù),以及 response 的數(shù)據(jù)量。

    如果在某個(gè)頁面點(diǎn)擊了瀏覽器的刷新按鈕或者按 F5,瀏覽器會(huì)忽略 Expires 時(shí)間,把該頁面需要的所有的文件都重新請求一遍。

    如果按住 Ctrl 再刷新或者 Ctrl-F5 (俗稱強(qiáng)制刷新),瀏覽器將不會(huì)發(fā)送 Last-Modified Header,將所有需要的文件請求一遍,服務(wù)器會(huì)返回文件的完整內(nèi)容,而不是僅僅一個(gè) 304 Not Modified 狀態(tài)碼。

    后記

    經(jīng)初步觀察,現(xiàn)在瀏覽器不會(huì)每次都彪呼呼地去請求一大堆 css、jpg、gif 文件了,瀏覽器也不會(huì)每次都腦殘地返回完整內(nèi)容了,看來是有效了。

    posted @ 2012-07-24 17:29 brock 閱讀(18908) | 評論 (0)編輯 收藏

    最近在VPS上嘗試配置安裝一個(gè)網(wǎng)站,VPS安裝了LNMP(Linux+Nginx+MySQL+php)在配置重定規(guī)則的時(shí)候經(jīng)常遇到一些問題,直接用Apache的規(guī)則到Nginx下沒起作用。原來Apache 重寫的規(guī)則到nginx上還有一些不太一樣的地方。

    這里只是簡單記錄一些學(xué)習(xí)示例,高手略過,新手可以看一下。

    Nginx Rewrite規(guī)則相關(guān)指令
    Nginx Rewrite規(guī)則相關(guān)指令有if、rewrite、set、return、break等,其中rewrite是最關(guān)鍵的指令。一個(gè)簡單的Nginx Rewrite規(guī)則語法如下:

    rewrite ^/b/(.*)\.html /play.php?video=$1 break;

    如果加上if語句,示例如下:

    if (!-f $request_filename)

    rewrite ^/img/(.*)$ /site/$host/images/$1 last;

    Nginx與Apache的Rewrite規(guī)則實(shí)例對比

    簡單的Nginx和Apache 重寫規(guī)則區(qū)別不大,基本上能夠完全兼容。例如:

    Apache Rewrite 規(guī)則:

    RewriteRule ^/(mianshi|xianjing)/$ /zl/index.php?name=$1 [L]

    RewriteRule ^/ceshi/$ /zl/ceshi.php [L]

    RewriteRule ^/(mianshi)_([a-zA-Z]+)/$ /zl/index.php?name=$1_$2 [L]

    RewriteRule ^/pingce([0-9]*)/$ /zl/pingce.php?id=$1 [L]

    Nginx Rewrite 規(guī)則:

    rewrite ^/(mianshi|xianjing)/$ /zl/index.php?name=$1 last;

    rewrite ^/ceshi/$ /zl/ceshi.php last;

    rewrite ^/(mianshi)_([a-zA-Z]+)/$ /zl/index.php?name=$1_$2 last;

    rewrite ^/pingce([0-9]*)/$ /zl/pingce.php?id=$1 last;

    由以上示例可以看出,Apache的Rewrite規(guī)則改為Nginx的Rewrite規(guī)則,其實(shí)很簡單:Apache的RewriteRule指令換成Nginx的rewrite指令,Apache的[L]標(biāo)記換成Nginx的last標(biāo)記,中間的內(nèi)容不變。

    如果Apache的Rewrite規(guī)則改為Nginx的Rewrite規(guī)則后,使用nginx -t命令檢查發(fā)現(xiàn)nginx.conf配置文件有語法錯(cuò)誤,那么可以嘗試給條件加上引號(hào)。例如一下的Nginx Rewrite規(guī)則會(huì)報(bào)語法錯(cuò)誤:

    rewrite ^/([0-9]{5}).html$ /x.jsp?id=$1 last;

    加上引號(hào)就正確了:
    rewrite “^/([0-9]{5}).html$” /x.jsp?id=$1 last;

    Apache與Nginx的Rewrite規(guī)則在URL跳轉(zhuǎn)時(shí)有細(xì)微的區(qū)別:

    Apache Rewrite 規(guī)則:
    RewriteRule ^/html/tagindex/([a-zA-Z]+)/.*$ /$1/ [R=301,L]

    Nginx Rewrite 規(guī)則:
    rewrite ^/html/tagindex/([a-zA-Z]+)/.*$ http://$host/$1/ permanent;

    以上示例中,我們注意到,Nginx Rewrite 規(guī)則的置換串中增加了“http://$host”,這是在Nginx中要求的。

    另外,Apache與Nginx的Rewrite規(guī)則在變量名稱方面也有區(qū)別,例如:

    Apache Rewrite 規(guī)則:
    RewriteRule ^/user/login/$ /user/login.php?login=1&forward=http://%{HTTP_HOST} [L]

    Nginx Rewrite 規(guī)則:
    rewrite ^/user/login/$ /user/login.php?login=1&forward=http://$host   last;

    Apache與Nginx Rewrite 規(guī)則的一些功能相同或類似的指令、標(biāo)記對應(yīng)關(guān)系:

    Apache的RewriteCond指令對應(yīng)Nginx的if指令;
    Apache的RewriteRule指令對應(yīng)Nginx的rewrite指令;
    Apache的[R]標(biāo)記對應(yīng)Nginx的redirect標(biāo)記;
    Apache的[P]標(biāo)記對應(yīng)Nginx的last標(biāo)記;
    Apache的[R,L]標(biāo)記對應(yīng)Nginx的redirect標(biāo)記;
    Apache的[P,L]標(biāo)記對應(yīng)Nginx的last標(biāo)記;
    Apache的[PT,L]標(biāo)記對應(yīng)Nginx的last標(biāo)記;

    允許指定的域名訪問本站,其他域名一律跳轉(zhuǎn)到http://www.aaa.com

    Apache Rewrite 規(guī)則:
    RewriteCond %{HTTP_HOST}    ^(.*?)\.domain\.com$
    RewriteCond %{HTTP_HOST}    !^qita\.domain\.com$
    RewriteCond %{DOCUMENT_ROOT}/market/%1/index.htm -f
    RewriteRule ^/wu/$ /market/%1/index.htm [L]

    Nginx的if指令不支持嵌套,也不支持AND、OR等多條件匹配,相比于Apache的RewriteCond,顯得麻煩一些,但是,我們可以通過下一頁的Nginx配置寫法來實(shí)現(xiàn)這個(gè)示例:

    Nginx Rewrite 規(guī)則:
    if ($host ~* ^(.*?)\.domain\.com$) set $var_wupin_city $1;
         set $var_wupin ‘1′;

    if ($host ~* ^qita\.domain\.com$)

        set $var_wupin ‘0′;

     if (!-f $document_root/market/$var_wupin_city/index.htm)

         set $var_wupin ‘0′;

    if ($var_wupin ~ ‘1′)

        rewrite ^/wu/$ /market/$var_wupin_city/index.htm last;
    }

     

    rewrite 的語法

     

    語法: rewrite regex replacement flag

    默認(rèn): none

    作用域: server, location, if

    This directive changes URI in accordance with the regular expression and the replacement string. Directives are carried out in order of appearance in the configuration file.

    這個(gè)指令根據(jù)表達(dá)式來更改URI,或者修改字符串。指令根據(jù)配置文件中的順序來執(zhí)行。

    Be aware that the rewrite regex only matches the relative path instead of the absolute URL. If you want to match the hostname, you should use an if condition, like so:

    注意重寫表達(dá)式只對相對路徑有效。如果你想配對主機(jī)名,你應(yīng)該使用if語句。

    rewrite只是會(huì)改寫路徑部分的東東,不會(huì)改動(dòng)用戶的輸入?yún)?shù),因此這里的if規(guī)則里面,你無需關(guān)心用戶在瀏覽器里輸入的參數(shù),rewrite后會(huì)自動(dòng)添加的因此,我們只是加上了一個(gè)?號(hào)和后面我們想要的一個(gè)小小的參數(shù) ***https=1就可以了。

    nginx的rewrite規(guī)則參考:

    1. ~ 為區(qū)分大小寫匹配
    2. ~* 為不區(qū)分大小寫匹配
    3. !~和!~*分別為區(qū)分大小寫不匹配及不區(qū)分大小寫不匹
    1. -f和!-f用來判斷是否存在文件
    2. -d和!-d用來判斷是否存在目錄
    3. -e和!-e用來判斷是否存在文件或目錄
    4. -x和!-x用來判斷文件是否可執(zhí)行
    1. last 相當(dāng)于Apache里的[L]標(biāo)記,表示完成rewrite,呵呵這應(yīng)該是最常用的
    2. break 終止匹配, 不再匹配后面的規(guī)則
    3. redirect 返回302臨時(shí)重定向 地址欄會(huì)顯示跳轉(zhuǎn)后的地址
    4. permanent 返回301永久重定向 地址欄會(huì)顯示跳轉(zhuǎn)后的地址
    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

    結(jié)合QeePHP的例子

    1. if (!-d $request_filename) {
    2. rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&amp;controller=$1&amp;action=$2&amp;$3 last;
    3. rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&amp;controller=$1 last;
    4. break;

    多目錄轉(zhuǎn)成參數(shù)
    abc.domian.com/sort/2 => abc.domian.com/index.php?act=sort&name=abc&id=2

    1. if ($host ~* (.*)\.domain\.com) {
    2. set $sub_name $1;
    3. rewrite ^/sort\/(\d+)\/?$ /index.php?act=sort&cid=$sub_name&id=$1 last;
    4. }

    目錄對換
    /123456/xxxx -> /xxxx?id=123456

    1. rewrite ^/(\d+)/(.+)/ /$2?id=$1 last;

    例如下面設(shè)定nginx在用戶使用ie的使用重定向到/nginx-ie目錄下:

    1. if ($http_user_agent ~ MSIE) {
    2. rewrite ^(.*)$ /nginx-ie/$1 break;
    3. }

    目錄自動(dòng)加“/”

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

    禁止htaccess

    1. location ~/\.ht {
    2. deny all;
    3. }

    禁止多個(gè)目錄

    1. location ~ ^/(cron|templates)/ {
    2. deny all;
    3. break;
    4. }

    禁止以/data開頭的文件
    可以禁止/data/下多級目錄下.log.txt等請求;

    1. location ~ ^/data {
    2. deny all;
    3. }

    禁止單個(gè)目錄
    不能禁止.log.txt能請求

    1. location /searchword/cron/ {
    2. deny all;
    3. }

    禁止單個(gè)文件

    1. location ~ /data/sql/data.sql {
    2. deny all;
    3. }

    給favicon.ico和robots.txt設(shè)置過期時(shí)間;
    這里為favicon.ico為99天,robots.txt為7天并不記錄404錯(cuò)誤日志

    1. location ~(favicon.ico) {
    2. log_not_found off;
    3. expires 99d;
    4. break;
    5. }

    6. location ~(robots.txt) {
    7. log_not_found off;
    8. expires 7d;
    9. break;
    10. }

    設(shè)定某個(gè)文件的過期時(shí)間;這里為600秒,并不記錄訪問日志

    1. location ^~ /html/scripts/loadhead_1.js {
    2. access_log   off;
    3. root /opt/lampp/htdocs/web;
    4. expires 600;
    5. break;
    6. }

    文件反盜鏈并設(shè)置過期時(shí)間
    這里的return 412 為自定義的http狀態(tài)碼,默認(rèn)為403,方便找出正確的盜鏈的請求
    “rewrite ^/ http://leech.divmy.com/leech.gif;”顯示一張防盜鏈圖片
    “access_log off;”不記錄訪問日志,減輕壓力
    “expires 3d”所有文件3天的瀏覽器緩存

    1. location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
    2. valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194;
    3. if ($invalid_referer) {
    4. rewrite ^/ http://leech.divmy.com/leech.gif;
    5. return 412;
    6. break;
    7. }
    8. access_log   off;
    9. root /opt/lampp/htdocs/web;
    10. expires 3d;
    11. break;
    12. }

    只充許固定ip訪問網(wǎng)站,并加上密碼

    1. root  /opt/htdocs/www;
    2. allow   208.97.167.194;
    3. allow   222.33.1.2;
    4. allow   231.152.49.4;
    5. deny    all;
    6. auth_basic “C1G_ADMIN”;
    7. auth_basic_user_file htpasswd;

    將多級目錄下的文件轉(zhuǎn)成一個(gè)文件,增強(qiáng)seo效果
    /job-123-456-789.html 指向/job/123/456/789.html

    1. rewrite ^/job-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /job/$1/$2/jobshow_$3.html last;

    將根目錄下某個(gè)文件夾指向2級目錄
    如/shanghaijob/ 指向 /area/shanghai/
    如果你將last改成permanent,那么瀏覽器地址欄顯是/location/shanghai/

    1. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

    上面例子有個(gè)問題是訪問/shanghai 時(shí)將不會(huì)匹配

    1. rewrite ^/([0-9a-z]+)job$ /area/$1/ last;
    2. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

    這樣/shanghai 也可以訪問了,但頁面中的相對鏈接無法使用,
    如./list_1.html真實(shí)地址是/area/shanghia/list_1.html會(huì)變成/list_1.html,導(dǎo)至無法訪問。

    那我加上自動(dòng)跳轉(zhuǎn)也是不行咯
    (-d $request_filename)它有個(gè)條件是必需為真實(shí)目錄,而我的rewrite不是的,所以沒有效果

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

    知道原因后就好辦了,讓我手動(dòng)跳轉(zhuǎn)吧

    1. rewrite ^/([0-9a-z]+)job$ /$1job/ permanent;
    2. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

    文件和目錄不存在的時(shí)候重定向:

    1. if (!-e $request_filename) {
    2. proxy_pass http://127.0.0.1;
    3. }

    域名跳轉(zhuǎn)

    1. server
    2. {
    3. listen       80;
    4. server_name  jump.88dgw.com;
    5. index index.html index.htm index.php;
    6. root  /opt/lampp/htdocs/www;
    7. rewrite ^/ http://www.88dgw.com/;
    8. access_log  off;
    9. }

    多域名轉(zhuǎn)向

    1. server_name  www.7oom.com/  www.divmy.com/;
    2. index index.html index.htm index.php;
    3. root  /opt/lampp/htdocs;
    4. if ($host ~ “c1gstudio\.net”) {
    5. rewrite ^(.*) http://www.7oom.com$1/ permanent;
    6. }

    三級域名跳轉(zhuǎn)

    1. if ($http_host ~* “^(.*)\.i\.c1gstudio\.com$”) {
    2. rewrite ^(.*) http://top.88dgw.com$1/;
    3. break;
    4. }

    域名鏡向

    1. server
    2. {
    3. listen       80;
    4. server_name  mirror.c1gstudio.com;
    5. index index.html index.htm index.php;
    6. root  /opt/lampp/htdocs/www;
    7. rewrite ^/(.*) http://www.divmy.com/$1 last;
    8. access_log  off;
    9. }

    某個(gè)子目錄作鏡向

    1. location ^~ /zhaopinhui {
    2. rewrite ^.+ http://zph.divmy.com/ last;
    3. break;
    4. }

    discuz ucenter home (uchome) rewrite

    1. rewrite ^/(space|network)-(.+)\.html$ /$1.php?rewrite=$2 last;
    2. rewrite ^/(space|network)\.html$ /$1.php last;
    3. rewrite ^/([0-9]+)$ /space.php?uid=$1 last;

    discuz 7 rewrite

    1. rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
    2. rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
    3. rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3 last;
    4. rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
    5. rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;
    6. rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last;

    給discuz某版塊單獨(dú)配置域名

    1. server_name  bbs.c1gstudio.com news.c1gstudio.com;

    2. location = / {
    3. if ($http_host ~ news\.divmy.com$) {
    4. rewrite ^.+ http://news.divmy.com/forum-831-1.html last;
    5. break;
    6. }
    7. }

    discuz ucenter 頭像 rewrite 優(yōu)化

    1. location ^~ /ucenter {
    2. location ~ .*\.php?$
    3. {
    4. #fastcgi_pass  unix:/tmp/php-cgi.sock;
    5. fastcgi_pass  127.0.0.1:9000;
    6. fastcgi_index index.php;
    7. include fcgi.conf;
    8. }

    9. location /ucenter/data/avatar {
    10. log_not_found off;
    11. access_log   off;
    12. location ~ /(.*)_big\.jpg$ {
    13. error_page 404 /ucenter/images/noavatar_big.gif;
    14. }
    15. location ~ /(.*)_middle\.jpg$ {
    16. error_page 404 /ucenter/images/noavatar_middle.gif;
    17. }
    18. location ~ /(.*)_small\.jpg$ {
    19. error_page 404 /ucenter/images/noavatar_small.gif;
    20. }
    21. expires 300;
    22. break;
    23. }
    24. }

    jspace rewrite

    1. location ~ .*\.php?$
    2. {
    3. #fastcgi_pass  unix:/tmp/php-cgi.sock;
    4. fastcgi_pass  127.0.0.1:9000;
    5. fastcgi_index index.php;
    6. include fcgi.conf;
    7. }

    8. location ~* ^/index.php/
    9. {
    10. rewrite ^/index.php/(.*) /index.php?$1 break;
    11. fastcgi_pass  127.0.0.1:9000;
    12. fastcgi_index index.php;
    13. include fcgi.conf;
    14. }

    另外這里還有一個(gè)工具可以直接把a(bǔ)pache規(guī)則轉(zhuǎn)化為nginx規(guī)則

    http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

    參考:

    http://wiki.nginx.org/NginxChsHttpRewriteModule

    http://blog.csdn.net/cnbird2008/archive/2009/08/04/4409620.aspx

    http://www.divmy.com/
    posted @ 2012-07-11 09:47 brock 閱讀(4299) | 評論 (0)編輯 收藏

    memcached如何處理容錯(cuò)的?
    不處理!:) 在memcached節(jié)點(diǎn)失效的情況下,集群沒有必要做任何容錯(cuò)處理。如果發(fā)生了節(jié)點(diǎn)失效,應(yīng)對的措施完全取決于用戶。節(jié)點(diǎn)失效時(shí),下面列出幾種方案供您選擇:
    * 忽略它! 在失效節(jié)點(diǎn)被恢復(fù)或替換之前,還有很多其他節(jié)點(diǎn)可以應(yīng)對節(jié)點(diǎn)失效帶來的影響。
    * 把失效的節(jié)點(diǎn)從節(jié)點(diǎn)列表中移除。做這個(gè)操作千萬要小心!在默認(rèn)情況下(余數(shù)式哈希算法),客戶端添加或移除節(jié)點(diǎn),會(huì)導(dǎo)致所有的緩存數(shù)據(jù)不可用!因?yàn)楣⒄盏墓?jié)點(diǎn)列表變化了,大部分key會(huì)因?yàn)楣V档母淖兌挥成涞剑ㄅc原來)不同的節(jié)點(diǎn)上。
    * 啟動(dòng)熱備節(jié)點(diǎn),接管失效節(jié)點(diǎn)所占用的IP。這樣可以防止哈希紊亂(hashing chaos)。


    同學(xué)們,根據(jù)上面的說法,memcached其中一個(gè)節(jié)點(diǎn)失效以后,memcached本身是沒有任何策略維持失效轉(zhuǎn)發(fā)的,這對于大型系統(tǒng)是一個(gè)無法接受的事實(shí)。

    Memcached分布式每個(gè)服務(wù)器端本身沒有相互相連的關(guān)系,數(shù)據(jù)分布是由客戶端來維持的,也可以說Memcached還沒有為集群提供真的高可用方案,因?yàn)閺募旱亩x上來說需要滿足:1.壓力分載 2.失效轉(zhuǎn)發(fā)。

    在項(xiàng)目組中l(wèi)ianjie.you同學(xué)問我如果在分布式中的其中一臺(tái)Memcached節(jié)點(diǎn)down掉了,應(yīng)該如何解決?我當(dāng)時(shí)愣住了,一時(shí)之間還不能給出任何完整的答案。

    今早在座公車來上班的路上用手機(jī)上網(wǎng)Google了一下,發(fā)現(xiàn)原來在網(wǎng)上有很多人與我們有相同的問題,我Google的關(guān)鍵字是 “Memcached 單點(diǎn)” 、“Memcached 單點(diǎn)故障”。給出的搜索結(jié)果都不算讓人滿意,我才打算寫一篇關(guān)于解決集群中Memcached單點(diǎn)故障的文章。Javabloger只向大家提供2種解決 思路,暫時(shí)不提供具體代碼。

    現(xiàn)象描述:
    在客戶端連接的部分寫入多個(gè)服務(wù)器端的ip地址,客戶端將會(huì)自動(dòng)的把緩存數(shù)據(jù)分布的放在每個(gè)不同的機(jī)器上,如圖所示:

    http://files.note.sdo.com/2011/04/25/5592/4134/1c75/P15SC~jrjKHFnM01o00E0-/17afb85b-7816-4ed7-be59-6cb81f8e7436.png
    查看大圖請點(diǎn)擊這里

    現(xiàn)象后果:
    如果其中一個(gè)緩存節(jié)點(diǎn)的機(jī)器down機(jī),那么客戶端存入的緩存數(shù)據(jù)將會(huì)丟失一部分,就是圖中紅色字體描述的“Losed 33% Cache Data”,也就是說那部分?jǐn)?shù)據(jù)徹底沒有了!如果是用戶的關(guān)鍵性信息那么就玩大了,如圖所示:http://files.note.sdo.com/2011/04/25/5592/4134/1c75/P15SC~jrjKHFnM01o00E0-/3d9a8f33-0715-4522-a4af-4daa2644995d.png
    查看大圖請點(diǎn)擊這里

    解決方案1:本地備份緩存
    在本地放一份緩存,同時(shí)也在分布式Memcached上放一份緩存,如果當(dāng)其中一臺(tái)節(jié)點(diǎn)當(dāng)機(jī)了,客戶端程序直接讀取本地的緩存,本地客戶端維護(hù)一個(gè)HashMap即可,這樣的方案雖然很簡陋,但是可以滿足一部分場景的需要,當(dāng)你很急需的時(shí)候可以作為臨時(shí)方案暫時(shí)替代一下。

    解決方案2:采用緩存代理服務(wù)器
    采用 Magent 緩存代理,防止單點(diǎn)現(xiàn)象,緩存代理也可以做備份,通過客戶端連接到緩存代理服務(wù)器,緩存代理服務(wù)器連接緩存服務(wù)器,緩存代理服務(wù)器可以連接多臺(tái)Memcached機(jī)器可以將每臺(tái)Memcached機(jī)器進(jìn)行數(shù)據(jù)同步。這樣的架構(gòu)比較完善了,如果其中一臺(tái)緩存代理服務(wù)器down機(jī),系統(tǒng)依然可以繼續(xù)工作,如果其中一臺(tái)Memcached機(jī)器down掉,數(shù)據(jù)不會(huì)丟失并且可以保證數(shù)據(jù)的完整性,以上描述的系統(tǒng)架構(gòu)如圖所示:
    http://files.note.sdo.com/2011/04/25/5592/4134/1c75/P15SC~jrjKHFnM01o00E0-/b009274d-77b3-49bb-a921-9953c378965c.png
    查看大圖請點(diǎn)擊這里

    還是那句話:沒有任何架構(gòu)是最完美的,只是最合適的,任何架構(gòu)都不可能一步到位,都是經(jīng)過一步一步演變過來的。

    posted @ 2012-05-07 17:07 brock 閱讀(5289) | 評論 (0)編輯 收藏

    操作步驟:
    sudo vim /home/admin/{app}/conf/tomcat-server.xml
    修改 HTTP/1.1 Connector中的maxPostSize="10000"
    以及AJP 1.3 Connector中的maxPostSize="10000"
    然后
    sudo -u admin cp /home/admin/{app}/conf/tomcat-server.xml /home/admin/{app}/.default/deploy/jboss-web.deployer/server.xml
    下來
    sudo -u admin /home/admin/{app}/bin/jbossctl restart {app}
    最后檢查一下應(yīng)用



    估計(jì)看pdf的人不多, 簡述一下大概意思為:
    常見的服務(wù)器會(huì)將用戶post的數(shù)據(jù)保存在hashmap中. 而向hashmap中插入n對元素的時(shí)間復(fù)雜度大約是O(n), 但如果精心構(gòu)造key使得每個(gè)key的hash值相同(也就是產(chǎn)生了碰撞),則時(shí)間復(fù)雜度會(huì)惡化到O(n^2),導(dǎo)致消耗大量的CPU時(shí)間.
    經(jīng)測試,在tomcat6服務(wù)器上, 總大小2MByte的數(shù)據(jù)就需要消耗一個(gè)i7CPU core44分鐘,也就是6kbit/s就可以讓這個(gè)CPU core一直忙碌. 所以只要一個(gè)G兆網(wǎng)絡(luò)就能讓100000個(gè)i7CPU core一直忙.

    再說下相同hash值key的構(gòu)造:
    在java中,字符串的hash函數(shù)采用DJBX33A,只不過常數(shù)因子改為了31. 這樣的函數(shù)有個(gè)特點(diǎn),即如果字符串X, Y的hash值相同,那么X,Y都添加任意相同的前綴或后綴的以后的hash值也都相同.比如: "rQ"與 "qp"的hash值相同, 則"rQrQ", "rQqp", "qprQ", "qpqp" 這四個(gè)也相同,繼續(xù)這個(gè)模式就可以很容易構(gòu)造出 2^n 個(gè) 2*n長度的不同字符串

    posted @ 2012-01-04 11:11 brock 閱讀(381) | 評論 (0)編輯 收藏

    棧內(nèi)存

    堆內(nèi)存

    基礎(chǔ)類型,對象引用(堆內(nèi)存地址

    由new創(chuàng)建的對象和數(shù)組,

    存取速度快

    相對于棧內(nèi)存較慢

    數(shù)據(jù)大小聲明周期必須確定

    分配的內(nèi)存由java虛擬機(jī)自動(dòng)垃圾回收器管理。動(dòng)態(tài)分配內(nèi)存大小

    共享特性

    棧中如果有字符串,則直接引用

    如果沒有,開辟新的空間存入值

    每new一次在堆內(nèi)存中生成一個(gè)新的對象。

    創(chuàng)建之后值可以改變

    String類聲明后則不可改變    

    一、棧內(nèi)存

    基礎(chǔ)類型int, short, long, byte, float, double, boolean, char和對象引用

    棧的共享特性

    String str1 = "abc";
    String str2 = "abc";
    System.out.println(str1==str2); //true

    1、編譯器先處理String str1 = "abc";它會(huì)在棧中創(chuàng)建一個(gè)變量為str1的引用,然后查找棧中是否有abc這個(gè)值,如果沒找到,就將abc存放進(jìn)來,然后將str1指向abc。

    2、   接著處理String str2 = "abc";在創(chuàng)建完b的引用變量后,因?yàn)樵跅V幸呀?jīng)有abc這個(gè)值,便將str2直接指向abc。這樣,就出現(xiàn)了str1與str2同時(shí)均指向abc的情況。

    二、堆內(nèi)存

    new、newarray、anewarray和multianewarray等指令建立

      要注意: 我們在使用諸如String str = "abc";的格式定義類時(shí),總是想當(dāng)然地認(rèn)為,創(chuàng)建了String類的對象str。擔(dān)心陷阱!對象可能并沒有被創(chuàng)建!而可能只是指向一個(gè)先前已經(jīng)創(chuàng)建的 對象。只有通過new()方法才能保證每次都創(chuàng)建一個(gè)新的對象。 由于String類的immutable性質(zhì),當(dāng)String變量需要經(jīng)常變換其值時(shí),應(yīng)該考慮使用StringBuffer類,以提高程序效率。

    三、  ==   內(nèi)存地址比對

    String str1 = "abc";
    String str2 = "abc";
    System.out.println(str1==str2); //true    str1
    和str2同時(shí)指向 棧內(nèi)存 中同一個(gè)內(nèi)存空間

    String str3 = "abc";
    String str4 = new String("abc") ;

    System.out.println(str3 == str4);    //flase str3值在棧內(nèi)存中,str4值在堆內(nèi)存中

    String hello = "hello" ;

    String hel = "hel" ;

    String lo = "lo" ;

    System.out.println(hello == "hel" + "lo") ; //true

    //兩個(gè)常量相加,先檢測棧內(nèi)存中是否有hello如有有,指向已有的棧中的hello空間

    System.out.println(hello == "hel" + lo) ;   //flase

    System.out.println(hello == hel + lo) ;     //flase

     //lo是在常量池中,不檢查棧內(nèi)存,在堆中產(chǎn)生一個(gè)新的hello

     四、  equals  值進(jìn)行比對

     public boolean equals(Object anObject)

    將此字符串與指定的對象比較。當(dāng)且僅當(dāng)該參數(shù)不為 null,并且是與此對象表示相同字符序列的 String 對象時(shí),結(jié)果才為 true。

     String str5 = "abc";
    String str6 = new String("abc") ;

    System.out.println(str5.equals(str6));    //true   str5的值str6的值比對

     五、  intern    棧中值的內(nèi)存地址

    Public String intern()

    當(dāng)調(diào)用 intern 方法時(shí)

    1、如果池已經(jīng)包含一個(gè)等于此 String 對象的字符串(用equals(Object) 方法確定),則返回池中的字符串。

    2、將此 String 對象添加到池中,并返回此 String 對象的引用。

    String s7 = new String("abc") ;

    String s8 = "abc" ;

    System.out.println(s7 == s7.intern()) ;//flase

    System.out.println(s8 == s7.intern() );//true

    1.檢查棧內(nèi)存中有沒有abc對象如果有

    2.將s7指向pool中abc

    posted @ 2011-03-24 16:58 brock 閱讀(4182) | 評論 (0)編輯 收藏

    這個(gè)手機(jī)號(hào)碼正則驗(yàn)證函數(shù)可以說是最新的都支持的,里面有詳細(xì)的介紹說明,不論以后增加什么號(hào)段大家都非常容易的稍微修改一下即可。
    javascript 手機(jī)號(hào)碼正則表達(dá)式驗(yàn)證函數(shù)

    代碼如下:

    //ip與域名驗(yàn)證函數(shù)
    function checkIP()
    {
    var ipArray,ip,j;
    ip = document.ipform.ip.value;

    if(/[A-Za-z_-]/.test(ip)){
    if (ip.indexOf(" ")>=0){
    ip = ip.replace(/ /g,"");
    document.ipform.ip.value = ip;
    }
    if (ip.toLowerCase().indexOf("http://")==0){
    ip = ip.slice(7);
    document.ipform.ip.value = ip;
    }
    if(!/^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)|(io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp))$/.test(ip)){
    alert("不是正確的域名");
    document.ipform.ip.focus();
    return false;
    }
    }
    else{
    ipArray = ip.split(".");
    j = ipArray.length
    if(j!=4)
    {
    alert("不是正確的IP");
    document.ipform.ip.focus();
    return false;
    }

    for(var i=0;i<4;i++)
    {
    if(ipArray[i].length==0 || ipArray[i]>255)
    {
    alert("不是正確的IP");
    document.ipform.ip.focus();
    return false;
    }
    }
    }
    }
    //手機(jī)號(hào)碼驗(yàn)證函數(shù)
    function checkMobile(){
    var sMobile = document.mobileform.mobile.value
    if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(sMobile))){
    alert("不是完整的11位手機(jī)號(hào)或者正確的手機(jī)號(hào)前七位");
    document.mobileform.mobile.focus();
    return false;
    }
    }
    //郵政編碼驗(yàn)證函數(shù)
    function checkZip(){
    var sZip = document.zipform.zip.value
    if(!(/^\d{4,6}$/.test(sZip))){
    alert("請輸入郵政編碼前4-6位");
    return false;
    }
    }
    //區(qū)號(hào)驗(yàn)證
    function checkZone(){
    var sZone = document.zoneform.zone.value
    if(!(/^0\d{2,6}$/.test(sZone))){
    alert("請輸入以“0”開頭的3-7位區(qū)號(hào)");
    return false;
    }
    }
    //身份證驗(yàn)證
    function checkID(){
    var sID = document.IDform.userid.value
    if(!(/^\d{15}$|^\d{18}$|^\d{17}[xX]$/.test(sID))){
    alert("請輸入15位或18位身份證號(hào)");
    document.IDform.userid.focus();
    return false;
    }

     

    posted @ 2010-12-27 10:11 brock| 編輯 收藏

    public class Sort implements Comparator<TestO> {
        
       
        
    public Sort() {

        }


        
    public int compare(TestO o1, TestO o2) {
            
    if (o1.getB().compareTo(o2.getB()) <0 ||o1.getA().compareTo(o2.getA()) <0{
                
    return -1;
            }
     else if (o1.getB().compareTo(o2.getB()) >0||o1.getA().compareTo(o2.getA()) >0{
                    
    return 1;
            }
     else {
                    
    return 0;
            }

        }

    }

    先排A ,后排B ,,,以B為最優(yōu)先級
    posted @ 2009-12-08 15:40 brock 閱讀(218) | 評論 (0)編輯 收藏

    JAVA_HOME=C:\j2sdk1.4.2_04
    CLASSPATH=.;C:\j2sdk1.4.2_04\lib\tools.jar;C:\j2sdk1.4.2_04\lib\dt.jar;C:\j2sdk1.4.2_04

    \bin;
    path=C:\j2sdk1.4.2_04\bin;

    posted @ 2009-10-15 09:36 brock 閱讀(244) | 評論 (0)編輯 收藏

    接口編程

     classpath :實(shí)現(xiàn) ModuleInterface 接口的實(shí)現(xiàn)類 
    // 獲得對象的所有屬性   
    Class cl = Class.forName(classpath) ;
            Object object
    = cl.getConstructor(new Class[] {})   
            .newInstance(
    new Object[] {}); 
    //轉(zhuǎn)型成接口

            ModuleInterface  utilConfig
    = (ModuleInterface )object;


         

    posted @ 2009-08-26 12:22 brock 閱讀(212) | 評論 (0)編輯 收藏

    僅列出標(biāo)題
    共15頁: First 上一頁 2 3 4 5 6 7 8 9 10 下一頁 Last 
    主站蜘蛛池模板: 久久久久亚洲精品成人网小说| 妞干网在线免费观看| 99re6热视频精品免费观看| 国产精品免费大片| 特级无码毛片免费视频尤物| 日本高清免费观看| 免费国产黄网站在线观看| 久久成人免费大片| 91福利免费视频| 四虎永久在线精品免费网址| 女人被男人躁的女爽免费视频| 午夜高清免费在线观看| 国产色婷婷精品免费视频| 免费一看一级毛片| 三上悠亚亚洲一区高清| 亚洲AV永久精品爱情岛论坛| 亚洲一区二区中文| 亚洲va乱码一区二区三区| 亚洲中文字幕无码中文| 精品视频免费在线| 三上悠亚在线观看免费| 未满十八18禁止免费无码网站| 妻子5免费完整高清电视| 在线免费观看一级毛片| 亚洲AV永久无码精品一区二区国产| 久久久久亚洲爆乳少妇无| 久久精品亚洲综合专区| 亚洲国产精品成人综合色在线婷婷| 亚洲综合激情五月色一区| 美美女高清毛片视频黄的一免费| 国产精品免费在线播放| 99爱在线观看免费完整版| 好吊妞998视频免费观看在线| 免费人成网站7777视频| 亚洲成a人片77777kkkk| 激情综合亚洲色婷婷五月| 特黄特色大片免费| 一区二区免费视频| 日本一道高清不卡免费| 亚洲级αV无码毛片久久精品| 亚洲国产综合精品|