CentOS7 安装 Cassandra 集群并进行压力测试

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

修改三处最重要的

  1. 所有主机的 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"
    
  2. 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
    
  3. 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 即表示 UpNormal, 此时服务已正常运行。
在这里插入图片描述


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 文件,拷贝至本机打开即可查看详细结果。
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值