说明
操作系统:Ubuntu 14.04.5 LTS
Cassandra Version: 3.11.3
机器: 3台,192.168.0.100, 192.168.0.101, 192.168.0.102
更改主机名
sudo vim /etc/hostname
sudo vim /etc/hosts
192.168.0.100 cassandra-1
192.168.0.101 cassandra-2
192.168.0.102 cassandra-3
reboot
安装 OpenJDK 8
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update -y
sudo apt-get install openjdk-8-jdk -y
sudo update-alternatives --config java
sudo update-alternatives --config javac
java -version
下载 Cassandra
wget http://mirrors.tuna.tsinghua.edu.cn/apache/cassandra/3.11.3/apache-cassandra-3.11.3-bin.tar.gz
sudo mkdir -p /opt
sudo mkdir -p /data/cassandra/data
sudo mkdir -p /data/cassandra/commitlog
sudo mkdir -p /data/cassandra/saved_caches
sudo mkdir -p /data/logs/cassandra
sudo tar -xzvf ./apache-cassandra-3.11.3-bin.tar.gz -C /opt
修改环境变量
sudo vim /opt/apache-cassandra-3.11.3/conf/cassandra-env.sh
MAX_HEAP_SIZE="4G"
HEAP_NEWSIZE="800M"
JVM_OPTS="$JVM_OPTS -XX:+UseCompressedOops"
JVM_OPTS="$JVM_OPTS -Dcassandra.compaction.priority=1"
配置
以 192.168.0.100 这台机为例。
sudo vim /opt/apache-cassandra-3.11.3/conf/cassandra.yaml
修改或增加下面的选项,其中listen_address一定要本机的ip
cluster_name: 'cassandra-cluster'
data_file_directories:
- /data/cassandra/data
commitlog_directory: /data/cassandra/commitlog
saved_caches_directory: /data/cassandra/saved_caches
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "192.168.0.100,192.168.0.101"
rpc_address: 0.0.0.0
broadcast_rpc_address: 192.168.0.100
listen_address: 192.168.0.100
authenticator: PasswordAuthenticator
authorizer: CassandraAuthorizer
endpoint_snitch: GossipingPropertyFileSnitc
memtable_allocation_type: offheap_objects
sudo vim /opt/apache-cassandra-3.11.3/conf/logback.xml
<file>/data/logs/cassandra/system.log</file>
执行
-
前台运行
/opt/apache-cassandra-3.11.3/bin/cassandra -f
-
后台运行 /opt/apache-cassandra-3.11.3/bin/cassandra /opt/apache-cassandra-3.11.3/bin/cassandra -Dcassandra.ignore_dc=true
-
查看状态
/opt/apache-cassandra-3.11.3/bin/nodetool status /opt/apache-cassandra-3.11.3/bin/nodetool tpstats /opt/apache-cassandra-3.11.3/bin/nodetool cfstats
-
停止运行
ps aux | grep cassandra | grep -v grep | awk '{print $2}' | xargs -n 1 kill
-
执行CQL
/opt/apache-cassandra-3.11.3/bin/cqlsh -ucassandra -p cassandra SELECT cluster_name, listen_address FROM system.local;
-
创建用户
/opt/apache-cassandra-3.11.3/bin/cqlsh -ucassandra -p cassandra use system_auth; create user nate with password '123123' superuser; select * from resource_role_permissons_index; select * from role_permissions; select * from roles;
-
删除 cassandra 用户
/opt/apache-cassandra-3.11.3/bin/cqlsh -unate -p 123123 use system_auth; drop user cassandra; select * from resource_role_permissons_index; select * from role_permissions; select * from roles;
监控
cassandra-exporter + prometheus + grafana
https://github.com/zegelin/cassandra-exporter
vim /opt/apache-cassandra-3.11.3/conf/cassandra-env.sh
JVM_OPTS="$JVM_OPTS -javaagent:/opt/apache-cassandra-3.11.3/lib/cassandra-exporter-agent-0.9.4.jar"