部署兩節點cassandra叢集
確保系統已安裝jdk,可不配置JAVA環境變數
cassandra版本:apache-cassandra-1.1.5jdk版本:jdk1.6.0_38
1、cassandra 日誌路徑#vim log4j-server.propertieslog4j.appender.R.File=/trs6/cassandra/logs/system.log
2、cassandra 記憶體使用量 (HEAP_NEWSIZE)=1/4(MAX_HEAP_SIZE)#vim cassandra-env.shMAX_HEAP_SIZE="4G"HEAP_NEWSIZE="800M"
3、cassandra 叢集配置#vim cassandra.yamlcluster_name: 'pis' //叢集名稱initial_token: 0 //由initial_token.py產生
#!/usr/bin/env pythonimport sysif (len(sys.argv) > 1): num=int(sys.argv[1])else: num=int(raw_input("How many nodes are in your cluster? "))for i in range(0, num): print 'node %d: %d' % (i, (i*(2**127)/num))
data_file_directories: - /trs6/cassandra/data //data儲存目錄commitlog_directory: /trs6/cassandra/commitlog //commit日誌目錄saved_caches_directory: /trs6/cassandra/saved_cache //cache儲存目錄- seeds: "192.168.183.71,192.168.183.72" //種子節點IPlisten_address: 192.168.183.71 //監聽地址->本機IPrpc_address: 192.168.183.71endpoint_snitch: SimpleSnitch
4、啟動叢集#bin/cassandra
5、查看叢集狀態#bin/nodetool -h 192.168.183.71 ring
Address DC Rack Status State Load Effective-Ownership Token 85070591730234615865843651857942052864 192.168.183.71 datacenter1 rack1 Up Normal 23.61 KB 50.00% 0 192.168.183.72 datacenter1 rack1 Up Normal 23.61 KB 50.00% 85070591730234615865843651857942052864
6、互動式命令列 分號結尾)[root@cas1 ~]# bin/cassandra-cli -h 192.168.183.71Connected to: "pis" on 192.168.183.71/9160Welcome to Cassandra CLI version 1.1.5
Type 'help;' or '?' for help.Type 'quit;' or 'exit;' to quit.
1)建立keyspace[default@unknown] create keyspace DEMO;5210d4ac-24e2-37e1-8d38-13a3cab24f33Waiting for schema agreement...... schemas agree across the cluster2)認證使用keyspace[default@unknown] use DEMO;Authenticated to keyspace: DEMO3)建立column family[default@DEMO] create column family Users ...with key_validation_class = 'UTF8Type' ...and comparator = 'UTF8Type' ...and default_validation_class = 'UTF8Type';8618bf72-4e3d-3b7c-84f6-031e69e7d161Waiting for schema agreement...... schemas agree across the cluster4)儲存資料到column family[default@DEMO] set Users[1234][name] = tianxin;Value inserted.Elapsed time: 87 msec(s).[default@DEMO] set Users[1234][password] = upgirl; Value inserted.Elapsed time: 28 msec(s).5)擷取資料[default@DEMO] get Users[1234];=> (column=name, value=tianxin, timestamp=1362521480914000)=> (column=password, value=upgirl, timestamp=1362521498155000)Returned 2 results.Elapsed time: 131 msec(s).
遇到的問題:1、啟動cassandra時,報錯 Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: cas1: cas1原因:叢集節點必須配置主機名稱的解析
2、建立keyspace時,報錯 The schema has not settled in 10 seconds; further migrations are ill-advised until it does.Versions are e71db6f5-eb85-3555-b851-1878497cf194:[198.216.27.72],eceb06f2-03a1-3bf8-a421-2528a053d7e6:[198.216.27.71]原因:叢集節點間時間不同步
本文出自 “振翅的小宇宙” 部落格,請務必保留此出處http://upgirl.blog.51cto.com/3744514/1147976