Linux下安装Cassandra

一、下载安装好JDK

https://blog.csdn.net/huangbaokang/article/details/79487890

二、下载Cassandra

到官网下载http://www.apache.org/dyn/closer.lua/cassandra/3.11.3/apache-cassandra-3.11.3-bin.tar.gz

[root@localhost hbk] wget http://mirrors.hust.edu.cn/apache/cassandra/3.11.3/apache-cassandra-3.11.3-bin.tar.gz

解压

[root@localhost hbk]# tar -zxvf apache-cassandra-3.11.3-bin.tar.gz 
[root@localhost hbk]# cd apache-cassandra-3.11.3
[root@localhost apache-cassandra-3.11.3]# ls
bin  CASSANDRA-14092.txt  CHANGES.txt  conf  doc  interface  javadoc  lib  LICENSE.txt  NEWS.txt  NOTICE.txt  pylib  tools

三、启动服务端

[root@localhost apache-cassandra-3.11.3]# cd bin/
[root@localhost bin]# ./cassandra -R

四、启用CQL

[root@localhost bin]# ./cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.3 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.

cqlsh> help;

Documented shell commands:
===========================
CAPTURE  CLS          COPY  DESCRIBE  EXPAND  LOGIN   SERIAL  SOURCE   UNICODE
CLEAR    CONSISTENCY  DESC  EXIT      HELP    PAGING  SHOW    TRACING

CQL help topics:
================
AGGREGATES               CREATE_KEYSPACE           DROP_TRIGGER      TEXT     
ALTER_KEYSPACE           CREATE_MATERIALIZED_VIEW  DROP_TYPE         TIME     
ALTER_MATERIALIZED_VIEW  CREATE_ROLE               DROP_USER         TIMESTAMP
ALTER_TABLE              CREATE_TABLE              FUNCTIONS         TRUNCATE 
ALTER_TYPE               CREATE_TRIGGER            GRANT             TYPES    
ALTER_USER               CREATE_TYPE               INSERT            UPDATE   
APPLY                    CREATE_USER               INSERT_JSON       USE      
ASCII                    DATE                      INT               UUID     
BATCH                    DELETE                    JSON            
BEGIN                    DROP_AGGREGATE            KEYWORDS        
BLOB                     DROP_COLUMNFAMILY         LIST_PERMISSIONS
BOOLEAN                  DROP_FUNCTION             LIST_ROLES      
COUNTER                  DROP_INDEX                LIST_USERS      
CREATE_AGGREGATE         DROP_KEYSPACE             PERMISSIONS     
CREATE_COLUMNFAMILY      DROP_MATERIALIZED_VIEW    REVOKE          
CREATE_FUNCTION          DROP_ROLE                 SELECT          
CREATE_INDEX             DROP_TABLE                SELECT_JSON     

五、相关操作

1、建立keyspace

cqlsh:hbk_space> CREATE KEYSPACE "hbk_space" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3} AND durable_writes = 'true';
cqlsh:hbk_space> DESCRIBE KEYSPACES 

system_schema  system_auth  system  system_distributed  system_traces  hbk_space

cqlsh:hbk_space> USE hbk_space ;
cqlsh:hbk_space> CREATE TABLE hbk_table(id int PRIMARY KEY ,name text ,age int,phone varint );
cqlsh:hbk_space> select * from hbk_table ;

 id | age | name | phone
----+-----+------+-------

(0 rows)
cqlsh:hbk_space> ALTER TABLE hbk_table ADD emp_address varchar ;
cqlsh:hbk_space> DESCRIBE TABLE hbk_table ;

CREATE TABLE hbk_space.hbk_table (
    id int PRIMARY KEY,
    age int,
    emp_address text,
    name text,
    phone varint
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
cqlsh:hbk_space> insert into hbk_table (id,age, emp_address , name , phone ) values(1,20,'nankang','hbk',18679758769);
cqlsh:hbk_space> select * from hbk_table  ;

 id | age | emp_address | name | phone
----+-----+-------------+------+-------------
  1 |  20 |     nankang |  hbk | 18679758769

(1 rows)

cqlsh:hbk_space> UPDATE hbk_table set emp_address = 'ganzhou' where id=1;
cqlsh:hbk_space> select * from hbk_table  ;

 id | age | emp_address | name | phone
----+-----+-------------+------+-------------
  1 |  20 |     ganzhou |  hbk | 18679758769

(1 rows)
cqlsh:hbk_space> DELETE from hbk_table where id=1;
cqlsh:hbk_space> select * from hbk_table  ;

 id | age | emp_address | name | phone
----+-----+-------------+------+-------

(0 rows)

你可能感兴趣的:(Cassandra)