Skip to content

Cassandra on Ubuntu

Published: at 00:00
说明
操作系统: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>
执行
监控
	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"