Cassandra dc 配置(4 datacenter)

Cassandra dc tips:

 

1. 修改cassandra配置:

vi /etc/cassandra/conf/cassandra.yaml(参看自己的配置文件)

seeds: - seeds: "192.168.8.205"(种子地址、管理者,在种子server中和本机地址相同)

rpc_address: 192.168.8.57 (本机地址)

listen_address: 192.168.8.57(本机地址)

 

2.修改datacenter配置:

vi/etc/cassandra/conf/cassandra-rackdc.properties

dc=dc2(本机所在datacenter,建议和consuldc一致)

 

3.重启cassandra

systemctl stop cassandra

systemctl start Cassandra

systemctl status Cassandra

 

若重启失败,可能原因:

1).端口占用->关闭端口占用

2).原数据库缓存信息->

cd /data/cassandra

rm -rf */*

 

 

 

4.查看结果

nodetool status

如果成功,出现如下:

Datacenter: dc1

===============

Status=Up/Down

|/ State=Normal/Leaving/Joining/Moving

-- Address       Load      Tokens       Owns (effective)  HostID                              Rack

UN  192.168.8.205337.09 KB  256         72.4%            cb426d0c-91a6-47c7-9b99-468513d5b56a  rack1

Datacenter: dc2

===============

Status=Up/Down

|/ State=Normal/Leaving/Joining/Moving

-- Address       Load      Tokens       Owns (effective)  HostID                              Rack

UN  192.168.8.57389.75 KB  256         78.2%            2e69c22b-210d-4082-8b5d-ae93ca5039c1  rack1

Datacenter: dc3

===============

Status=Up/Down

|/ State=Normal/Leaving/Joining/Moving

--  Address       Load      Tokens       Owns (effective)  HostID                              Rack

UN  192.168.8.127364.87 KB  256         76.9%            ae6da68b-8115-4221-82cc-7e13cb20e558  rack1

Datacenter: dc4

===============

Status=Up/Down

|/ State=Normal/Leaving/Joining/Moving

-- Address       Load      Tokens       Owns (effective)  HostID                              Rack

UN 192.168.8.206 197.97 KB 256         72.5%            2b6d6438-e960-46b6-adaa-5ea21f7e61d1  rack1

 

 

其中—选线若为DN,则表示此dc已挂掉,那么需要在seed中,使用nodetool  removenode HostID 删掉此dc,并在此dc中重新开启cassandra。

 

 

5. 登陆

 

cqlsh 192.168.8.57-u[username] -p[password];

 

cassandra 默认cqlsh192.168.8.57 -ucassandra-pcassandra;

 

 

6. 修改数据库dc 策略

1).更改用户策略

通过默认用户名进入数据库 cqlsh 192.168.8.57-ucassandra -pcassandra;

alter keyspace system_auth WITH replication = {'class':'org.apache.cassandra.locator.NetworkTopologyStrategy', 'dc1': 1, 'dc2': 1,'dc3': 1, 'dc4': 1};

策略是否更改成功,可以通过以下查看:

select * from system_schema.keyspaces;

2).更改数据库策略

cqlsh 192.168.8.57-utest -ptest;

alter keyspace mykeyspace WITH replication = {'class':'NetworkTopologyStrategy', 'dc1': 1, 'dc2': 1,'dc3': 1, 'dc4': 1};

 


你可能感兴趣的:(Cassandra dc 配置(4 datacenter))