安装 Cassandra 数据库,要先安装 JDK
安装 JDK8
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
// 解压
tar -zxvf jdk-8u221-linux-x64.tar.gz
cd jdk1.8.0_221
这里我们使用 alternatives
来安装,如果原来装了老版本的,就会进行替换
/opt/jdk1.8.0_221
是我的文件解压目录
alternatives --install <link> <name> <path> <priority>
install表示安装
link是符号链接
name则是标识符
path是执行文件的路径
priority则表示优先级
alternatives --install /usr/bin/java java /opt/jdk1.8.0_221/bin/java 2
//选择程序
alternatives --config java
//因为之前装过,所有多个,这里我们选择3
-----------------------------------------------
共有 3 个提供“java”的程序。
选项 命令
-----------------------------------------------
+ 1 /opt/jdk-12.0.2/bin/java
* 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre/bin/java)
3 /opt/jdk1.8.0_221/bin/java
按 Enter 保留当前选项[+],或者键入选项编号:3
alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_221/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_221/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_221/bin/jar
alternatives --set javac /opt/jdk1.8.0_221/bin/javac
java -version
//装完了看一下版本信息
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
配置环境
vi + /etc/profile
// 在最后面添加
export JAVA_HOME=/opt/jdk1.8.0_221
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
//重载
source /etc/profile
安装 Cassandra 数据库
yum install https://www.apache.org/dist/cassandra/redhat/311x/cassandra-3.11.4-1.noarch.rpm
依赖关系解决
=================================================================================================================================
Package 架构 版本 源 大小
=================================================================================================================================
正在安装:
cassandra noarch 3.11.4-1 /cassandra-3.11.4-1.noarch 38 M
事务概要
=================================================================================================================================
安装 1 软件包
使用密码登陆
#修改配置文件 authenticator 项
authenticator: AllowAllAuthenticator
改为 PasswordAuthenticator
//设置文件夹权限
chown -R cassandra.cassandra /var/lib/cassandra/
//启动服务
service cassandra start
//看查看集群信息
nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 114.74 KiB 256 100.0% 547d1aa6-326a-43a3-871d-ead1f0fb132d rack1
//无密码登陆会提示没有权限
cqlsh
Connection error: ('Unable to connect to any servers', {'127.0.0.1': AuthenticationFailed('Remote end requires authentication.',)})
//使用默认用户名和密码登陆
cqlsh -ucassandra -pcassandra
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cassandra@cqlsh>
设置用户名和密码
// 创建新用户和密码
cassandra@cqlsh> CREATE USER ncc with PASSWORD '123456' SUPERUSER;
cassandra@cqlsh> quit
// 测试登陆
cqlsh -uncc -p123456
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
ncc@cqlsh>
// 删除原来的默认账号
DROP USER cassandra ;