欧洲一级在线观看,超碰在线影院,国产精品爱久久久久久久http://www.aygfsteel.com/askcuix/category/32218.htmlKeep Walking......zh-cnMon, 07 Mar 2011 20:55:26 GMTMon, 07 Mar 2011 20:55:26 GMT60SAXParseException: Content is not allowed in prologhttp://www.aygfsteel.com/askcuix/archive/2011/03/07/345896.htmlChris.CuiChris.CuiMon, 07 Mar 2011 10:39:00 GMThttp://www.aygfsteel.com/askcuix/archive/2011/03/07/345896.htmlhttp://www.aygfsteel.com/askcuix/comments/345896.htmlhttp://www.aygfsteel.com/askcuix/archive/2011/03/07/345896.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/345896.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/345896.html
出現這種問題,有幾種可能性:  閱讀全文

Chris.Cui 2011-03-07 18:39 發表評論
]]>
使用ARA實現GlassFish中Web應用的資源分配http://www.aygfsteel.com/askcuix/archive/2010/04/23/319210.htmlChris.CuiChris.CuiFri, 23 Apr 2010 09:55:00 GMThttp://www.aygfsteel.com/askcuix/archive/2010/04/23/319210.htmlhttp://www.aygfsteel.com/askcuix/comments/319210.htmlhttp://www.aygfsteel.com/askcuix/archive/2010/04/23/319210.html#Feedback2http://www.aygfsteel.com/askcuix/comments/commentRss/319210.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/319210.html閱讀全文

Chris.Cui 2010-04-23 17:55 發表評論
]]>
GlassFish移植Tipshttp://www.aygfsteel.com/askcuix/archive/2010/03/23/316339.htmlChris.CuiChris.CuiTue, 23 Mar 2010 09:30:00 GMThttp://www.aygfsteel.com/askcuix/archive/2010/03/23/316339.htmlhttp://www.aygfsteel.com/askcuix/comments/316339.htmlhttp://www.aygfsteel.com/askcuix/archive/2010/03/23/316339.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/316339.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/316339.html閱讀全文

Chris.Cui 2010-03-23 17:30 發表評論
]]>
GlassFish Componentshttp://www.aygfsteel.com/askcuix/archive/2009/12/21/306820.htmlChris.CuiChris.CuiMon, 21 Dec 2009 08:40:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/12/21/306820.htmlhttp://www.aygfsteel.com/askcuix/comments/306820.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/12/21/306820.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/306820.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/306820.html閱讀全文

Chris.Cui 2009-12-21 16:40 發表評論
]]>
StartUp Choice: ServletContextListener vs Servlethttp://www.aygfsteel.com/askcuix/archive/2009/11/03/300894.htmlChris.CuiChris.CuiTue, 03 Nov 2009 06:46:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/11/03/300894.htmlhttp://www.aygfsteel.com/askcuix/comments/300894.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/11/03/300894.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/300894.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/300894.html閱讀全文

Chris.Cui 2009-11-03 14:46 發表評論
]]>
GlassFish安裝指南http://www.aygfsteel.com/askcuix/archive/2009/10/27/299921.htmlChris.CuiChris.CuiTue, 27 Oct 2009 07:18:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/10/27/299921.htmlhttp://www.aygfsteel.com/askcuix/comments/299921.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/10/27/299921.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/299921.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/299921.html閱讀全文

Chris.Cui 2009-10-27 15:18 發表評論
]]>
Spring延遲加載EJB代理http://www.aygfsteel.com/askcuix/archive/2009/09/07/294205.htmlChris.CuiChris.CuiMon, 07 Sep 2009 10:02:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/09/07/294205.htmlhttp://www.aygfsteel.com/askcuix/comments/294205.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/09/07/294205.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/294205.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/294205.html閱讀全文

Chris.Cui 2009-09-07 18:02 發表評論
]]>
JMS - 異步消息的使者http://www.aygfsteel.com/askcuix/archive/2009/08/06/290012.htmlChris.CuiChris.CuiWed, 05 Aug 2009 16:35:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/08/06/290012.htmlhttp://www.aygfsteel.com/askcuix/comments/290012.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/08/06/290012.html#Feedback1http://www.aygfsteel.com/askcuix/comments/commentRss/290012.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/290012.html閱讀全文

Chris.Cui 2009-08-06 00:35 發表評論
]]>
Standalone Client Lookup JNDI from the GlassFishhttp://www.aygfsteel.com/askcuix/archive/2009/07/30/288985.htmlChris.CuiChris.CuiWed, 29 Jul 2009 16:27:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/07/30/288985.htmlhttp://www.aygfsteel.com/askcuix/comments/288985.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/07/30/288985.html#Feedback2http://www.aygfsteel.com/askcuix/comments/commentRss/288985.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/288985.html閱讀全文

Chris.Cui 2009-07-30 00:27 發表評論
]]>
Weblogic中獲取Server信息http://www.aygfsteel.com/askcuix/archive/2009/06/23/283707.htmlChris.CuiChris.CuiTue, 23 Jun 2009 03:12:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/06/23/283707.htmlhttp://www.aygfsteel.com/askcuix/comments/283707.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/06/23/283707.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/283707.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/283707.html閱讀全文

Chris.Cui 2009-06-23 11:12 發表評論
]]>
SLF4J+logBack, 日志領域中的新秀http://www.aygfsteel.com/askcuix/archive/2009/03/14/259697.htmlChris.CuiChris.CuiSat, 14 Mar 2009 04:13:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/03/14/259697.htmlhttp://www.aygfsteel.com/askcuix/comments/259697.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/03/14/259697.html#Feedback5http://www.aygfsteel.com/askcuix/comments/commentRss/259697.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/259697.html閱讀全文

Chris.Cui 2009-03-14 12:13 發表評論
]]>
Checkstyle的配置詳解http://www.aygfsteel.com/askcuix/archive/2009/02/08/253775.htmlChris.CuiChris.CuiSun, 08 Feb 2009 04:47:00 GMThttp://www.aygfsteel.com/askcuix/archive/2009/02/08/253775.htmlhttp://www.aygfsteel.com/askcuix/comments/253775.htmlhttp://www.aygfsteel.com/askcuix/archive/2009/02/08/253775.html#Feedback3http://www.aygfsteel.com/askcuix/comments/commentRss/253775.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/253775.html Checkstyle可以讓我們養成書寫良好代碼風格的習慣,代碼的整潔也減少了很多bad smell的產生。使用checkstyle的過程中可能需要經常的調整配置文件,有些check過于嚴格,可以根據實際情況取消一些代碼檢查。  閱讀全文

Chris.Cui 2009-02-08 12:47 發表評論
]]>
利用JPDA進行Remote Debughttp://www.aygfsteel.com/askcuix/archive/2008/11/09/239529.htmlChris.CuiChris.CuiSun, 09 Nov 2008 09:10:00 GMThttp://www.aygfsteel.com/askcuix/archive/2008/11/09/239529.htmlhttp://www.aygfsteel.com/askcuix/comments/239529.htmlhttp://www.aygfsteel.com/askcuix/archive/2008/11/09/239529.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/239529.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/239529.html閱讀全文

Chris.Cui 2008-11-09 17:10 發表評論
]]>
HttpClient之上傳文件http://www.aygfsteel.com/askcuix/archive/2008/06/21/209731.htmlChris.CuiChris.CuiSat, 21 Jun 2008 14:43:00 GMThttp://www.aygfsteel.com/askcuix/archive/2008/06/21/209731.htmlhttp://www.aygfsteel.com/askcuix/comments/209731.htmlhttp://www.aygfsteel.com/askcuix/archive/2008/06/21/209731.html#Feedback3http://www.aygfsteel.com/askcuix/comments/commentRss/209731.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/209731.html
 1   File f1 = new File("D:\\download\\aa.txt");
 2   PostMethod filePost = new PostMethod("http://10.3.3.106:8090/~jid=aWHLXB6y4O9a/webdrive/upload.do?contentID=99999820&action=submit");
 3   try{
 4       Part[] parts = {new FilePart("file0", f1)};
 5       filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
 6   }catch(FileNotFoundException e){
 7       System.out.println("===================file not found exception: " + e);
 8   }
 9   HttpClient client = new HttpClient();
10   // 若上傳的文件比較大 , 可在此設置最大的連接超時時間 
11   //client.getHttpConnectionManager(). getParams().setConnectionTimeout(5000); 
12   int status = 0;
13   try {
14       
15        status = client.executeMethod(filePost);
16                
17   } catch (HttpException e) {
18        System.out.println("===================http exception: " + e);
19   } catch (IOException e) {
20        System.out.println("===================io exception: " + e);
21   }finally {
22        filePost.releaseConnection();
23   }
24   if (status == HttpStatus.SC_OK) {
25       System.out.println("============================UpLoad file OK! ");
26   } 

     本來URL中的contentID和action兩個參數我是通過StringPart來傳遞的,結果傳遞上去的值就成了:
     action=
Content-Transfer-Encoding: 8bit
     submit
     而且目前這種方法上傳的文件,也會在文件內容的第一行中出現:Content-Transfer-Encoding: 8bit,由于不影響測試的效果,所以就擱置了,等有空時再來研究這個問題,如果有朋友知道問題的原因,也請一定不要吝嗇您的回答哦。

Chris.Cui 2008-06-21 22:43 發表評論
]]>
HttpClient的一些技巧http://www.aygfsteel.com/askcuix/archive/2008/06/20/209549.htmlChris.CuiChris.CuiFri, 20 Jun 2008 13:37:00 GMThttp://www.aygfsteel.com/askcuix/archive/2008/06/20/209549.htmlhttp://www.aygfsteel.com/askcuix/comments/209549.htmlhttp://www.aygfsteel.com/askcuix/archive/2008/06/20/209549.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/209549.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/209549.html
一、字符編碼
    某目標頁的編碼可能出現在兩個地方,第一個地方是服務器返回的 http 頭中,另外一個地方是得到的 html/xml 頁面中。
    1、在 http 頭的 Content-Type 字段可能會包含字符編碼信息。
      例如可能返回的頭會包含這樣子的信息:Content-Type: text/html; charset=UTF-8。這個頭信息表明該頁的編碼是UTF-8,但是服務器返回的頭信息未必與內容能匹配上。比如對于一些雙字節語言國家,可能服務器返回的編碼類型是UTF-8,但真正的內容卻不是UTF-8編碼的,因此需要在另外的地方去得到頁面的編碼信息;但是如果服務器返回的編碼不是UTF-8,而是具體的一些編碼,比如gb2312等,那服務器返回的可能是正確的編碼信息。通過method對象的getResponseCharSet()方法就可以得到http頭中的編碼信息。
    2、對于象xml或者html這樣的文件,允許在頁面中直接指定編碼類型。比如在html中會有<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>這樣的標簽;或者在xml中會有<?xml version="1.0" encoding="gb2312"?>這樣的標簽,在這些情況下,可能與http頭中返回的編碼信息沖突,需要用戶自己判斷到底那種編碼類型應該是真正的編碼。

二、自動轉向
    根據RFC中對自動轉向的定義,主要有兩種:301和302。301表示永久的移走(Moved Permanently),當返回的是301,則表示請求的資源已經被移到一個固定的新地方,任何向該地址發起請求都會被轉到新的地址上。302表示暫時的轉向,比如在服務器端的servlet程序調用了sendRedirect方法,則在客戶端就會得到一個302的代碼,這時服務器返回的頭信息中location的值就是sendRedirect轉向的目標地址。
HttpClient支持自動轉向處理,但是象POST和PUT方式這種要求接受后繼服務的請求方式,暫時不支持自動轉向,因此如果碰到POST方式提交后返回的是301或者302的話需要自己處理。需要注意的是,有時候location返回的可能是相對路徑,因此需要對location返回的值做一些處理才可以發起向新地址的請求。
    另外除了在頭中包含的信息可能使頁面發生重定向外,在頁面中也有可能會發生頁面的重定向。引起頁面自動轉發的標簽是:<meta http-equiv="refresh" content="5; url=http://www.ibm.com/">。如果你想在程序中也處理這種情況的話得自己分析頁面來實現轉向。需要注意的是,在上面那個標簽中url的值也可以是一個相對地址,如果是這樣的話,需要對它做一些處理后才可以轉發。

三、代理服務器
    HttpClient中使用代理服務器非常簡單,調用HttpClient中setProxy方法就可以,方法的第一個參數是代理服務器地址,第二個參數是端口號。另外HttpClient也支持SOCKS代理。

    httpClient.getHostConfiguration().setProxy(hostName,port);

    HttpClient對http協議的支持非常好,使用起來很簡單,功能也很強大,具有足夠的靈活性和擴展性。對于想在Java應用中直接訪問http資源的編程人員來說,HttpClient是一個不可多得的好工具。

Chris.Cui 2008-06-20 21:37 發表評論
]]>
HttpClient基本功能的使用http://www.aygfsteel.com/askcuix/archive/2008/06/20/209547.htmlChris.CuiChris.CuiFri, 20 Jun 2008 13:26:00 GMThttp://www.aygfsteel.com/askcuix/archive/2008/06/20/209547.htmlhttp://www.aygfsteel.com/askcuix/comments/209547.htmlhttp://www.aygfsteel.com/askcuix/archive/2008/06/20/209547.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/209547.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/209547.html     使用 HttpClient 需要以下 6 個步驟:
    1. 創建 HttpClient 的實例
    2. 創建某種連接方法的實例,在這里是 GetMethod。在 GetMethod 的構造函數中傳入待連接的地址
    3. 調用第一步中創建好的實例的 execute 方法來執行第二步中創建好的 method 實例
    4. 讀 response
    5. 釋放連接。無論執行方法是否成功,都必須釋放連接
    6. 對得到后的內容進行處理

    根據以上步驟,我們來編寫用GET方法取得某網頁內容的代碼。
    1、大部分情況下 HttpClient 默認的構造函數已經足夠使用。
 
       HttpClient httpClient = new HttpClient();

    2、創建GET方法的實例。
      在GET方法的構造函數中傳入待連接的地址即可。用GetMethod將會自動處理轉發過程,如果想要把自動處理轉發過程去掉的話,可以調用方法setFollowRedirects(false)。
     
      GetMethod getMethod = new GetMethod("http://www.ibm.com/");

    3、調用 httpClient 的 executeMethod 方法來執行 getMethod。
      由于是執行在網絡上的程序,在運行executeMethod方法的時候,需要處理兩個異常,分別是HttpException和IOException。引起第一種異常的原因主要可能是在構造getMethod的時候傳入的協議不對,比如將"http"寫成了"htp",或者服務器端返回的內容不正常等,并且該異常發生是不可恢復的;第二種異常一般是由于網絡原因引起的異常,對于這種異常(IOException),HttpClient會根據你指定的恢復策略自動試著重新執行executeMethod方法。HttpClient的恢復 策略可以自定義(通過實現接口HttpMethodRetryHandler來實現)。通過httpClient的方法setParameter設置你實現的恢復策略,本例中使用的是系統提供的默認恢復策略,該策略在碰到第二類異常的時候將自動重試3次。executeMethod返回值是一個整數,表示了執行該方法后服務器返回的狀態碼,該狀態碼能表示出該方法執行是否成功、需要認證或者頁面發生了跳轉(默認狀態下GetMethod的實例是自動處理跳轉的)等。

     //設置成了默認的恢復策略,在發生異常時候將自動重試3次,在這里你也可以設置成自定義的恢復策略
     getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                                              
new DefaultHttpMethodRetryHandler());
     //執行getMethod
     int statusCode = client.executeMethod(getMethod);
     if (statusCode != HttpStatus.SC_OK) {
          System.err.println(
"Method failed: " + getMethod.getStatusLine());
     }

    4、在返回的狀態碼正確后,即可取得內容。
      取得目標地址的內容有三種方法:
      Ⅰ、getResponseBody,該方法返回的是目標的二進制的byte流;
      Ⅱ、getResponseBodyAsString,這個方法返回的是String類型,值得注意的是該方法返回的String的編碼是根據系統默認的編碼方式,所以返回的String值可能編碼類型有誤;
      Ⅲ、getResponseBodyAsStream,這個方法對于目標地址中有大量數據需要傳輸是最佳的。
      在這里我們使用了最簡單的 getResponseBody方法。

       byte[] responseBody = method.getResponseBody();

    5、釋放連接。
       無論執行方法是否成功,都必須釋放連接。
     
       method.releaseConnection();

    6、處理內容。
      在這一步中根據你的需要處理內容,本例中只是簡單的將內容打印到控制臺。
     
       System.out.println(new String(responseBody));

    下面是程序的完整代碼:
 1   package test;
 2   import java.io.IOException;
 3   import org.apache.commons.httpclient.*;
 4   import org.apache.commons.httpclient.methods.GetMethod;
 5   import org.apache.commons.httpclient.params.HttpMethodParams;
 6   public class GetSample{
 7      public static void main(String[] args) {
 8         //構造HttpClient的實例
 9         HttpClient httpClient = new HttpClient();
10         //創建GET方法的實例
11         GetMethod getMethod = new GetMethod("http://www.ibm.com");
12         //使用系統提供的默認的恢復策略
13         getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
14                                                  new DefaultHttpMethodRetryHandler());
15         try {
16           //執行getMethod
17           int statusCode = httpClient.executeMethod(getMethod);
18           if (statusCode != HttpStatus.SC_OK) {
19               System.err.println("Method failed: "
20                                         + getMethod.getStatusLine());
21           }
22            //讀取內容
23            byte[] responseBody = getMethod.getResponseBody();
24            //處理內容
25            System.out.println(new String(responseBody));
26         } catch (HttpException e) {
27            //發生致命的異常,可能是協議不對或者返回的內容有問題
28            System.out.println("Please check your provided http address!");
29            e.printStackTrace();
30         } catch (IOException e) {
31            //發生網絡異常
32            e.printStackTrace();
33         } finally {
34            //釋放連接
35            getMethod.releaseConnection();
36         }
37       }
38    }

二、POST方法
    POST 方法用來向目的服務器發出請求,要求它接受被附在請求后的實體,并把它當作請求隊列(Request-Line)中請求URI所指定資源的附加新子項。
    調用 HttpClient 中的 PostMethod 與 GetMethod 類似,除了設置 PostMethod 的實例與 GetMethod 有些不同之外,剩下的步驟都差不多。在下面的例子中,省去了與GetMethod相同的步驟,只說明與上面不同的地方。
    構造 PostMethod 之前的步驟都相同,與 GetMethod 一樣,構造 PostMethod 也需要一個URI參數,在創建了PostMethod的實例之后,需要給method實例填充表單的值,一般的登錄表單中需要有兩個域,第一個是用戶名,第二個是密碼。表單中的域用類 NameValuePair 來表示,該類的構造函數第一個參數是表單域名名稱,第二參數是該域的值;將表單所有的值設置到 PostMethod 中用方法 setRequestBody。如果登錄成功后會轉向另外一個頁面,HttpClient對于要求接受后繼服務的請求,比如POST和PUT,不支持自動轉發,因此需要自己對頁面轉向做處理。
    代碼如下:
 1  String url = "http://www.test.com/login.jsp";
 2  PostMethod postMethod = new PostMethod(url);
 3  // 填入各個表單域的值
 4  NameValuePair[] data = { new NameValuePair("id""youUserName"),                
 5                           new NameValuePair("passwd""yourPwd") };
 6  // 將表單的值放入postMethod中
 7  postMethod.setRequestBody(data);
 8  // 執行postMethod
 9  int statusCode = httpClient.executeMethod(postMethod);
10  // HttpClient對于要求接受后繼服務的請求,象POST和PUT等不能自動處理轉發
11  // 301或者302
12  if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY ||
13                       statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
14      // 從頭中取出轉向的地址
15      Header locationHeader = postMethod.getResponseHeader("location");
16      String location = null;
17      if (locationHeader != null) {
18         location = locationHeader.getValue();
19         System.out.println("The page was redirected to:" + location);
20      } else {
21         System.err.println("Location field value is null.");
22      }
23      return;
24  }




Chris.Cui 2008-06-20 21:26 發表評論
]]>
HttpClient簡介http://www.aygfsteel.com/askcuix/archive/2008/06/20/209538.htmlChris.CuiChris.CuiFri, 20 Jun 2008 12:52:00 GMThttp://www.aygfsteel.com/askcuix/archive/2008/06/20/209538.htmlhttp://www.aygfsteel.com/askcuix/comments/209538.htmlhttp://www.aygfsteel.com/askcuix/archive/2008/06/20/209538.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/209538.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/209538.html     HttpClient 是 Apache Jakarta Common 下的子項目,用來提供高效的、最新的、功能豐富的支持 HTTP 協議的客戶端編程工具包,該項目就是專門設計來簡化 HTTP 客戶端與服務器進行各種通訊編程,通過它,可以讓原來很頭疼的事情現在輕松的解決。

    HttpClient 功能介紹:
    以下列出的是 HttpClient 提供的主要的功能,
  • 實現了所有 HTTP 的方法(GET,POST,PUT,HEAD 等)
  • 支持自動轉向
  • 支持 HTTPS 協議
  • 支持代理服務器等



Chris.Cui 2008-06-20 20:52 發表評論
]]>
memcached安裝http://www.aygfsteel.com/askcuix/archive/2008/05/20/208304.htmlChris.CuiChris.CuiTue, 20 May 2008 08:40:00 GMThttp://www.aygfsteel.com/askcuix/archive/2008/05/20/208304.htmlhttp://www.aygfsteel.com/askcuix/comments/208304.htmlhttp://www.aygfsteel.com/askcuix/archive/2008/05/20/208304.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/208304.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/208304.html1、下載, memcached需要先安裝libevent
   memcached的下載地址:http://danga.com/memcached/download.bml
   libevent的下載地址 :http://www.monkey.org/~provos/libevent/

2、安裝libevent

# tar xvf libevent-1.4.4-stable.tar.gz     
#
 cd libevent-1.4.4-stable    
#
 ./configure --prefix= /opt/cuix/3rdParty/libevent-1.4.4    
#
 make    
#
 make install

   檢查是否安裝成功:

#cd /opt/cuix/3rdParty/libevent-1.4.4/lib

   如果有:
   libevent-1.4.so.2 
   libevent-1.4.so.2.0.0 
   libevent.a 
   libevent.la 
   libevent.so
   這幾個文件存在,說明安裝成功。

3、安裝memcached
   

# tar xvf memcached-1.2.5.tar.gz     
#
 cd memcached-1.2.5   
#
 ./configure --with-libevent=/opt/cuix/3rdParty/libevent-1.4.4 
         --prefix=/opt/cuix/3rdParty/memcached-1.2.5    
# make    
#
 make install

   
   檢查是否安裝成功:

# cd 3rdParty/memcached-1.2.5/bin

   如果memcached 和memcached-debug這2個文件存在,說明安裝成功

4、執行

# cd /opt/cuix/3rdParty/memcached-1.2.5/bin    
#
 ./memcached -h

 
   如果出現:
  

memcached 1.2.5
   -p <num>      TCP port number to listen on (default: 
11211)
   -U <num>      UDP port number to listen on (default: 
0, off)
   -s <file>     unix socket path to listen on (disables network support)
   -a <mask>     access mask for unix socket
, in octal (default 0700)
   -l <ip_addr>  interface to listen on
, default is INDRR_ANY
   -d            run as a daemon
   -r            maximize core file limit
   -u <username> assume identity of <username> (only when run as root)
   -m <num>      max memory to use for items in megabytes
, default is 64 MB
   -M            return error on memory exhausted (rather than removing items)
   -c <num>      max simultaneous connections
, default is 1024
   -k            lock down all paged memory.  Note that there is a
                 limit on how much memory you may lock.  Trying to
                 allocate more than that would fail
, so be sure you
                 set the limit correctly for the user you started
                 the daemon with (not for -u <username> user
;
                 under sh this is done with 'ulimit -S -l NUM_KB').
   -v            verbose (print errors/warnings while in event loop)
   -vv           very verbose (also print client commands/reponses)
   -h            print this help and exit
   -i            print memcached and libevent license
   -b            run a managed instanced (mnemonic: buckets)
   -P <file>     save PID in <file>
, only used with -d option
   -f <factor>   chunk size growth factor
, default 1.25
   -n <bytes>    minimum space allocated for key+value+flags
, default 48 

    說明安裝成功,并且路徑配置正確。
   有可能會出現:

memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

   說明沒有找到文件:libevent-1.4.so.2

   解決辦法:
   將libevent-1.4.so.2拷貝到任何一個列出的lib下或者軟鏈接就可以了。
   或者 修改.profile文件。加入:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/opt/cuix/3rdParty/libevent-1.4.4/lib 

  
   啟動服務:

./memcached --10 -u cuix -10.3.2.36 -18887 -256 -/tmp/memcached.pid

   
   參數說明:
    -d選項是啟動一個守護進程
    -m是分配給Memcache使用的內存數量,單位是MB,我這里是10MB
    -u是運行Memcache的用戶,我這里是root
    -l是監聽的服務器IP地址
    -p是設置Memcache監聽的端口,最好是1024以上的端口
    -c選項是最大運行的并發連接數,默認是1024,按照你服務器的負載量來設定
    -P是設置保存Memcache的pid文件

    停止服務:
    用# ps -e 查看進程,# kill pid memcached的進程號。



Chris.Cui 2008-05-20 16:40 發表評論
]]>
memcached概述http://www.aygfsteel.com/askcuix/archive/2008/05/18/208301.htmlChris.CuiChris.CuiSun, 18 May 2008 10:15:00 GMThttp://www.aygfsteel.com/askcuix/archive/2008/05/18/208301.htmlhttp://www.aygfsteel.com/askcuix/comments/208301.htmlhttp://www.aygfsteel.com/askcuix/archive/2008/05/18/208301.html#Feedback0http://www.aygfsteel.com/askcuix/comments/commentRss/208301.htmlhttp://www.aygfsteel.com/askcuix/services/trackbacks/208301.html
      首先啟動一個memcached監護進程,監護進程不需要配置文件,只要在命令行里面加三四個參數就可以了:
        # ./memcached -d -m 2048 -l 10.0.0.40 -p 11211
      這里指定使用2GB內存,監聽10.0.0.40的11211端口來啟動memcached。因為32位處理器最多只能有4GB的地址空間。如果你確實需要32位的服務器處理4-64GB的內存(使用PAE),則每個使用2-3GB內存。
   
      數據庫為了在關系數據庫管理系統上實現ACID,使用了鎖,導致很多讀寫阻塞。而memcached從不會阻塞。首先使用緩存的很多用戶都是用于WEB。這意味著要分配時間出來做多請求處理給不同的系統,如mod_perl、PHP等等,這是對全局緩存的一種浪費。如果你使用多線程語言和共享內存API,如IPC::Shareable,你的每個線程都擁有獨立的緩存。這個也是共享內存的局限性。
   
      memcached服務器和客戶端實現了全局緩存。實際上,很推薦你在同一臺機器上同時運行WEB結點和memcached結點。這會節省一點網絡開銷,非常快,它使用 libevent 來處理任意數量的連接。在Linux上,盡可能使用 epoll 來實現。使用非阻塞的網絡IO和計算,所以對象在不同的客戶端上可能有不同的狀態。還使用內置的內存塊分配和哈希表算法,確保虛擬內存不會過來搗亂。
   
    你可能感興趣用戶是否會獲取一個過期的值。服務器API只有一種獲取數據的方法,并有3種提交數據的方法:
     * set 無條件的設置指定的鍵為給定的值。
     * add 添加到緩存,如果不存在。
     * replace 當存在已有值時,替換一下。
    另外,這3個函數都可以設置過期時間。

Chris.Cui 2008-05-18 18:15 發表評論
]]>
主站蜘蛛池模板: 蕲春县| 缙云县| 四子王旗| 治多县| 乌鲁木齐市| 格尔木市| 惠安县| 吉木乃县| 保康县| 清河县| 濮阳市| 当雄县| 萨迦县| 兴化市| 基隆市| 阿克苏市| 前郭尔| 合江县| 平远县| 永安市| 呼伦贝尔市| 富源县| 洛阳市| 吉水县| 唐山市| 遂宁市| 诏安县| 礼泉县| 隆昌县| 宝坻区| 红原县| 临泉县| 巫山县| 松原市| 大冶市| 陆良县| 疏附县| 本溪市| 于都县| 清丰县| 文山县|