如何在Linux云服务器上安装和配置Cassandra?
常见问题
如何在Linux云服务器上安装和配置Cassandra?
2025-04-13 02:55
Linux云服务器
Linux云服务器环境下的Apache Cassandra部署指南
作为领先的分布式NoSQL数据库,Apache Cassandra以其卓越的水平扩展能力和高可用性著称。本文将详细介绍在Linux云服务器上部署Cassandra的全套流程,包含环境准备、集群配置和性能优化等关键环节。
一、环境准备
1.1 服务器需求
- 操作系统:推荐Ubuntu 20.04 LTS或CentOS 8
- 硬件配置:至少4核CPU/8GB内存/100GB SSD存储
- 网络要求:确保节点间端口7000-7001开放
1.2 依赖安装
# Ubuntu/Debian
sudo apt update
sudo apt install -y openjdk-11-jdk python2
# CentOS/RHEL
sudo yum install -y java-11-openjdk-devel python2
二、安装Cassandra
2.1 添加官方源
# Ubuntu/Debian
echo "deb https://downloads.apache.org/cassandra/debian 40x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
sudo apt update
# CentOS/RHEL
sudo yum install -y epel-release
sudo yum install -y cassandra
2.2 安装核心组件
sudo apt install -y cassandra cassandra-tools
三、集群配置
3.1 关键配置文件修改
编辑/etc/cassandra/cassandra.yaml:
cluster_name: 'MyProductionCluster'
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "192.168.1.10,192.168.1.11"
listen_address: [当前节点私有IP]
rpc_address: [当前节点私有IP]
endpoint_snitch: GossipingPropertyFileSnitch
3.2 跨数据中心配置(可选)
编辑/etc/cassandra/cassandra-rackdc.properties:
dc=DC1
rack=RAC1
四、运维管理
4.1 服务控制命令
# 启动服务
sudo systemctl start cassandra
# 设置开机自启
sudo systemctl enable cassandra
# 检查节点状态
nodetool status
4.2 基础CQL操作
cqlsh [节点IP] -u username -p password
CREATE KEYSPACE demo WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': 3};
USE demo;
CREATE TABLE users (id UUID PRIMARY KEY, name text, email text);
五、性能优化
5.1 JVM调优
修改/etc/cassandra/jvm.options:
-Xms16G
-Xmx16G
-XX:+UseG1GC
-XX:MaxGCPauseMillis=500
5.2 内核参数优化
# 增加文件描述符限制
echo "cassandra - nofile 100000" | sudo tee -a /etc/security/limits.conf
# 调整swapiness
echo 'vm.swappiness = 1' | sudo tee -a /etc/sysctl.conf
常见问题排查
- 启动失败:检查
/var/log/cassandra/system.log
- 节点不可见:验证防火墙和网络配置
- 磁盘空间不足:配置自动压缩策略
通过以上步骤,您已成功在Linux云服务器上部署了高性能Cassandra集群。建议定期进行备份和维护,确保数据安全。
Linux云服务器环境下的Apache Cassandra部署指南
作为领先的分布式NoSQL数据库,Apache Cassandra以其卓越的水平扩展能力和高可用性著称。本文将详细介绍在Linux云服务器上部署Cassandra的全套流程,包含环境准备、集群配置和性能优化等关键环节。
一、环境准备
1.1 服务器需求
- 操作系统:推荐Ubuntu 20.04 LTS或CentOS 8
- 硬件配置:至少4核CPU/8GB内存/100GB SSD存储
- 网络要求:确保节点间端口7000-7001开放
1.2 依赖安装
# Ubuntu/Debian
sudo apt update
sudo apt install -y openjdk-11-jdk python2
# CentOS/RHEL
sudo yum install -y java-11-openjdk-devel python2
二、安装Cassandra
2.1 添加官方源
# Ubuntu/Debian
echo "deb https://downloads.apache.org/cassandra/debian 40x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
sudo apt update
# CentOS/RHEL
sudo yum install -y epel-release
sudo yum install -y cassandra
2.2 安装核心组件
sudo apt install -y cassandra cassandra-tools
三、集群配置
3.1 关键配置文件修改
编辑/etc/cassandra/cassandra.yaml:
cluster_name: 'MyProductionCluster'
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "192.168.1.10,192.168.1.11"
listen_address: [当前节点私有IP]
rpc_address: [当前节点私有IP]
endpoint_snitch: GossipingPropertyFileSnitch
3.2 跨数据中心配置(可选)
编辑/etc/cassandra/cassandra-rackdc.properties:
dc=DC1
rack=RAC1
四、运维管理
4.1 服务控制命令
# 启动服务
sudo systemctl start cassandra
# 设置开机自启
sudo systemctl enable cassandra
# 检查节点状态
nodetool status
4.2 基础CQL操作
cqlsh [节点IP] -u username -p password
CREATE KEYSPACE demo WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': 3};
USE demo;
CREATE TABLE users (id UUID PRIMARY KEY, name text, email text);
五、性能优化
5.1 JVM调优
修改/etc/cassandra/jvm.options:
-Xms16G
-Xmx16G
-XX:+UseG1GC
-XX:MaxGCPauseMillis=500
5.2 内核参数优化
# 增加文件描述符限制
echo "cassandra - nofile 100000" | sudo tee -a /etc/security/limits.conf
# 调整swapiness
echo 'vm.swappiness = 1' | sudo tee -a /etc/sysctl.conf
常见问题排查
- 启动失败:检查
/var/log/cassandra/system.log
- 节点不可见:验证防火墙和网络配置
- 磁盘空间不足:配置自动压缩策略
通过以上步骤,您已成功在Linux云服务器上部署了高性能Cassandra集群。建议定期进行备份和维护,确保数据安全。
标签:
- Apache Cassandra
- Linux云服务器
- NoSQL数据库部署
- 莱卡云
