「Apache Cassandra」:修訂間差異

出自Gea-Suan Lin's Wiki
跳至導覽 跳至搜尋
本頁面具有訪問限制。如果您看見此訊息,這代表您沒有訪問本頁面的權限。
行 74: 行 74:
<syntaxhighlight lang="sql">
<syntaxhighlight lang="sql">
DESCRIBE keyspaces;
DESCRIBE keyspaces;
</syntaxhighlight>
使用<code>ks1</code>然後列出table:
<syntaxhighlight lang="sql">
USE ks1;
DESCRIBE tables;
</syntaxhighlight>
</syntaxhighlight>



於 2021年8月19日 (四) 17:43 的修訂

Apache Cassandra是一套資料庫。

需求

開機就大約吃1.3GB左右,用2GB記憶體機器開機完就已經有吃到Swap了,最好是4GB記憶體,我這邊是用AWSt4g.medium跑測試環境。

安裝

先安裝OpenJDK 11:

sudo apt install -y openjdk-11-jdk; sudo apt clean

再來安裝Cassandra 4:

curl -L https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -; echo "deb http://www.apache.org/dist/cassandra/debian 40x main" | sudo tee /etc/apt/sources.list.d/cassandra.list; sudo apt update; sudo apt install -y cassandra

設定

防火牆

Port Usage Comment
7000/tcp Cluster communication
7001/tcp Cluster communication (TLS mode)
7199/tcp JMX
9042/tcp Native protocol

/etc/cassandra/cassandra.yaml

基本上一定會改的:

  • cluster_name改成自己要的名稱。
  • listen_address改成自己的IP位置(但不能是0.0.0.0,有擋),這樣外部才能連線。可以考慮直接用listen_interface
  • seeds改成第一台機器的IP位置與Port,這個參數只在第一次初始化整個Cassandra時用一次,後續的機器資訊都會存到硬碟裡。如果沒有用Cluster架構的話不需要改。

其他會改的:

  • commitlog_compression改用LZ4Compressor
  • endpoint_snitch改成Ec2Snitch或是Ec2MultiRegionSnitch,如果你的Cassandra架在AWS上。
  • hints_compression改用LZ4Compressor
  • internode_compression改成all

常用指令

cqlsh

使用cqlsh:

cqlsh cassandra-1.example.com -u root -p password

列出所有的keyspace:

DESCRIBE keyspaces;

使用ks1然後列出table:

USE ks1;
DESCRIBE tables;

其他指令

看目前Cluster的狀態:

nodetool status

連結