最近在开发监控系统,后台存储使用了cassandra,安装的时候留个档!

准备

1
2
3
4
5
6
7
8
9
# 操作系统
3*CentOS Linux release 7.6.1810 (Core)
# java版本
[admin@db-apmDB-1 ~]$ java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
# 安装包
apache-cassandra-3.11.4-bin.tar.gz

下载

apache-cassandra-3.11.4-bin.tar.gz 下载地址

1
2
3
4
# 解压
tar -zxf  apache-cassandra-3.11.4-bin.tar.gz -C /httx/run/
# 重命名
mv apache-cassandra-3.11.4 cassandra-3.11.4

添加环境变量

1
2
3
4
5
6
7
# 打开环境变量文件
vim /etc/profile
# 添加环境变量
export CASSANDRA_HOME=/httx/run/cassandra-3.11.4
export PATH=$PATH:$CASSANDRA_HOME/bin
# 立刻生效
source /etc/profile

创建数据目录

1
2
3
4
5
6
7
8
# 数据目录
mkdir -p /httx/run/cassandra_data/data1
mkdir -p /httx/run/cassandra_data/data2
mkdir -p /httx/run/cassandra_data/data3
mkdir -p /httx/run/cassandra_data/data4
mkdir -p /httx/run/cassandra_data/data5
# commitlog目录
mkdir -p /httx/run/cassandra_data/data6

修改配置文件

1
2
cd $CASSANDRA_HOME/conf 
vim cassandra.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 设置集群名
# The name of the cluster. This is mainly used to prevent machines in
# one logical cluster from joining another.
cluster_name: 'APM Cluster'


# 设置集群种子节点IP,如果多个用逗号分隔
# seeds is actually a comma-delimited list of addresses.
          # Ex: "<ip1>,<ip2>,<ip3>"
          - seeds: "你的机器IP1,你的机器IP2,你的机器IP3"

# 设置监听地址(本机的IP),是为了其他节点能与节点进行通信(默认是 localhost),每台机器填自己机器的IP
# address associated with the hostname (it might not be).
#
# Setting listen_address to 0.0.0.0 is always wrong.
#
listen_address: 你本机IP

# 开启 thrift rpc 服务(默认是 false)
# Whether to start the thrift rpc server.
start_rpc: true

# 设置rpc的地址(默认是 localhost)
# For security reasons, you should not expose this port to the internet.  Firewall it if needed.
rpc_address: 你本机IP

# 设置数据文件所在路径(默认是在cassandra目录下的data)
# Directories where Cassandra should store data on disk.  Cassandra
# will spread data evenly across them, subject to the granularity of
# the configured compaction strategy.
# If not set, the default directory is $CASSANDRA_HOME/data/data.
data_file_directories:
     - /httx/run/cassandra_data/data1
     - /httx/run/cassandra_data/data2
     - /httx/run/cassandra_data/data3
     - /httx/run/cassandra_data/data4
     - /httx/run/cassandra_data/data5
# 设置commit log目录
# commit log.  when running on magnetic HDD, this should be a
# separate spindle than the data directories.
# If not set, the default directory is $CASSANDRA_HOME/data/commitlog.
commitlog_directory: /httx/run/cassandra_data/data6
因为这两个文件很大,分散集群中磁盘I/O压力,前者是cassandra实际数据存放的目录,后者是数据写入commitlog的文件目录

可以将上面上述修改的配置文件拷贝到其他的机器上,但是一定要修改$CASSANDRA_HOME/conf/cassandra.yaml 中的 listen_address 和 rpc_address 将其设置成自己的IP

启动

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 分别在三台上执行
cassandra

# 查看状态,现实UN为正常,DN为异常
[admin@db-apmDB-1 /httx/run/cassandra-3.11.4/bin]$ nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address      Load       Tokens       Owns (effective)  Host ID                               Rack
UN  你的ip1  431.18 KiB  256          63.9%             82bb5bf7-504b-44b6-a630-55b6f8ef1b3c  rack1
UN  你的ip2  274.44 KiB  256          68.7%             b82dd539-28bf-4934-91f1-ae48dd25cb57  rack1
UN  你的ip3  245.96 KiB  256          67.3%             a90214dc-4232-47a0-9ca3-b2ea225903cf  rack1

# cqlsh 
[admin@db-apmDB-1 ~]$ cqlsh 你的IP
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>

完成!!!