搭建cassandra集羣簡要

cassandra是facebook開源的著名nosql數據庫。因爲它和google的big talbe及amazon的dynamo有着千絲萬縷的聯繫,一時好奇,搭建了下簡單的雙機環境。

cassandra是由java寫的,所以需要安裝openjdk
如果客戶端程序使用cassandra,可以用facebook的thrift這個高性能二進制中間件。

假設有兩個客戶端:
10.1.1.11/24和10.1.1/12/24

解壓之後,創建文件夾,並使之可以被當前用戶訪問(chown -R)
mkdir -p /var/log/cassandra
mkdir -p /var/lib/cassandra


編輯conf/cassandra.yaml文件
seed_provider:
# Addresses of hosts that are deemed contact points.
# Cassandra nodes use this list of hosts to find each other and learn
# the topology of the ring. You must change this if you are running
# multiple nodes!
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
# seeds is actually a comma-delimited list of addresses.
# Ex: "<ip1>,<ip2>,<ip3>"
- seeds: "127.0.0.1, 10.1.1.11, 10.1.1.12" #這裏寫上性能比較穩定的seed服務器

listen_address: 10.1.1.12 #可以空着,表示本機IP地址


rpc_address: 0.0.0.0 #允許任何地址的程序前來訪問本數據庫

這裏沒有硬性規定seed應該是誰。普通cassandra啓動的時候都會先去連接seed,看看有其它node是否存活

之後可以啓動cassandra
cassandra -f


查看一下集羣的狀態
bin/nodetool -host 10.1.1.11 -p 7199 ring


使用客戶端訪問cassandra集羣
bin/cassandra-cli -h 127.0.0.1 -p 9160


創建一個簡單的keyspace並添加數據,查看數據
  [default@unknown] create keyspace Keyspace1;
ece86bde-dc55-11df-8240-e700f669bcfc
[default@unknown] use Keyspace1;
Authenticated to keyspace: Keyspace1
[default@Keyspace1] create column family Users with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
737c7a71-dc56-11df-8240-e700f669bcfc

[default@KS1] set Users[jsmith][first] = 'John';
Value inserted.
[default@KS1] set Users[jsmith][last] = 'Smith';
Value inserted.
[default@KS1] set Users[jsmith][age] = long(42);
Value inserted.
[default@KS1] get Users[jsmith];


至此簡單集羣搭建成功,詳細就翻翻apache cassandra的文檔吧。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章