`
sillycat
  • 浏览: 2540933 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Apache Cassandra 2019 Cluster

 
阅读更多
Apache Cassandra 2019 Cluster

Haha, it looks like continues hash to form the cluster and replica the data in nodes.

Try to Set Up Cassandra Manually
> wget http://mirrors.ibiblio.org/apache/cassandra/3.11.4/apache-cassandra-3.11.4-bin.tar.gz
Unzip and place in the working directory
> sudo ln -s /home/carl/tool/apache-cassandra-3.11.4 /opt/cassandra-3.11.4
> sudo ln -s /opt/cassandra-3.11.4 /opt/cassandra

Add the Cassandra to the Path
export PATH="/opt/cassandra/bin:$PATH"

Some important configurations in conf/cassandra.yaml
cluster_name: 'SillycatCluster'
- seeds: "ubuntu-master"
listen_address: ubuntu-master
native_transport_port: 9042
rpc_address: ubuntu-master

Command to start cassandra
> bin/cassandra -f

Check the status on ubuntu-master
> nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address         Load       Tokens       Owns (effective)  Host ID                               Rack
UN  192.168.56.101  103.66 KiB  256          100.0%            19b79248-63e2-4749-bf9d-5081f3d3ada0  rack1

Do the similar on ubuntu-dev2 and ubuntu-dev4
> wget http://mirrors.ibiblio.org/apache/cassandra/3.11.4/apache-cassandra-3.11.4-bin.tar.gz
Unzip and place in right directory, add to PATH

Change the conf/cassandra.yaml as follow:
cluster_name: 'SillycatCluster'
- seeds: "ubuntu-master"
listen_address: ubuntu-dev2 or listen_address: ubuntu-dev4
native_transport_port: 9042
rpc_address: ubuntu-dev2 or rpc_address: ubuntu-dev4

Start that and you can see this from ubuntu-master
> bin/cassandra -f

Check status
> nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address         Load       Tokens       Owns (effective)  Host ID                               Rack
UN  192.168.56.3    45.66 KiB  256          100.0%            5a91cb7e-0b4d-487a-b2bc-a5e13e26887a  rack1
UN  192.168.56.101  108.61 KiB  256          100.0%            19b79248-63e2-4749-bf9d-5081f3d3ada0  rack1

3 nodes will be like this
> nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address         Load       Tokens       Owns (effective)  Host ID                               Rack
UN  192.168.56.3    93.96 KiB  256          65.2%             5a91cb7e-0b4d-487a-b2bc-a5e13e26887a  rack1
UN  192.168.56.101  108.61 KiB  256          70.1%             19b79248-63e2-4749-bf9d-5081f3d3ada0  rack1
UN  192.168.56.103  26.22 KiB  256          64.7%             11aa7d21-7ce3-48dd-8921-e196feb74f42  rack1

Use my other machine to connect to the cluster
> cqlsh ubuntu-master 9042

Create the test key space
> CREATE KEYSPACE patient WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 2};

Create table to store the data
sillycat@cqlsh> CREATE TABLE patient.exam (
   ... patient_id int,
   ... id int,
   ... date timeuuid,
   ... details text,
   ... PRIMARY KEY (patient_id, id));

Insert some test data from other people’s blog
> INSERT INTO patient.exam (patient_id,id,date,details) values (1,1,now(),'first exam patient 1');
> INSERT INTO patient.exam (patient_id,id,date,details) values (1,2,now(),'second exam patient 1');
> INSERT INTO patient.exam (patient_id,id,date,details) values (2,1,now(),'first exam patient 2');
> INSERT INTO patient.exam (patient_id,id,date,details) values (3,1,now(),'first exam patient 3');

Query all the records for patient 1
> use patient;
> select * from exam where patient_id=1;

Connect to node ubuntu-dev2
> cqlsh ubuntu-dev2 9042
> desc keyspaces;
patient  system_schema  system_auth  system  system_distributed  system_traces

> use patient;

You can see the same data there with the same commands
> select * from exam where patient_id=1;

The cluster works pretty well.

Seed is the contact nodes we need when other nodes start.

References:
https://sillycat.iteye.com/blog/2011992
https://www.ibm.com/developerworks/cn/opensource/ba-set-up-apache-cassandra-architecture/index.html



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics