文章目录
- 一、概述
- 1.官方文档
- 2. 克隆服务器
- 3.安装准备
- 3.1.安装 JDK 11
- 3.2.安装 Python
- 3.3.下载文件
- 二、安装部署
- 1.配置 Cassandra
- 2.启动 Cassandra
- 3.关闭Cassandra
- 4.查看状态
- 5.客户端连接服务器
- 6.服务运行脚本
- 开源中间件
# Cassandra
https://iothub.org.cn/docs/middleware/
https://iothub.org.cn/docs/middleware/cassandra/cassandra-deploy/
一、概述
1.官方文档
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. 克隆服务器
# 克隆机器
# 修改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
# 安装JDK 11
# yum install java-11-openjdk -y
# java -version
# cd /usr/lib/jvm
[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
[root@cassandra cassandra]# python -V
Python 2.7.5
3.3.下载文件
# 下载 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 的数据文件夹
[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
[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
data_file_directories:
- /usr/local/apache-cassandra-4.0.1/data
- 配置 commitlog_directory
commitlog_directory: /usr/local/apache-cassandra-4.0.1/commitlog
- 配置 saved_caches_directory
saved_caches_directory: /usr/local/apache-cassandra-4.0.1/saved_caches
- 配置 RPC
rpc_address: 192.168.202.156
2.启动 Cassandra
# cd /usr/local/apache-cassandra-4.0.1/bin
# ./cassandra -R
[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
[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
ps -ef|grep cassandra
显示如图,pid 是 1818:
3.关闭Cassandra
刚才已经查到了 pid,现在可以使用命令杀掉这个pid对应的进程
kill -9 1818
4.查看状态
运行bin 目录下的 nodetool
[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 命令查看
[root@localhost bin]# journalctl -u cassandra
# 问题
[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 目录,输入
./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,输入一下内容:
#!/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
接下来就可以使用这个脚本进行 启动,重启,关闭 的操作
[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
# 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! *
- 开源中间件
# Cassandra
https://iothub.org.cn/docs/middleware/
https://iothub.org.cn/docs/middleware/cassandra/cassandra-deploy/