1. 基础条件
- CentOS7 主机多台(本例四台)ip 分别是
172, 173, 174, 175
,其中172, 173
将作为 seed 节点 - JDK 1.8 安装包
jdk-8u221-linux-x64.tar.gz
- Cassandra 3.11.11 安装包
apache-cassandra-3.11.11-bin.tar.gz
Cassandra 官方下载
2. 环境准备
- 关闭防火墙
# 停止防火墙服务 systemctl stop firewalld # 禁止开机启动 systemctl disable firewalld
- 拷贝 jdk 和 cassandra 安装包至所有主机上
3. 安装 JDK
解压缩并移动至 /home 目录下
tar -zxvf jdk-8u221-linux-x64.tar.gz
mv jdk1.8.0_221/ /home/java
编辑 /etc/profile
文件,在末尾追加写入以下内容
export JAVA_HOME=/home/java
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport JRE_HOME=$JAVA_HOME/jre
刷新环境变量使生效
source /etc/profile
4. 安装 Cassandra
解压缩并移动至 /home 目录下
tar -zxvf apache-cassandra-3.11.11-bin.tar.gz
mv apache-cassandra-3.11.11 /home/cassandra
编辑配置文件
vi /home/cassandra/conf/cassandra.yaml
修改三处最重要的
- 所有主机的 seeds 统一修改为开头所定的
172, 173
两台主机地址# constructor that takes a Map<String, String> of parameters will do. seed_provider: # Addresses of hosts that are deemed contact points. # Cassandra nodes use this list of hosts to find each other and learn # the topology of the ring. You must change this if you are running # multiple nodes! - class_name: org.apache.cassandra.locator.SimpleSeedProvider parameters: # seeds is actually a comma-delimited list of addresses. # Ex: "<ip1>,<ip2>,<ip3>" - seeds: "172.22.190.172,172.22.190.173"
- listen_address 修改为各自所在主机的地址,例如
174
主机上的配置为# Address or interface to bind to and tell other Cassandra nodes to connect to. # You _must_ change this if you want multiple nodes to be able to communicate! # # Set listen_address OR listen_interface, not both. # # Leaving it blank leaves it up to InetAddress.getLocalHost(). This # will always do the Right Thing _if_ the node is properly configured # (hostname, name resolution, etc), and the Right Thing is to use the # address associated with the hostname (it might not be). # # Setting listen_address to 0.0.0.0 is always wrong. # listen_address: 172.22.190.174
- rpc_address 也修改为各自所在主机的地址,例如
173
主机上的配置为# The address or interface to bind the Thrift RPC service and native transport # server to. # # Set rpc_address OR rpc_interface, not both. # # Leaving rpc_address blank has the same effect as on listen_address # (i.e. it will be based on the configured hostname of the node). # # Note that unlike listen_address, you can specify 0.0.0.0, but you must also # set broadcast_rpc_address to a value other than 0.0.0.0. # # For security reasons, you should not expose this port to the internet. Firewall it if needed. rpc_address: 172.22.190.173
5. 启动 Cassandra 服务
进入 cassandra 的 bin 目录
cd /home/cassandra/bin/
启动服务(-R
参数是允许以 root
用户启动)
./cassandra -R
首先将两个 seed
节点服务启动,然后启动其他节点服务,在 seed
节点下可以使用如下命令查看集群节点状态
./nodetool status
如下图所示,集群各节点状态 UN
即表示 Up
和 Normal
, 此时服务已正常运行。
6. 使用 cassandra-stress 工具进行压力测试
我们以 173
节点作为测试入口,首先进入 tools 目录中
/home/cassandra/tools/bin
执行如下命令进行测试
./cassandra-stress write -node 172.22.190.173 -graph file=result.html
write
代表执行写入测试
-node
后面需要指定集群 seed
节点之一
-graph
代表将测试结果输出为图形化展示
file=result.html
代表将图形化展示结果存储到哪个文件中
其他更多测试选项可以使用 help 命令进行查看。
运行命令后,控制台会打印不同线程数下的测试结果
全部测试完成后即在当前目录下生成 result.html
文件,拷贝至本机打开即可查看详细结果。