亚洲韩日午夜视频,欧美日韩在线精品一区二区三区,韩国超清无码一区二区三区,亚洲国产成人影院播放,久草新在线,在线看片AV色

您好,歡迎來到思海網(wǎng)絡(luò),我們將竭誠為您提供優(yōu)質(zhì)的服務(wù)! 誠征網(wǎng)絡(luò)推廣 | 網(wǎng)站備案 | 幫助中心 | 軟件下載 | 購買流程 | 付款方式 | 聯(lián)系我們 [ 會員登錄/注冊 ]
促銷推廣
客服中心
業(yè)務(wù)咨詢
有事點擊這里…  531199185
有事點擊這里…  61352289
點擊這里給我發(fā)消息  81721488
有事點擊這里…  376585780
有事點擊這里…  872642803
有事點擊這里…  459248018
有事點擊這里…  61352288
有事點擊這里…  380791050
技術(shù)支持
有事點擊這里…  714236853
有事點擊這里…  719304487
有事點擊這里…  1208894568
有事點擊這里…  61352289
在線客服
有事點擊這里…  531199185
有事點擊這里…  61352288
有事點擊這里…  983054746
有事點擊這里…  893984210
當(dāng)前位置:首頁 >> 技術(shù)文章 >> 文章瀏覽
技術(shù)文章

NoSQL數(shù)據(jù)庫Apache Cassandra的配置

添加時間:2011-3-12  添加: admin 

在這里我們將介紹的是NoSQL數(shù)據(jù)庫Apache Cassandra的配置與相關(guān)問題。現(xiàn)在數(shù)據(jù)庫市場對于NoSQL的關(guān)注度日益升高,我們也該看到未來數(shù)據(jù)庫技術(shù)的變革。

上次說了安裝的問題,可以參考《VirtualBox 虛擬機(jī) Debian系統(tǒng)上安裝Cassandra步驟及遇到的問題》。當(dāng)然,在windows下也可以使用,但是要設(shè)置JAVA_HOME參數(shù),然后啟動目錄bin里的cassandra.bat。編輯cassandra.bat看到

  1. if NOT DEFINED CASSANDRA_HOME set CASSANDRA_HOME=%CD% 

改成

  1. if NOT DEFINED CASSANDRA_HOME set CASSANDRA_HOME=F:\apache-cassandra-0.5.1 

“F:\apache-cassandra-0.5.1”是我的安裝目錄。

一、cassandra的單節(jié)點服務(wù)器配置

先說下cassandra的配置,還是講Linux下的。需要配置的文件一共有三個,當(dāng)然,也可以使用默認(rèn)配置。

這個三個文件分別是:

bin/cassandra.in.sh

conf/log4j.properties

conf/storage-conf.xml

其中,log4j.properties是日志的配置,其它兩個是配置的運行環(huán)境。

cassandra.in.sh文件一般不需要調(diào)整,當(dāng)然,加入你沒有使用alternatives調(diào)整java的默認(rèn)環(huán)境,而你又需要使用jre6.0,這種情況下,可以設(shè)置cassandra.in.sh中

 

  1. #JAVA_HOME=/usr/local/jdk6 

JAVA_HOME=/usr/local/jre6   #這里是你的jre解壓縮的路徑

log4j.properties的配置網(wǎng)上講的很多,就不說了。

storage-conf.xml的配置是最重要的。

第一個是Keyspaces,這個默認(rèn)只設(shè)置了Keyspace1,可以增加另外的Keyspaces。客戶端調(diào)用需要使用這個名字。

Keyspace節(jié)點中的KeysCachedFraction設(shè)置的鍵索引的內(nèi)存大小。說明上也寫了,假如鍵的數(shù)量較少,長度較長,可以增加這個值。而設(shè)置為0,則是禁用。

接下來是設(shè)置ColumnFamily,這里配置的名稱,在客戶端調(diào)用時候也要是有。另外還指定了列的類型。

ReplicationFactor設(shè)置了副本的數(shù)目,這個是在分布式部署中有用,保持?jǐn)?shù)據(jù)的冗余,以至于某幾臺服務(wù)壞掉,能保證數(shù)據(jù)完整。

CommitLogDirectory以及接下來的幾行都是設(shè)置目錄的,這個就不說了。

Seeds也是和分部署主從服務(wù)器部署方式有關(guān)的,本文不準(zhǔn)備講這個。

ThriftAddress是比較重要的,這個是設(shè)置客戶端訪問的,而ThriftPort是設(shè)置訪問的端口。接下來的部分是和性能有關(guān)的,這些說明可以仔細(xì)閱讀。貧道對下面的設(shè)置也理解不深入,就不獻(xiàn)丑了。

二、如何編程訪問cassandra

從http://incubator.apache.org/cassandra/找了好久,找到了http://github.com/rantav/hector  (java)。這個是一個訪問cassandra的包裝。很遺憾的是,我使用這個包裝訪問時候,讀取一個Key的值需要7~8秒!!!暈倒。我開始以為是虛擬機(jī)的原因,結(jié)果部署到其他兩臺linux服務(wù)器上還是一樣。當(dāng)然這些機(jī)器和我的機(jī)器都不在同一個網(wǎng)段,我不知道這點是不是會對性能有很大的影響。后來,我放到自己機(jī)器上,以及把寫好的程序當(dāng)?shù)滥繕?biāo)機(jī)器上,讀取速度變成了20MS每條。性能相差也太大了。一個是速度慢得和螞蟻一樣,而第二次則是坐上烏龜了。

其它語言的訪問包裝可以在http://wiki.apache.org/cassandra/ClientExamples 這里找到。當(dāng)然,沒有C#的。

三、用C#和Java訪問cassandra

cassandra用到了另外一個好用的東西:thrift。這個東東可以在http://www.thrift-rpc.org/下載。

具體在http://www.thrift-rpc.org/?p=thrift.git;a=shortlog;h=refs/misc/instant,一般點第一個snapshot就行了,這是最新的。版本幾個小時更新一個,太牛叉了。

下載完后,搞到Linux上,解壓。進(jìn)入目錄后進(jìn)行安裝。

  1. #chmod +x *  //設(shè)置執(zhí)行權(quán)限  
  2. #./bootstrap.sh  
  3. #./configure  
  4. #make  
  5. #make install 

安裝好了,接下來,開始生成操作。

切換到cassandra的interface目錄。

然后,使用/home/xieping/thrift/ompiler/cpp/thrift -gen csharp cassandra.thrift 命令生成。運行該命令后,在interface目錄增加了gen-csharp目錄。把它搞到你的機(jī)器,然后,切換到/home/xieping/thrift/lib/csharp目錄。把src目錄搞下來。打開Thrift.csproj文件,右鍵Thrift項目,設(shè)置編譯符號為NET_2_0。新建個C#項目,把gen-csharp目錄下的東西添加進(jìn)去,然后,引用Thrift項目,就可以寫以下代碼調(diào)用:

  • using System;  
  • using Thrift.Transport;  
  • using Thrift.Protocol;  
  • using Apache.Cassandra;namespace TestCa {      
  • class Program {          
  • static void Main(string[] args)   
  • {              
  • TTransport transport = new TSocket("192.168.93.30", 9160);              
  • TProtocol protocol = new TBinaryProtocol(transport);              
  • Cassandra.Client client = new Cassandra.Client(protocol);              
  • transport.Open();              
  • System.Text.Encoding utf8Encoding = System.Text.Encoding.UTF8;              
  • long timeStamp = DateTime.Now.Millisecond;            
  • ColumnPath nameColumnPath = new ColumnPath() {                  
  • Column_family = "Standard1",                  
  • Column = utf8Encoding.GetBytes("name")              
  • };              
  • client.insert("Keyspace1",                            
  • "1",                          nameColumnPath,                          
  • utf8Encoding.GetBytes("測試輸入1"),    
  • timeStamp,   
  • ConsistencyLevel.ONE);              
  • client.insert("Keyspace1",                            
  • "2",                            
  • nameColumnPath,                            
  • utf8Encoding.GetBytes("測試輸入2"),                            
  • timeStamp,                            
  • ConsistencyLevel.ONE);              
  • ColumnOrSuperColumn returnedColumn = client.get("Keyspace1", "1", nameColumnPath, ConsistencyLevel.ONE);              
  • Console.WriteLine("Keyspace1/Standard1 列值: 鍵: {0}, 值: {1}",                                
  • utf8Encoding.GetString(returnedColumn.Column.Name),                              
  • utf8Encoding.GetString(returnedColumn.Column.Value));            
  • transport.Close();              
  • Console.ReadKey();          
  • }    }} 
      
      

      而Java的就變成

      /home/xieping/thrift/ompiler/cpp/thrift -gen java cassandra.thrift

      java相應(yīng)的代碼

      1. import static me.prettyprint.cassandra.utils.StringUtils.bytes;  
      2. import java.io.UnsupportedEncodingException;  
      3. import org.apache.cassandra.service.Cassandra;  
      4. import org.apache.cassandra.service.ColumnOrSuperColumn;  
      5. import org.apache.cassandra.service.ColumnPath;  
      6. import org.apache.cassandra.service.ConsistencyLevel;  
      7. import org.apache.cassandra.service.InvalidRequestException;  
      8. import org.apache.cassandra.service.NotFoundException;  
      9. import org.apache.cassandra.service.TimedOutException;  
      10. import org.apache.cassandra.service.UnavailableException;  
      11. import org.apache.thrift.TException;  
      12. import org.apache.thrift.protocol.TBinaryProtocol;  
      13. import org.apache.thrift.protocol.TProtocol;  
      14. import org.apache.thrift.transport.*;public class Program {      
      15. public class s{              
      16. }          
      17. /**     * @param args       
      18. * @throws Exception        
      19. */      
      20. public static void main(String[] args) throws Exception {          
      21. Long startTime = System.currentTimeMillis();           
      22. for(int i = 0;i < 10000;i++){              
      23. run();          
      24. }          
      25. Long endTime = System.currentTimeMillis();         System.out.println("程序運行到此處計算機(jī)當(dāng)前毫秒數(shù) " + startTime);          
      26. System.out.println("程序共計運行 "+ (endTime-startTime)+" 毫秒");      
      27.  }          
      28. static void run() throws InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, UnsupportedEncodingException{        TTransport transport = new TSocket("192.168.93.30",9160);          
      29. TProtocol protocol = new TBinaryProtocol(transport);          
      30. Cassandra.Client client = new Cassandra.Client(protocol);          
      31. transport.open();          
      32. Long timeStamp = System.currentTimeMillis();                   
      33. ColumnPath nameColumnPath = new ColumnPath("Standard1",null,bytes("name"));          
      34. client.insert("Keyspace1",                        
      35. "1",                      nameColumnPath,                        
      36. bytes("測試數(shù)據(jù)1"),                      timeStamp,                      ConsistencyLevel.ONE);          
      37. client.insert("Keyspace1",                        
      38. "2",                      nameColumnPath,                        
      39. bytes("測試數(shù)據(jù)2"),                      timeStamp,                      ConsistencyLevel.ONE);          
      40. ColumnOrSuperColumn returnedColumn = client.get("Keyspace1", "1", nameColumnPath, ConsistencyLevel.ONE);                  
      41. System.out.println(String.format("key:%s;value:%s",                   
      42. new String(returnedColumn.column.name),                new String(returnedColumn.column.value,"utf-8")));          
      43. transport.close();     
      44.  }    } 

          關(guān)鍵字:NoSQL 數(shù)據(jù)庫 Apache Cassandra 配置
      45. 分享到:

        頂部 】 【 關(guān)閉
        版權(quán)所有:佛山思海電腦網(wǎng)絡(luò)有限公司 ©1998-2024 All Rights Reserved.
        聯(lián)系電話:(0757)22630313、22633833
        中華人民共和國增值電信業(yè)務(wù)經(jīng)營許可證: 粵B1.B2-20030321 備案號:粵B2-20030321-1
        網(wǎng)站公安備案編號:44060602000007 交互式欄目專項備案編號:200303DD003  
        察察 工商 網(wǎng)安 舉報有獎  警警  手機(jī)打開網(wǎng)站