cluster_name: 'TC01'num_tokens: 256seed_provider: - class_name: org.apache.cassandra.locator.SimpleSeedProvider parameters: - seeds: "192.168.2.103"listen_address: 192.168.2.103rpc_address: 192.168.2.103endpoint_snitch: SimpleSnitch
cluster_name必须修改,以免使用默认的“Test Cluster“与他人发生冲突,所有显示ip的地方都需要注意和修改,127.0.0.1和localhost改为您的外部访问ip,例如,我的局域网ip是192.168.2.103。
启动cassandra,
XXXXX@XXXXX-asus:~/apache-cassandra-2.0.6$ cd bin/XXXXX@XXXXX-asus:~/apache-cassandra-2.0.6/bin$ ./cassandra -f
现在cassandra已经启动了节点1,节点2在虚拟机上(ip:192.168.2.102),其配置与节点1非常相似,需要将配置中的seedsip改为节点1ip
cluster_name: 'TC01'num_tokens: 256seed_provider: - class_name: org.apache.cassandra.locator.SimpleSeedProvider parameters: - seeds: "192.168.2.103"listen_address: 192.168.2.102rpc_address: 192.168.2.102endpoint_snitch: SimpleSnitch
以同样的方式启动节点2,您可以在节点1中看到节点2已经添加到集群中。此时,以下信息可以在节点1的标志中看到
WARN 17:36:15,477 Gossip stage has 1 pending tasks; skipping status check (no nodes will be marked down) INFO 17:36:16,358 Handshaking version with /192.168.2.102 INFO 17:36:17,999 Node /192.168.2.102 is now part of the cluster INFO 17:36:18,496 Handshaking version with /192.168.2.102 INFO 17:36:18,727 InetAddress /192.168.2.102 is now UP INFO 17:36:53,523 [Stream #24d92630-c2ef-11e3-9d13-81bcfc8708 Received streaming plan for Bootstrap INFO 17:36:54,336 [Stream #24d92630-c2ef-11e3-9d13-81bcfc8708 Session with /192.168.2.102 is complete INFO 17:36:54,586 [Stream #24d92630-c2ef-11e3-9d13-81bcfc8708 All sessions completed
如果使用nodetool,您可以看到以下信息
XXXXX@XXXXX-asus:~/apache-cassandra-2.0.6/bin$ ./nodetool statusDatacenter: datacenter=======================Status=Up/Down|// State=Normal/Leaving/Joining/Moving-- Address Load Tokens Owns (effective) Host ID RackUN 192.168.2.102 54.74 KB 256 100.0% 0782976-b020-43a7-8fa5-b7dee95efe6fe1 rack1UN 192.168.2.103 45.75 KB 256 100.0% 80a96105-819a-40f2-ac7c-489285017de1 rack1
很明显,你可以看到所有两个节点都在线。
然后
./cassandra-cli -h 192.168.2.103 -p 9160可以操作集群数据!