首页 > 其他分享 >Cassandra基础配置

Cassandra基础配置

时间:2022-11-15 21:46:41浏览次数:46  
标签:city ks1 name 配置 基础 192.168 cqlsh replication Cassandra

Cassandra基础配置

一,集群部署
# conf/cassandra.yaml
#集群名称配置,默认Test Cluster
cluster_name: 'Test Cluster' 
#种子节点配置,若为单节点也可配置为127.0.0.1
#下方示例为三节点都作为种子节点
seed_provider:
    # Addresses of hosts that are deemed contact points. 
    # Cassandra nodes use this list of hosts to find each other and learn
    # the topology of the ring.  You must change this if you are running
    # multiple nodes!
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
      parameters:
          # seeds is actually a comma-delimited list of addresses.
          # Ex: "<ip1>,<ip2>,<ip3>"
          - seeds: "192.168.150.128,192.168.150.129,192.168.150.130"
# 当前节点的监听地址, 以192.168.150.128为例
listen_address: 192.168.150.128
# listen_interface: eth0
# listen_interface_prefer_ipv6: false

#远程调用机器(rpc)地址
rpc_address: 192.168.150.128
# rpc_interface: eth1
# rpc_interface_prefer_ipv6: false

# port for Thrift to listen for clients on
rpc_port: 9160
二,集群启动
#bin文件
./cassandra
#查看集群启动
[root@master bin]$./nodetool status
#数据中心:datacenter1 ,部署位置:rack1, 环上地址个数:256
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address          Load       Tokens       Owns (effective)  Host ID                               Rack
UN  192.168.150.128  317.42 KB  256          66.0%             23db0622-72f1-4e1a-a7e2-64d8a24933de  rack1
UN  192.168.150.129  317.42 KB  256          65.2%             18eaf078-9037-410b-a563-747b676a4434  rack1
UN  192.168.150.130  319.25 KB  256          68.7%             1db719e0-620f-45c4-b08c-26613646eaab  rack1
#查看集群信息
[root@master bin]$ ./nodetool info
ID                     : 23db0622-72f1-4e1a-a7e2-64d8a24933de
Gossip active          : true
Thrift active          : false
Native Transport active: true
Load                   : 317.42 KB
Generation No          : 1668513274
Uptime (seconds)       : 147
Heap Memory (MB)       : 72.32 / 1004.00
Off Heap Memory (MB)   : 0.00
Data Center            : datacenter1
Rack                   : rack1
Exceptions             : 0
Key Cache              : entries 35, size 2.62 KB, capacity 50 MB, 65 hits, 103 requests, 0.631 recent hit rate, 14400 save period in seconds
Row Cache              : entries 0, size 0 bytes, capacity 0 bytes, 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds
Counter Cache          : entries 0, size 0 bytes, capacity 25 MB, 0 hits, 0 requests, NaN recent hit rate, 7200 save period in seconds
Token                  : (invoke with -T/--tokens to see all 256 tokens)

三,CQL和cqlsh
#进入shell
[root@master bin]$ ./cqlsh 192.168.150.128
Connected to Test Cluster at 192.168.150.128:9042.
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
cqlsh> 
#查看键空间
cqlsh> desc keyspaces;

语法说明与mysql类似

#创建键空间
create keyspace "KeySpaceName" with replication = {'class':'Strategy name', 'replication_factor':n};
# replication 包含两个属性:Stratetgy name   , replication_factor
#Stratrgy name 包含两个选项:SimpleStrategy(简单复制策略), NetworkTopologyStrategy(网络拓扑复制策略)
#SimpleStrategy(简单复制策略)
create keyspace simple_ks with replication = {'class':'SimpleStrategy','replication_factor':1};

#NetworkTopologyStrategy(网络拓扑复制策略),durable_writes = false关闭预写日志
create keyspace network_ks with replication = {'class':'NetworkTopologyStrategy','dc1':3,'dc2':2} and durable_writes = false;

#切换键空间
cqlsh:ks1> use simple_ks;

#修改键空间属性
cqlsh:ks1> alter keyspace simple_ks with replication = {'class':'NetworkTopologyStrategy','dc1':3,'dc2':2} and durable_writes = false;

#创建表 ,双主键
CREATE TABLE ks1.city_s (
    id int,
    name text,
    city text,
    phone list<text>,
    salary int,
    PRIMARY KEY (id, name)
);
#条件查询时要按主键顺序,不然报错
cqlsh:ks1> select * from city_S where name = 'tom';
InvalidRequest: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"
cqlsh:ks1> select * from city_S where id = 1 and name = 'tom';
#无索引机制下但条件查询
select * from city_S where name = 'tom' allow filtering;
#索引机制,
create index city_a on city_s(city);

#IF轻量级事务
cqlsh:ks1> insert into ks1.city_s(id,name,city,phone,salary) values(4,'cxv','zhejiang',['123314','2352525'],8000) if not exists;
四,关闭集群

标签:city,ks1,name,配置,基础,192.168,cqlsh,replication,Cassandra
From: https://www.cnblogs.com/blwx/p/16894073.html

相关文章

  • Java基础语法01
    注释注释不会被执行,属于解释代码的内容单行注释以//开头,只能注释一行文字多行注释以/开头,以/结尾,可以注释多行文字文档注释以/**开头,以*/结尾标识符Ja......
  • MySQL基础
    MySQL基础今日目标:完成MySQL的安装及登陆基本操作能通过SQL对数据库进行CRUD能通过SQL对表进行CRUD能通过SQL对数据进行CRUD1,数据库相关概念以前我们做系统,数......
  • 嵌入式-Linux基础:Windows和Linux间的文件传输方式
    首先必须安装VMWare里面的VmWareTool(1)拖拽方式:安装完之后就可以通过拖拽的方式将Windows的文件移到虚拟机里了,同样虚拟机里的也可以拖拽到Windows中。(2)设置共享文件夹......
  • JavaScript基础知识
    变量变量是数据的命名存储,我们可以用变量来保存商品、访客和其他信息。在JavaScript中创建一个变量,需要用到关键字let。例如:letmessage="hello";//将字符串hello保......
  • c语言基础认知1
    1)c语言的命名编程时给变量或者函数起的名字就是标识符。C语言的标识符是不可以随便起名字的,必须遵守一定的规则。C语言规定,标识符可以是字母(A~Z,a~z)、数字(0~9)、下划线_组......
  • IM开源项目OpenIM部署文档-从准备工作到nginx配置
    IM开源项目OpenIM部署文档-从准备工作到nginx配置2022-11-1422:27·OpenIM 一、准备工作运行环境linux系统即可,Ubuntu7.5.0-3ubuntu1~18.04最优......
  • 软件设计复习一统一建模语言基础知识(1)
    一、UML(UnifiedModelLanguage)统一建模语言是用图形、符号表达的语言,它的结构由视图、图、模型元素和通用机制四部分组成。首先视图(View)有逻辑视图、开发视图......
  • 复习java基础的第二天
    java流程控制1Scanner对象基本语法Scannerscanner=newScanner(System.in);next();一定要读取到有效字符后才可以结束输入。对输入有效字符之前遇到的空......
  • C语言基础知识
    算法结构:一、顺序结构、选择结构、循环结构;二、循环结构又分为while型、until型、for循环结构;程序流程图;结构化程序设计方法:(1)自顶向下;(2)逐步细化;(3)模块化设计;(4)结构化编码......
  • 网络编程基础
    内容概要软件开发架构架构发展趋势网络编程简介OSI七层协议各种重点协议软件开发架构软件开发架构规定了程序的请求逻辑、功能分块1.C/S架构 Client:客户端......