Cassandra112入门指南(单节点)_第1页
Cassandra112入门指南(单节点)_第2页
Cassandra112入门指南(单节点)_第3页
Cassandra112入门指南(单节点)_第4页
Cassandra112入门指南(单节点)_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Cassandra1.1.2入门指南Cassandraisahighlyscalable,eventuallyconsistent,distributed,structuredkey-valuestore.Cassandra是高扩展性的、最终一致性的、分布式的、结构化的key/value存储系统。Formoreinformationsee:///:///cassandra/Projectdescription-------------------CassandrabringstogetherthedistributedsystemstechnologiesfromDynamoandthedatamodelfromGoogle'sBigTable.LikeDynamo,Cassandraiseventuallyconsistent.LikeBigTable,CassandraprovidesaColumnFamily-baseddatamodelricherthantypicalkey/valuesystems.Cassandra结合了源自Dynamo的分布式系统技术〔存储模型〕与源自GoogleBigTable的数据组织结构和访问控制技术〔数据模型〕。Cassandra采用了Dynamo的最终一致性原那么,采用了BigTable的基于ColumnFamily的数据模型〔优于典型的key/value系统数据模型〕。keyspace类似于关系数据库中的database。ColumnFamily类似于关系数据库中的关系relation。key类似于关系数据库中的主键primarykey。column类似于关系数据库中的列名columnname。value类似于关系数据库中一个行列交汇处的值value。Requirements------------*Java>=1.6(OpenJDKandSunhavebeentested)Gettingstarted---------------Thisshortguidewillwalkyouthroughgettingabasiconenodeclusterupandrunning,anddemonstratesomesimplereadsandwrites.构建并运行只有一个节点的集群,然后演示简单的读写。在Linux下执行命令如下:*tar-zxvfapache-cassandra-$VERSION.tar.gz*cdapache-cassandra-$VERSION*sudomkdir-p/var/log/cassandra*sudochown-R`whoami`/var/log/cassandra*sudomkdir-p/var/lib/cassandra*sudochown-R`whoami`/var/lib/cassandraNote:Thesampleconfigurationfilesinconf/determinethefile-systemlocationsCassandrausesforlogginganddatastorage.Youarefreetochangethesetosuityourownenvironmentandadjustthepathnamesusedhereaccordingly.$cassandra_HOME/conf/目录下的cassandra.yaml配置文件设置了用于记录日志和数据存储的文件系统的位置。可以任意修改到其他路径。#directorieswhereCassandrashouldstoredataondisk.data_file_directories:-/var/lib/cassandra/data#commitlogcommitlog_directory:/var/lib/cassandra/commitlog补充:Linux下执行bin/cassandra启动Cassandra之前,需要设置如下环境变量,否那么会抛出NoClassDefFoundError等异常:#CLASSPATH--AJavaclasspathcontainingeverythingnecessarytorun. Java类路径,包含运行所需的所有jar(通过bin/cassandra.in.sh设置)#JVM_OPTS--AdditionalargumentstotheJVMforheapsize,etc JVM的其他参数,如堆大小等(通过conf/cassandra-env.sh设置,执行bin/cassandra会调用该脚本)。#CASSANDRA_CONF--DirectorycontainingCassandraconfigurationfiles. Cassandra配置文件目录(通过bin/cassandra.in.sh设置)使环境变量立刻生效:sourcebin/cassandra.in.sh查看环境变量: echo$CLASSPATHNowthatwe'reready,let'sstartitup!Linux下翻开终端窗口,通过脚本启动Cassandra,执行如下:*bin/cassandra-fUnix:Runningthestartupscriptwiththe-fargumentwillcauseCassandratoremainintheforegroundandlogtostandardout.注意:Linux下启动Cassandra使用-f参数,可以使Cassandra前台运行,以方便查看输出日志。其他还有如下两个参数:#-p<filename>:logthepidtoafile(usefultokillitlater) 将Cassandra的进程ID〔pid〕记录到日志文件〔后续可以通过kill<pid>停止Cassandra〕#-v:printversionstringandexit 打印出版本信息并停止Windows:bin\cassandra.batrunsintheforegroundbydefault.ToinstallCassandraasaWindowsservice,downloadProcrunfrom:///daemon/procrun.html,setthePRUNSRVenvironmentvariabletothefullpathofprunsrv(e.g.,C:\procrun\prunsrv.exe),andrun"bin\cassandra.batinstall".Similarly,"uninstall"willremovetheservice.Nowlet'strytoreadandwritesomedatausingthecommandlineclient.下面就可以使用命令行客户端读写数据了。翻开新的终端窗口,执行如下命令:*bin/cassandra-cli--hostlocalhostThecommandlineclientisinteractivesoifeverythingworkedyoushouldbesittinginfrontofaprompt...该命令行客户端具有交互性,如果一切正常,将会出现如下提示。Connectedto:"TestCluster"onlocalhost/9160WelcometocassandraCLI.Type'help;'or'?'forhelp.Type'quit;'or'exit;'toquit.[default@unknown]Asthebannersays,youcanuse'help;'or'?'toseewhattheCLIhastooffer,and'quit;'or'exit;'whenyou'vehadenoughfun.Butletstrysomethingslightlymoreinteresting...在出现的提示符后面执行如下操作:[default@unknown]createkeyspaceKeyspace1;ece86bde-dc55-11df-8240-e700f669bcfc[default@unknown]useKeyspace1;Authenticatedtokeyspace:Keyspace1[default@Keyspace1]createcolumnfamilyUserswithcomparator=UTF8Typeanddefault_validation_class=UTF8Typeandkey_validation_class=UTF8Type;737c7a71-dc56-11df-8240-e700f669bcfc[default@KS1]setUsers[jsmith][first]='John';Valueinserted.[default@KS1]setUsers[jsmith][last]='Smith';Valueinserted.[default@KS1]setUsers[jsmith][age]=long(42);Valueinserted.[default@KS1]getUsers[jsmith];=>(column=last,value=Smith,timestamp=1287604215498000)=>(column=first,value=John,timestamp=1287604214111000)=>(column=age,value=42,timestamp=1287604216661000)Returned3results.Ifyoursessionlookssimilartowhat'sabove,congrats,yoursinglenodeclusterisoperational!Butwhatexactlywasallofthat?Let'sbreakitdownintopiecesandsee.setUsers[jsmith][first]='John';\\\\\\_key\\_value\\_column\_columnfamilyDatastoredinCassandraisassociatedwithacolumnfamily(Users),whichinturnisassociatedwithakeyspace(Keyspace1).Intheexampleabove,wesetthevalue'John'inthe'first'columnforkey'jsmith'.FormoreinformationontheCassandradatamodelbesuretocheckout:///cassandra/DataModelWondering

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论