Cassandra 安装部署

文章目录

shell 复制代码
# Cassandra

https://iothub.org.cn/docs/middleware/
https://iothub.org.cn/docs/middleware/cassandra/cassandra-deploy/

一、概述

1.官方文档

shell 复制代码
https://cassandra.apache.org/_/index.html
https://cassandra.apache.org/_/download.html


# 下载 cassandra-4.0.1
https://archive.apache.org/dist/cassandra/
https://archive.apache.org/dist/cassandra/4.0.1/

2. 克隆服务器

shell 复制代码
# 克隆机器

# 修改IP地址
cd /etc/sysconfig/network-scripts
vim ifcfg-ens33
192.168.202.156

# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

# 设置主机名
hostnamectl set-hostname cassandra

3.安装准备

3.1.安装 JDK 11

注意:Cassandra 使用 JAVA 语言开发,首先保证当前机器中已经安装 JDK 11

shell 复制代码
# 安装JDK 11 

# yum install java-11-openjdk -y

# java -version

# cd /usr/lib/jvm
shell 复制代码
[root@cassandra cassandra]# yum install java-11-openjdk -y


[root@cassandra cassandra]# java -version
openjdk version "11.0.22" 2024-01-16 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.22.0.7-1.el7_9) (build 11.0.22+7-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.22.0.7-1.el7_9) (build 11.0.22+7-LTS, mixed mode, sharing)


[root@cassandra cassandra]# cd /usr/lib/jvm
[root@cassandra jvm]# ll
total 0
drwxr-xr-x. 6 root root 68 Feb 28 19:22 java-11-openjdk-11.0.22.0.7-1.el7_9.x86_64
lrwxrwxrwx. 1 root root 21 Feb 28 19:22 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 24 Feb 28 19:22 jre-11 -> /etc/alternatives/jre_11
lrwxrwxrwx. 1 root root 32 Feb 28 19:22 jre-11-openjdk -> /etc/alternatives/jre_11_openjdk
lrwxrwxrwx. 1 root root 42 Feb 28 19:22 jre-11-openjdk-11.0.22.0.7-1.el7_9.x86_64 -> java-11-openjdk-11.0.22.0.7-1.el7_9.x86_64
lrwxrwxrwx. 1 root root 29 Feb 28 19:22 jre-openjdk -> /etc/alternatives/jre_openjdk
3.2.安装 Python

注意:Cassandra的客户端的使用需要用的Python2.X版本。需要先安装Python2.X

shell 复制代码
[root@cassandra cassandra]# python -V
Python 2.7.5
3.3.下载文件
shell 复制代码
# 下载 4.0.1
# wget https://archive.apache.org/dist/cassandra/4.0.1/apache-cassandra-4.0.1-bin.tar.gz


# 解压
# tar -zxvf apache-cassandra-4.0.1-bin.tar.gz

[root@cassandra cassandra]# ll
total 48248
drwxr-xr-x. 8 root root      176 Feb 28 19:09 apache-cassandra-4.0.1
-rw-r--r--. 1 root root 49404559 Feb 28 19:08 apache-cassandra-4.0.1-bin.tar.gz


# 移动文件
[root@cassandra cassandra]# mv apache-cassandra-4.0.1 /usr/local/

[root@cassandra apache-cassandra-4.0.1]# ll
total 600
drwxr-xr-x. 2 root root    230 Feb 28 19:09 bin
-rw-r--r--. 1 root root   4832 Aug 30  2021 CASSANDRA-14092.txt
-rw-r--r--. 1 root root 434601 Aug 30  2021 CHANGES.txt
drwxr-xr-x. 3 root root   4096 Feb 28 19:09 conf
drwxr-xr-x. 3 root root     33 Feb 28 19:09 doc
drwxr-xr-x. 3 root root   4096 Feb 28 19:09 lib
-rw-r--r--. 1 root root  12960 Aug 30  2021 LICENSE.txt
-rw-r--r--. 1 root root 135759 Aug 30  2021 NEWS.txt
-rw-r--r--. 1 root root    349 Aug 30  2021 NOTICE.txt
drwxr-xr-x. 3 root root    230 Feb 28 19:09 pylib
drwxr-xr-x. 4 root root    169 Feb 28 19:09 tools

二、安装部署

1.配置 Cassandra

1.进入解压后的目录,创建3个 Cassandra 的数据文件夹

shell 复制代码
[root@cassandra apache-cassandra-4.0.1]# mkdir data
[root@cassandra apache-cassandra-4.0.1]# mkdir commitlog
[root@cassandra apache-cassandra-4.0.1]# mkdir saved-caches
shell 复制代码
[root@cassandra apache-cassandra-4.0.1]# pwd
/usr/local/apache-cassandra-4.0.1
[root@cassandra apache-cassandra-4.0.1]# mkdir data
[root@cassandra apache-cassandra-4.0.1]# mkdir commitlog
[root@cassandra apache-cassandra-4.0.1]# mkdir saved-caches

2.修改配置文件

在 conf 目录中找到 cassandra.yaml 配置文件,配置上面创建的3个数据目录

  • 配置 data_file_directories
shell 复制代码
data_file_directories:
    - /usr/local/apache-cassandra-4.0.1/data
  • 配置 commitlog_directory
shell 复制代码
commitlog_directory: /usr/local/apache-cassandra-4.0.1/commitlog
  • 配置 saved_caches_directory
shell 复制代码
saved_caches_directory: /usr/local/apache-cassandra-4.0.1/saved_caches
  • 配置 RPC
shell 复制代码
rpc_address: 192.168.202.156

2.启动 Cassandra

shell 复制代码
# cd /usr/local/apache-cassandra-4.0.1/bin

# ./cassandra -R
shell 复制代码
[root@cassandra /]# cd /usr/local/apache-cassandra-4.0.1/bin
[root@cassandra bin]# ll
total 152
-rwxr-xr-x. 1 root root 10542 Aug 30  2021 cassandra
-rw-r--r--. 1 root root  5667 Aug 30  2021 cassandra.in.sh
-rwxr-xr-x. 1 root root  2995 Aug 30  2021 cqlsh
-rwxr-xr-x. 1 root root 95408 Aug 30  2021 cqlsh.py
-rwxr-xr-x. 1 root root  1894 Aug 30  2021 debug-cql
-rwxr-xr-x. 1 root root  3491 Aug 30  2021 nodetool
-rwxr-xr-x. 1 root root  1770 Aug 30  2021 sstableloader
-rwxr-xr-x. 1 root root  1778 Aug 30  2021 sstablescrub
-rwxr-xr-x. 1 root root  1778 Aug 30  2021 sstableupgrade
-rwxr-xr-x. 1 root root  1781 Aug 30  2021 sstableutil
-rwxr-xr-x. 1 root root  1778 Aug 30  2021 sstableverify
-rwxr-xr-x. 1 root root  1175 Aug 30  2021 stop-server
shell 复制代码
[root@cassandra bin]# ./cassandra -R
[root@cassandra bin]# OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
CompileCommand: dontinline org/apache/cassandra/db/Columns$Serializer.deserializeLargeSubset(Lorg/apache/cassandra/io/util/DataInputPlus;Lorg/apache/cassandra/db/Columns;I)Lorg/apache/cassandra/db/Columns;
CompileCommand: dontinline org/apache/cassandra/db/Columns$Serializer.serializeLargeSubset(Ljava/util/Collection;ILorg/apache/cassandra/db/Columns;ILorg/apache/cassandra/io/util/DataOutputPlus;)V
CompileCommand: dontinline org/apache/cassandra/db/Columns$Serializer.serializeLargeSubsetSize(Ljava/util/Collection;ILorg/apache/cassandra/db/Columns;I)I

输入命令来查看正在运行的cassandra的 pid

shell 复制代码
ps -ef|grep cassandra

显示如图,pid 是 1818:

3.关闭Cassandra

刚才已经查到了 pid,现在可以使用命令杀掉这个pid对应的进程

shell 复制代码
kill -9 1818

4.查看状态

运行bin 目录下的 nodetool

shell 复制代码
[root@localhost bin]# ./nodetool status

# nodetool -Dcom.sun.jndi.rmiURLParsing=legacy status
# ./nodetool -h ::FFFF:127.0.0.1 status

如果cassandra启动出错,可以在bin目录下 使用 journalctl -u cassandra 命令查看

shell 复制代码
[root@localhost bin]# journalctl -u cassandra
shell 复制代码
# 问题
[root@cassandra bin]# ./nodetool status
nodetool: Failed to connect to '127.0.0.1:7199' - URISyntaxException: 'Malformed IPv6 address at index 7: rmi://[127.0.0.1]:7199'.


# 解决办法
[root@cassandra bin]# ./nodetool -Dcom.sun.jndi.rmiURLParsing=legacy status
[root@cassandra bin]# ./nodetool -h ::FFFF:127.0.0.1 status

5.客户端连接服务器

进入Cassandra的 bin 目录,输入

shell 复制代码
./cqlsh 192.168.202.156 9042


[root@cassandra bin]# ./cqlsh 192.168.202.156 9042
Python 2.7 support is deprecated. Install Python 3.6+ or set CQLSH_NO_WARN_PY2 to suppress this message.

Connected to Test Cluster at 192.168.202.156:9042
[cqlsh 6.0.0 | Cassandra 4.0.1 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> 

6.服务运行脚本

为了方便管理,可以编写脚本来管理,在 /usr/local/apache-cassandra-4.0.1 下创建一个 startme.sh,输入一下内容:

shell 复制代码
#!/bin/sh
CASSANDRA_DIR="/usr/local/apache-cassandra-4.0.1"
 echo "************cassandra***************"
case "$1" in
        start)

                echo "*                                  *"
                echo "*            starting              *"
                nohup $CASSANDRA_DIR/bin/cassandra -R >> $CASSANDRA_DIR/logs/system.log 2>&1 &
                echo "*            started               *"
                echo "*                                  *"
                echo "************************************"
                ;;
        stop)

                echo "*                                  *"
                echo "*           stopping               *"
                PID_COUNT=`ps aux |grep CassandraDaemon |grep -v grep | wc -l`
                PID=`ps aux |grep CassandraDaemon |grep -v grep | awk {'print $2'}`
                if [ $PID_COUNT -gt 0 ];then
                        echo "*           try stop               *"
                        kill -9 $PID
                        echo "*          kill  SUCCESS!          *"
                else
                        echo "*          there is no !           *"
                echo "*                                  *"
                echo "************************************"
                fi
                ;;
        restart)

                echo "*                                  *"
                echo "*********     restarting      ******"
                $0 stop
                $0 start
                echo "*                                  *"
                echo "************************************"
                ;;
        status)
                $CASSANDRA_DIR/bin/nodetool status
                ;;

        *)
        echo "Usage:$0 {start|stop|restart|status}"

        exit 1
esac

接下来就可以使用这个脚本进行 启动,重启,关闭 的操作

shell 复制代码
[root@cassandra apache-cassandra-4.0.1]# ./startme.sh start
[root@cassandra apache-cassandra-4.0.1]# ./startme.sh restart
[root@cassandra apache-cassandra-4.0.1]# ./startme.sh stop
shell 复制代码
# chmod +x startme.sh


[root@cassandra apache-cassandra-4.0.1]# ./startme.sh start
************cassandra***************
*                                  *
*            starting              *
*            started               *
*                                  *
************************************
[root@cassandra apache-cassandra-4.0.1]# ./startme.sh restart
************cassandra***************
*                                  *
*********     restarting      ******
************cassandra***************
*                                  *
*           stopping               *
*           try stop               *
*          kill  SUCCESS!          *
************cassandra***************
*                                  *
*            starting              *
*            started               *
*                                  *
************************************
*                                  *
************************************
[root@cassandra apache-cassandra-4.0.1]# ./startme.sh stop
************cassandra***************
*                                  *
*           stopping               *
*           try stop               *
*          kill  SUCCESS!          *
shell 复制代码
# Cassandra

https://iothub.org.cn/docs/middleware/
https://iothub.org.cn/docs/middleware/cassandra/cassandra-deploy/
相关推荐
憧憬成为web高手1 小时前
皮卡丘靶场速通--sql 2
数据库·sql·mybatis
段一凡-华北理工大学1 小时前
向量数据库实战:选型、调优与落地~系列文章12:文本分块策略实战:chunk_size 怎么选?重叠多少?
开发语言·数据库·后端·oracle·rust·工业智能体·高炉智能化
oradh3 小时前
Oracle XTTS实现跨版本迁移和升级(Oracle 11g单库升级至19C RAC集群)
数据库·oracle·11g升级19c·xtts跨版本迁移和升级
z123456789864 小时前
2026最新两款AI编程工具深度对比实测
java·数据库·ai编程
程序猿DD4 小时前
一个 API Key,统一调用大模型、生图和联网搜索
数据库·网关
TlSfoward5 小时前
抓包代理链路下的 TLS 指纹变化分析 TLSFOWARD抓包工具
数据库·爬虫·网络协议·搜索引擎·php
数智化管理手记5 小时前
账龄分析手工统计易遗漏?自动账龄分析工具怎么搭建
大数据·网络·数据库·人工智能·数据挖掘
LabVIEW开发5 小时前
NI Package Manager安装LabVIEW时InternalServerError错误
网络·数据库·labview·labview知识·labview功能·labview程序
SelectDB6 小时前
PostgreSQL 实时同步到 Apache Doris:一站式 CDC 解决方案
数据库
欲速不达88206 小时前
Mysql并发DML锁等待的优化
数据库·mysql