cassadra 安装
1.下载:
apache-cassandra-2.0.6-bin.tar.gz
jdk-8-linux-x64.rpm
2.先更新jdk
rpm -ivh jdk-8-linux-x64.rpm
修改java ,指定到最新版本
rm /usr/bin/java java.bak
ln -s /usr/java/jdk1.8.0/bin/java java
[root@localhost bin]# java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70,mixed mode)
3.安装cassandra
[root@localhost backup]# tar zxvf apache-cassandra-2.0.6-bin.tar.gz
[root@localhost backup]# cd apache-cassandra-2.0.6/bin
root@localhost bin]# ll cassandra
-rwxr-xr-x 1 mongo mongo 7108 3月 7 20:34 cassandra
[root@localhost bin]# ./cassndra
-bash: ./cassndra: 没有那个
文件或目录
[root@localhost bin]# ./cassandra
[root@localhost bin]# INFO 17:59:33,186 Logging initialized
INFO 17:59:33,369 Loading settings from file:/opt/backup/apache-cassandra-2.0.6/conf/cassandra.yaml
ps INFO 17:59:34,440 Data files directories: [/var/lib/cassandra/data]
INFO 17:59:34,443 Commit log directory: /var/lib/cassandra/commitlog
INFO 17:59:34,444 DiskAccessMode 'auto' determined to be mmap,indexAccessMode is mmap
Cassandra集群 实施方案:
两个节点:192.168.10.104 192.168.10.206 相关的JAVA,cassandra 安装不再累述。两节点的配置安装和上面的是一样的。 下面来做相关
配置文件的
修改: 节点1: 192.168.10.104 vi /opt/apache-cassandra-2.0.6/conf/cassandra.yaml
修改内容如下: cluster_name: 'Cluster1' - seeds: "192.168.10.104" listen_address: 192.168.10.104 节点2: 192.168.10.206 vi /opt/apache-cassandra-2.0.6/conf/cassandra.yaml
修改内容如下: cluster_name: 'Cluster1' - seeds: "192.168.10.104" listen_address: 192.168.10.206 启动 节点1: [root@localhost bin]# ./cassandra -f INFO 21:30:13,864 Logging initialized INFO 21:30:13,907 Loading settings from file:/opt/backup/apache-cassandra-2.0.6/conf/cassandra.yaml INFO 21:30:14,202 Data files directories: [/var/lib/cassandra/data] INFO 21:30:14,203 Commit log directory: /var/lib/cassandra/commitlog INFO 21:30:14,203 DiskAccessMode 'auto' determined to be mmap,indexAccessMode is mmap INFO 21:30:14,203 disk_failure_policy is stop INFO 21:30:14,203 commit_failure_policy is stop INFO 21:30:14,207 Global memtable threshold is enabled at 1996MB INFO 21:30:14,282 Not using multi-threaded compaction INFO 21:30:14,420 JVM vendor/version: Java HotSpot(TM) 64-Bit Server VM/1.8.0 INFO 21:30:14,420 Heap size: 8375238656/8375238656 ................... INFO 22:14:41,166 Compacted 4 sstables to [/var/lib/cassandra/data/system/local/system-local-jb-25,]. 6,206 bytes to 5,671 (~91% of original) in 26ms = 0.208011MB/s. 4 total partitions merged to 1. Partition merge counts were {4:1,} INFO 22:14:41,197 Node /192.168.10.104 state jump to normal INFO 22:14:41,209 Waiting for gossip to settle before accepting client requests... INFO 22:14:49,210 No gossip backlog; proceeding INFO 22:14:49,351 Starting listening for CQL clients on /192.168.10.104:9042... INFO 22:14:49,406 Using TFramedTransport with a max frame size of 15728640 bytes. INFO 22:14:49,408 Binding thrift service to /192.168.10.104:9160 INFO 22:14:49,418 Using synchronous/threadpool thrift server on 192.168.10.104 : 9160 INFO 22:14:49,419 Listening for thrift clients... INFO 22:15:44,802 Handshaking version with /192.168.10.206 INFO 22:15:45,914 Node /192.168.10.206 is now part of the cluster INFO 22:15:45,924 Handshaking version with /192.168.10.206 INFO 22:15:45,930 InetAddress /192.168.10.206 is now UP 节点2: [root@localhost bin]# ./cassandra -f INFO 22:18:50,672 Logging initialized INFO 22:18:50,742 Loading settings from file:/opt/backup/apache-cassandra-2.0.6/conf/cassandra.yaml INFO 22:18:51,194 Data files directories: [/var/lib/cassandra/data] INFO 22:18:51,196 Commit log directory: /var/lib/cassandra/commitlog INFO 22:18:51,196 DiskAccessMode 'auto' determined to be mmap,indexAccessMode is mmap INFO 22:18:51,196 disk_failure_policy is stop INFO 22:18:51,197 commit_failure_policy is stop INFO 22:18:51,203 Global memtable threshold is enabled at 253MB INFO 22:18:51,339 Not using multi-threaded compaction INFO 22:18:51,651 JVM vendor/version: Java HotSpot(TM) 64-Bit Server VM/1.8.0 INFO 22:18:51,652 Heap size: 1063256064/1063256064 ................... INFO 22:19:05,145 Starting listening for CQL clients on /192.168.10.206:9042... INFO 22:19:05,267 Using TFramedTransport with a max frame size of 15728640 bytes. INFO 22:19:05,271 Binding thrift service to /192.168.10.206:9160 INFO 22:19:05,320 Using synchronous/threadpool thrift server on 192.168.10.206 : 9160 INFO 22:19:05,322 Listening for thrift clients... INFO 22:20:12,302 Handshaking version with /192.168.10.104 INFO 22:20:12,345 Node /192.168.10.104 is now part of the cluster INFO 22:20:12,422 Handshaking version with /192.168.10.104 INFO 22:20:12,436 InetAddress /192.168.10.104 is now UP 经检查,发现防火墙开着,两节点一直无法连接上。在
修改防火墙后,终于成功
解决问题。 查看集群状态如下: [root@localhost bin]# ./nodetool -h 192.168.10.206 ring Datacenter: datacenter1 ========== Address Rack Status State Load Owns Token 9219864279989867836 192.168.10.104 rack1 Up Normal 61.04 KB 100.00% -9209067550672142833 ............................. 192.168.10.104 rack1 Up Normal 61.04 KB 100.00% 9119365032104954381 192.168.10.104 rack1 Up Normal 61.04 KB 100.00% 9144131727983125656 192.168.10.104 rack1 Up Normal 61.04 KB 100.00% 9194205234863680199 192.168.10.104 rack1 Up Normal 61.04 KB 100.00% 9205150584807094387 192.168.10.206 rack1 Up Normal 64.28 KB 100.00% -9093153247508407374 192.168.10.206 rack1 Up Normal 64.28 KB 100.00% -8959856259961417723 192.168.10.206 rack1 Up Normal 64.28 KB 100.00% -8933270068536399704 ........................ Warning: "nodetool ring" is used to output all the tokens of a node. To view status related info of a node use "nodetool status" instead. 测试: 1.在 206 节点创建 keyspace,并插入数据: [root@localhost bin]# ./cassandra-cli -host 192.168.10.206 Connected to: "Cluster1" on 192.168.10.206/9160 Welcome to Cassandra CLI version 2.0.6 The CLI is deprecated and will be removed in Cassandra 3.0. Consider migrating to cqlsh. CQL is fully backwards compatible with Thrift data; see http://www.datastax.com/dev/blog/thrift-to-cql3 Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit. [default@unknown] create keyspace testspace ... ; 6ceaabf9-afde-3d03-ae18-21da5c18f58b [default@unknown] use testspace; Authenticated to keyspace: testspace [default@testspace] create column family testcf ... with column_type = 'Standard' ... and comparator = 'UTF8Type' ... and default_validation_class = 'UTF8Type' ... and key_validation_class = 'UTF8Type' ... and read_repair_chance = 0.1 ... and dclocal_read_repair_chance = 0.0 ... and populate_io_cache_on_flush = false ... and gc_grace = 864000 ... and min_compaction_threshold = 4 ... and max_compaction_threshold = 32 ... and replicate_on_write = true ... and compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy' ... and caching = 'KEYS_ONLY' ... and default_time_to_live = 0 ... and speculative_retry = 'NONE' ... and compression_options = {'sstable_compression' : 'org.apache.cassandra.io.compress.LZ4Compressor'} ... and index_interval = 128; 273dc95f-512c-336f-b6e4-fb751560c4f2 [default@testspace] set testcf['num']['num1']=1111; Value inserted. Elapsed time: 91 msec(s). [default@testspace] 2.在节点2查看数据: [root@localhost bin]# ./cassandra-cli -h 192.168.10.104 Connected to: "Cluster1" on 192.168.10.104/9160 Welcome to Cassandra CLI version 2.0.6 The CLI is deprecated and will be removed in Cassandra 3.0. Consider migrating to cqlsh. CQL is fully backwards compatible with Thrift data; see http://www.datastax.com/dev/blog/thrift-to-cql3 Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit. [default@unknown] use testspace; Authenticated to keyspace: testspace [default@testspace] list testcf; Using default limit of 100 Using default cell limit of 100 ------------------- RowKey: num => (name=num1,value=1111,timestamp=1397399586622000) 1 Row Returned. Elapsed time: 421 msec(s). [default@testspace] 可以看到,数据已同步过来了。