##Cassandra单节点安装
####安装包方式
#添加Cassandra依赖
echo 'deb http://www.apache.org/dist/cassandra/debian 39x main' | sudo tee --append /etc/apt/sources.list.d/cassandra.list > /dev/null
#添加源信息
curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
#更新源信息
sudo apt-get update
#执行安装命令
sudo apt-get install cassandra
#如果出现“不能满足依赖关系”错误,执行以下命令
sudo apt-get -f install
#如果出现"无法验证以下签名,因为公用密钥不可用"的错误,执行以下命令
sudo apt-key adv --keyserver pool.sks-keyservers.net --recv-key A278B781FE4B2BDA
#工具安装
sudo apt-get install cassandra-tools
####源码包方式
#下载源码包
wget http://archive.apache.org/dist/cassandra/3.9/apache-cassandra-3.9-bin.tar.gz
#解压
sudo tar -zxvf apache-cassandra-3.9-bin.tar.gz -C /opt/
#新建目录
sudo mkdir -p /data/cassandra/data
sudo mkdir -p /data/cassandra/saved_caches
sudo mkdir -p /data/cassandra/commitlog
sudo mkdir -p /data/cassandra/hints
sudo mkdir -p /data/cassandra/logs
#把目录归属改成操作用户
sudo chown -R user:user /data/cassandra/
####修改配置文件
- 修改 cassandra-env.sh
#备份配置文件
sudo cp cassandra-env.sh cassandra-env.sh.bak
#编辑配置文件
sudo vim cassandra-env.sh
#MAX_HEAP_SIZE: 生产环境建议8G*
MAX_HEAP_SIZE="150M"
#HEAP_NEWSIZE: 一般设置为MAX_HEAP_SIZE的1/4
HEAP_NEWSIZE="50M"
- 修改 cassandra.yaml
#备份配置文件
sudo cp cassandra.yaml cassandra.yaml.bak
#编辑配置文件
sudo vim cassandra.yaml
#修改hints_directory目录(72)
hints_directory: /var/lib/cassandra/hints
#修改data目录(190)
data_file_directories:
- /var/lib/cassandra/data
#修改commit log目录
commitlog_directory: /var/lib/cassandra/commitlog
#修改saved_caches_directory目录(368)
saved_caches_directory: /var/lib/cassandra/saved_caches
#修改seed_provider配置,seeds主机IP(425)
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
#Ex: "<ip1>,<ip2>,<ip3>"配置集群时配置多个IP
- seeds: "172.31.11.54"
#种子节点时listen_address必须与seeds相同,非种子节点与本机地址相同
listen_address: 172.31.11.54
#修改rpc_address
rpc_address: 0.0.0.0
#修改rpc_addressbroadcast_rpc_address,当rpc_address设置为:0.0.0.0时,必须设置broadcast_rpc_address
broadcast_rpc_address: 172.31.11.54
#修改超时时间
read_request_timeout_in_ms: 20000
range_request_timeout_in_ms: 20000
write_request_timeout_in_ms: 20000
counter_write_request_timeout_in_ms: 50000
cas_contention_timeout_in_ms: 10000
truncate_request_timeout_in_ms: 120000
request_timeout_in_ms: 60000
#修改端点的snitch
endpoint_snitch: GossipingPropertyFileSnitch
- 修改 logback.xml
<configuration scan="true">
<appender name="SYSTEMLOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<!-- 修改日志存储位置 -->
<file>/data/log/system.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<!-- 修改日志压缩位置 -->
<fileNamePattern>/data/log/system.log.%i.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>20</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>20MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%-5level [%thread] %date{ISO8601} %F:%L - %msg%n</pattern>
</encoder>
</appender>
<!-- DEBUGLOG rolling file appender to debug.log (all levels) -->
<appender name="DEBUGLOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 修改日志存储位置 -->
<file>/data/log/debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<!-- 修改日志压缩位置 -->
<fileNamePattern>/data/log/debug.log.%i.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>20</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>20MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%-5level [%thread] %date{ISO8601} %F:%L - %msg%n</pattern>
</encoder>
</appender>
</configuration>
####Cassandra启停
- 停止 Cassandra 服务
#安装包方式
sudo service cassandra stop
#源码包方式
ps -aux|grep cassandra
kill -9 PID
- 启动 Cassandra 服务
#安装包方式
sudo service cassandra start
#源码包方式
cd /etc/apache-cassandra-3.9/bin
./cassandra
- Cassandra 导入数据
./cqlsh -f xxx.cql