cassandra集群环境搭建——注意seeds节点,DHT p2p集群管理难道初始化都应如此吗?

解压cassandra的安装包后可以查看主要的配置文件,都在conf/目录下,conf/cassandra.yaml比较重要,其中需要着重注意的有以下一些配置项:

复制代码
cluster_name: 'TC01'
num_tokens: 256
seed_provider:
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
      parameters:
          - seeds: "192.168.2.103"
listen_address: 192.168.2.103
rpc_address: 192.168.2.103
endpoint_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非常类似,要改动配置里面的seeds那一项的ip为节点1的ip

复制代码
cluster_name: 'TC01'
num_tokens: 256
seed_provider:
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
      parameters:
          - seeds: "192.168.2.103"
listen_address: 192.168.2.102
rpc_address: 192.168.2.102
endpoint_snitch: SimpleSnitch
复制代码

以同样的方式启动节点2,就可以在节点1中看到节点2已经加入到集群。此时,节点1的log中可以看到以下信息

复制代码
 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-81bcfc870408] Received streaming plan for Bootstrap
 INFO 17:36:54,336 [Stream #24d92630-c2ef-11e3-9d13-81bcfc870408] Session with /192.168.2.102 is complete
 INFO 17:36:54,586 [Stream #24d92630-c2ef-11e3-9d13-81bcfc870408] All sessions completed
复制代码

如果用nodetool来看,可以看到以下信息

复制代码
XXXXX@XXXXX-asus:~/apache-cassandra-2.0.6/bin$ ./nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address        Load       Tokens  Owns (effective)  Host ID                               Rack
UN  192.168.2.102  54.74 KB   256     100.0%            00782976-b020-43a7-8fa5-b7dee95e6f1e  rack1
UN  192.168.2.103  45.75 KB   256     100.0%            80a96105-819a-40f2-ac7c-489285017de1  rack1
复制代码

很清楚的可以看到2个节点全部在线。

然后

 ./cassandra-cli -h 192.168.2.103 -p 9160

就可以去操作集群数据了!
posted @ 2017-01-18 19:19  bonelee  阅读(2454)  评论(2编辑  收藏  举报