新聞中心
簡介
創(chuàng)新互聯(lián)是一家專業(yè)提供濟寧企業(yè)網(wǎng)站建設,專注與成都網(wǎng)站建設、做網(wǎng)站、H5頁面制作、小程序制作等業(yè)務。10年已為濟寧眾多企業(yè)、政府機構(gòu)等服務。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站設計公司優(yōu)惠進行中。
Cassandra是一套開源分布式NoSql數(shù)據(jù)庫系統(tǒng),Cassandra的主要特點是無中心的設計,其分布式集群由一堆數(shù)據(jù)庫節(jié)點共同構(gòu)成一個分布式網(wǎng)絡服務,對Cassandra 的一個寫操作,會被復制到其他節(jié)點上去,對Cassandra的讀操作,也會被路由到某個節(jié)點上面去讀取。對于一個Cassandra群集來說,擴展性能是比較簡單的事情,只管在群集里面添加節(jié)點就可以了。
隨著NOSQL的火熱,Hbase、MongoDB已然成了NoSQL數(shù)據(jù)庫的代表,而Cassandra在國內(nèi)的使用卻不多(據(jù)說360公司在大規(guī)模使用),根據(jù)百度指數(shù)的顯示cassandra的火熱度遠遠低于mongodb和Hbase。
而在國外,根據(jù)數(shù)據(jù)庫評分網(wǎng)站DB-Engines的16.10的最新數(shù)據(jù),cassandra排名上升到了第7,排名遠遠高于Hbase。
優(yōu)點:
1、模式靈活
使用Cassandra,像文檔存儲,你不必提前解決記錄中的字段。你可以在系統(tǒng)運行時隨意的添加或移除字段。這是一個驚人的效率提升,特別是在大型部署上。
2、真正的可擴展性
Cassandra是純粹意義上的水平擴展。為給集群添加更多容量,可以指向另一臺電腦。你不必重啟任何進程,改變應用查詢,或手動遷移任何數(shù)據(jù)。
3、多數(shù)據(jù)中心識別
你可以調(diào)整你的節(jié)點布局來避免某一個數(shù)據(jù)中心起火,一個備用的數(shù)據(jù)中心將至少有每條記錄的完全復制。
4、范圍查詢
如果你不喜歡全部的鍵值查詢,則可以設置鍵的范圍來查詢。
5、列表數(shù)據(jù)結(jié)構(gòu)
在混合模式可以將超級列添加到5維。對于每個用戶的索引,這是非常方便的。
6、分布式寫操作
有可以在任何地方任何時間集中讀或?qū)懭魏螖?shù)據(jù)。并且不會有任何單點失敗
缺點
1. 讀的性能太慢
無中心的設計,造成讀數(shù)據(jù)時通過逆熵做計算,性能損耗很大,甚至會嚴重影響服務器運作。
2. 數(shù)據(jù)同步太慢(最終一致性延遲可能非常大)
由于無中心設計,要靠各節(jié)點傳遞信息。相互發(fā)通知告知狀態(tài),如果副本集有多份,其中又出現(xiàn)節(jié)點有宕機的情況,那么做到數(shù)據(jù)的一致性,延遲可能非常大,效率也很低的。
3. 用插入和更新代替查詢,缺乏靈活性,所有查詢都要求提前定義好。
與大多數(shù)數(shù)據(jù)庫為讀優(yōu)化不同,Cassandra的寫性能理論上是高于讀性能的,因此非常適合流式的數(shù)據(jù)存儲,尤其是寫負載高于讀負載的。與HBase比起來,它的隨機訪問性能要高很多,但不是很擅長區(qū)間掃描,因此可以作為HBase的即時查詢緩存,由HBase進行批量的大數(shù)據(jù)處理,由Cassandra提供隨機查詢的接口
4. 不支持直接接入hadoop,不能實現(xiàn)MapReduce。
現(xiàn)在大數(shù)據(jù)的代名詞就是hadoop,做為海量數(shù)據(jù)的框架不支持hadoop及MapReduce,就將被取代。除非Cassandra能夠給出其他的定位,或者海量數(shù)據(jù)解決方案。DataStax公司,正在用Cassandra重構(gòu)HDFS的文件系統(tǒng),不知道是否可以成功。
一:部署cassandra
規(guī)劃:
集群節(jié)點:3
10.10.8.3
10.10.8.4
10.10.8.5
(1)配置jdk
10.10.8.3、10.10.8.4、10.10.8.5
$ wget http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz $ tar xf jdk-8u112-linux-x64.tar.gz -C /opt $ vim /etc/profile 增加 export JAVA_HOME=/opt/jdk1.8.0_112 export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar $ source /etc/profile
(2)安裝Cassandra
10.10.8.3、10.10.8.4、10.10.8.5
$ wget http://apache.fayea.com/cassandra/3.0.9/apache-cassandra-3.0.9-bin.tar.gz $ tar xvf apache-cassandra-3.0.9-bin.tar.gz -C /opt $ ln -s /opt/apache-cassandra-3.0.9 /opt/cassandra
(3)配置
10.10.8.3、10.10.8.4、10.10.8.5
$ copy conf/cassandra.yaml conf/cassandra.yaml.bak $ vim conf/cassandra.yaml #cassandra-3.0.9的精簡配置,可以運行集群的最低配置。 cluster_name: 'My Cluster' #集群名 num_tokens: 256 seed_provider: - class_name: org.apache.cassandra.locator.SimpleSeedProvider parameters: - seeds: "10.10.8.3,10.10.8.4,10.10.8.5" #節(jié)點ip列表 listen_address: 10.10.8.5 #進程監(jiān)聽地址 storage_port: 7000 #集群中節(jié)點通信的端口號 start_native_transport: true #開啟native協(xié)議 native_transport_port: 9042 #客戶端的交互端口 data_file_directories: - /data/cassandra/dbdata # 數(shù)據(jù)位置,多盤的話可以寫多個目錄 commitlog_directory: - /data/cassandra/commitlog #commitlog的路徑,與data目錄分開磁盤,提高性能 saved_caches_directory: - /data/cassandra/caches #緩存數(shù)據(jù)目錄 hints_directory: - /data/cassandra/hints commitlog_sync: batch #批量記錄commitlog,每隔一段時間將數(shù)據(jù)commitlog commitlog_sync_batch_window_in_ms: 2 #batch模式下,批量操作緩存的時間間隔 #commitlog_sync: periodic #周期記錄commitlog,每一次有數(shù)據(jù)更新都commitlog #commitlog_sync_period_in_ms: 10000 #periodic模式,刷新commitlog的時間間隔 partitioner: org.apache.cassandra.dht.Murmur3Partitioner endpoint_snitch: SimpleSnitch
如果使用cassandra的默認配置,只需要修改如下行即可,其他性能參數(shù)請參照官方文檔。
10 cluster_name: 'My Cluster' 71 hints_directory: /data/cassandra/hints 169 data_file_directories:170 - /data/cassandra/dbdata 175 commitlog_directory: /data/cassandra/commitlog 287 saved_caches_directory: /data/cassandra/caches 343 - seeds: "10.10.8.3,10.10.8.4,10.10.8.5" 473 listen_address: localhost
(4)創(chuàng)建對應的目錄
10.10.8.3、10.10.8.4、10.10.8.5
$ mkdir -p /data/cassandra/{dbdata,commitlog,caches,hints}
(5)啟動進程
10.10.8.3、10.10.8.4、10.10.8.5
$ /opt/cassandra/bin/cassandra
二:插件工具使用
(1)nodetool工具
nodetool是cassandra的集群和節(jié)點的管理和信息查看工具。
$ /opt/cassandra/bin/nodetool usage: nodetool [(-u| --username )] [(-pw | --password )] [(-pwf | --password-file )] [(-h | --host )] [(-p | --port )] [ ]
1:查看集群狀態(tài)
$/opt/cassandra/bin/nodetool status Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 10.10.8.3 304.71 KB 256 68.0% 64b6a935-caa6-4ed5-857b-70963e74a81d rack1 UN 10.10.8.4 173.84 KB 256 65.3% db77bd8a-2655-41c6-b13e-584cf44b8162 rack1 UN 10.10.8.5 297.2 KB 256 66.7% 8fac64f8-1ed9-4ca3-af70-dee9ebcf77c2 rack1
2:當前節(jié)點狀態(tài)
$/opt/cassandra/bin/nodetool info ID : db77bd8a-2655-41c6-b13e-584cf44b8162 Gossip active : true Thrift active : true Native Transport active: true Load : 173.84 KB Generation No : 1478159246 Uptime (seconds) : 4554 Heap Memory (MB) : 297.65 / 7987.25 Off Heap Memory (MB) : 0.00 Data Center : datacenter1 Rack : rack1 Exceptions : 0 Key Cache : entries 14, size 1.08 KB, capacity 100 MB, 110 hits, 127 requests, 0.866 recent hit rate, 14400 save period in seconds Row Cache : entries 0, size 0 bytes, capacity 0 bytes, 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds Counter Cache : entries 0, size 0 bytes, capacity 50 MB, 0 hits, 0 requests, NaN recent hit rate, 7200 save period in seconds Token : (invoke with -T/--tokens to see all 256 tokens)
3:關(guān)閉cassandra的進程
$ /opt/cassandra/bin/nodetool stopdaemon Cassandra has shutdown. error: Connection refused -- StackTrace -- java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
4:查看各個列的數(shù)據(jù)詳細信息、讀寫次數(shù),響應時間等
$ /opt/cassandra/bin/nodetool cfstats Keyspace: system_traces Read Count: 0 Read Latency: NaN ms. Write Count: 0 Write Latency: NaN ms. Pending Flushes: 0 Table: events SSTable count: 0 Space used (live): 0 Space used (total): 0 Space used by snapshots (total): 0 Off heap memory used (total): 0 SSTable Compression Ratio: 0.0 Number of keys (estimate): 0 Memtable cell count: 0 Memtable data size: 0 Memtable off heap memory used: 0 Memtable switch count: 0
(2)cqlsh 命令行工具
cqlsh是cassandra的客戶端命令行工具,替代了之前版本中的cassandra-cli,能實現(xiàn)對數(shù)據(jù)的增刪改查等一些列的操作。
$ /opt/cassandra/bin/cqlsh Usage: cqlsh [options] [host [port]] CQL Shell for Apache Cassandra
1:安裝python2.7(依賴python)
$ yum install openssl-devel #防止python編譯后沒有ssl模塊,導致cqlsh不可用 $ wget https://www.python.org/ftp/python/2.7/Python-2.7.tgz $ tar xf Python-2.7.tgz $ cd Python-2.7 $ mkdir /usr/local/python27 $ ./configure --prefix=/usr/local/python27 $ make&&make install $ ln -s /usr/local/python27/bin/python2.7 /usr/bin/python2.7
如果遇到 ImportError: No module named _ssl ,就安裝openssl-devel,然后再編譯安裝python
2:連接host
$ /opt/cassandra/bin/cqlsh 10.10.8.3 9042 Connected to My Cluster at 10.10.8.3:9042. [cqlsh 5.0.1 | Cassandra 3.0.9 | CQL spec 3.4.0 | Native protocol v4] Use HELP for help. cqlsh> show version [cqlsh 5.0.1 | Cassandra 3.0.9 | CQL spec 3.4.0 | Native protocol v4] cqlsh> show host Connected to My Cluster at 10.10.8.3:9042.
3:help命令可以看到 CQL數(shù)據(jù)操作語言的相關(guān)命令
cqlsh> help Documented shell commands: =========================== CAPTURE CLS COPY DESCRIBE EXPAND LOGIN SERIAL SOURCE UNICODE CLEAR CONSISTENCY DESC EXIT HELP PAGING SHOW TRACING CQL help topics: ================ AGGREGATES CREATE_KEYSPACE DROP_TRIGGER TEXT ALTER_KEYSPACE CREATE_MATERIALIZED_VIEW DROP_TYPE TIME ALTER_MATERIALIZED_VIEW CREATE_ROLE DROP_USER TIMESTAMP ALTER_TABLE CREATE_TABLE FUNCTIONS TRUNCATE ALTER_TYPE CREATE_TRIGGER GRANT TYPES ALTER_USER CREATE_TYPE INSERT UPDATE APPLY CREATE_USER INSERT_JSON USE ASCII DATE INT UUID BATCH DELETE JSON BEGIN DROP_AGGREGATE KEYWORDS BLOB DROP_COLUMNFAMILY LIST_PERMISSIONS BOOLEAN DROP_FUNCTION LIST_ROLES COUNTER DROP_INDEX LIST_USERS CREATE_AGGREGATE DROP_KEYSPACE PERMISSIONS CREATE_COLUMNFAMILY DROP_MATERIALIZED_VIEW REVOKE CREATE_FUNCTION DROP_ROLE SELECT CREATE_INDEX DROP_TABLE SELECT_JSON cqlsh>
參考資料
連接:http://cassandra.apache.org/doc/latest/ ---官方文檔
鏈接:http://jingyan.baidu.com/article/7e440953ec8a7e2fc0e2ef9b.html ---優(yōu)點
鏈接:https://www.zhihu.com/question/19592244/answer/21430967 ---缺點
連接:http://yikebocai.com/2014/06/cassandra-principle/ ---原理
新聞名稱:開源Nosql數(shù)據(jù)庫Cassandra3.0實戰(zhàn)-集群部署與插件使用
URL標題:http://fisionsoft.com.cn/article/pgocis.html