开源Nosql数据库Cassandra3.0实战-集群部署与插件使用-创新互联

简介

市中网站建设公司创新互联,市中网站设计制作,有大型网站制作公司丰富经验。已为市中上1000+提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的市中做网站的公司定做!

  Cassandra是一套开源分布式NoSQL数据库系统,Cassandra的主要特点是无中心的设计,其分布式集群由一堆数据库节点共同构成一个分布式网络服务,对Cassandra 的一个写操作,会被复制到其他节点上去,对Cassandra的读操作,也会被路由到某个节点上面去读取。对于一个Cassandra群集来说,扩展性能是比较简单的事情,只管在群集里面添加节点就可以了。

  随着Nosql的火热,Hbase、Mongodb已然成了NoSQL数据库的代表,而Cassandra在国内的使用却不多(据说360公司在大规模使用),根据百度指数的显示cassandra的火热度远远低于mongodb和Hbase。

开源Nosql数据库Cassandra3.0实战-集群部署与插件使用

  而在国外,根据数据库评分网站DB-Engines的16.10的最新数据,cassandra排名上升到了第7,排名远远高于Hbase。

开源Nosql数据库Cassandra3.0实战-集群部署与插件使用

  • 优点:

1、模式灵活

使用Cassandra,像文档存储,你不必提前解决记录中的字段。你可以在系统运行时随意的添加或移除字段。这是一个惊人的效率提升,特别是在大型部署上。

2、真正的可扩展性

Cassandra是纯粹意义上的水平扩展。为给集群添加更多容量,可以指向另一台电脑。你不必重启任何进程,改变应用查询,或手动迁移任何数据。

3、多数据中心识别

你可以调整你的节点布局来避免某一个数据中心起火,一个备用的数据中心将至少有每条记录的完全复制。

4、范围查询

如果你不喜欢全部的键值查询,则可以设置键的范围来查询。

5、列表数据结构

在混合模式可以将超级列添加到5维。对于每个用户的索引,这是非常方便的。

6、分布式写操作

有可以在任何地方任何时间集中读或写任何数据。并且不会有任何单点失败

  • 缺点

1. 读的性能太慢

无中心的设计,造成读数据时通过逆熵做计算,性能损耗很大,甚至会严重影响服务器运作。

2. 数据同步太慢(最终一致性延迟可能非常大)

由于无中心设计,要靠各节点传递信息。相互发通知告知状态,如果副本集有多份,其中又出现节点有宕机的情况,那么做到数据的一致性,延迟可能非常大,效率也很低的。

3. 用插入和更新代替查询,缺乏灵活性,所有查询都要求提前定义好。

与大多数数据库为读优化不同,Cassandra的写性能理论上是高于读性能的,因此非常适合流式的数据存储,尤其是写负载高于读负载的。与HBase比起来,它的随机访问性能要高很多,但不是很擅长区间扫描,因此可以作为HBase的即时查询缓存,由HBase进行批量的大数据处理,由Cassandra提供随机查询的接口

4. 不支持直接接入hadoop,不能实现MapReduce。

现在大数据的代名词就是hadoop,做为海量数据的框架不支持hadoop及MapReduce,就将被取代。除非Cassandra能够给出其他的定位,或者海量数据解决方案。DataStax公司,正在用Cassandra重构HDFS的文件系统,不知道是否可以成功。

一:部署cassandra

规划:

集群节点: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"   #节点ip列表 listen_address: 10.10.8.5                 #进程监听地址 storage_port: 7000                        #集群中节点通信的端口号 start_native_transport: true              #开启native协议 native_transport_port: 9042               #客户端的交互端口 data_file_directories:     - /data/cassandra/dbdata              # 数据位置,多盘的话可以写多个目录 commitlog_directory:     - /data/cassandra/commitlog           #commitlog的路径,与data目录分开磁盘,提高性能 saved_caches_directory:     - /data/cassandra/caches              #缓存数据目录 hints_directory:     - /data/cassandra/hints commitlog_sync: batch                     #批量记录commitlog,每隔一段时间将数据commitlog commitlog_sync_batch_window_in_ms: 2      #batch模式下,批量操作缓存的时间间隔 #commitlog_sync: periodic                 #周期记录commitlog,每一次有数据更新都commitlog #commitlog_sync_period_in_ms: 10000       #periodic模式,刷新commitlog的时间间隔 partitioner: org.apache.cassandra.dht.Murmur3Partitioner endpoint_snitch: SimpleSnitch

 

如果使用cassandra的默认配置,只需要修改如下行即可,其他性能参数请参照官方文档。

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)创建对应的目录

  • 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的集群和节点的管理和信息查看工具。

$ /opt/cassandra/bin/nodetool usage: nodetool [(-u <username> | --username <username>)]         [(-pw <password> | --password <password>)]         [(-pwf <passwordFilePath> | --password-file <passwordFilePath>)]         [(-h <host> | --host <host>)] [(-p <port> | --port <port>)] <command> [<args>]

1:查看集群状态

$/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

开源Nosql数据库Cassandra3.0实战-集群部署与插件使用

2:当前节点状态

$/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:关闭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:查看各个列的数据详细信息、读写次数,响应时间等

$ /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,能实现对数据的增删改查等一些列的操作。

$ /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

开源Nosql数据库Cassandra3.0实战-集群部署与插件使用

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数据操作语言的相关命令

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  ---优点

链接:https://www.zhihu.com/question/19592244/answer/21430967      ---缺点

连接:http://yikebocai.com/2014/06/cassandra-principle/         ---原理

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

分享题目:开源Nosql数据库Cassandra3.0实战-集群部署与插件使用-创新互联
本文链接:https://www.cdcxhl.com/article42/dssdec.html

成都网站建设公司_创新互联,为您提供搜索引擎优化网站设计动态网站ChatGPTApp设计网站收录

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站托管运营