Cassandra集群搭建
1、下载安装包
http://archive.apache.org/dist/cassandra/3.11.6/
apache-cassandra-3.11.6-bin.tar.gz
2、确保各机器已经配置好网络IP及hostname关闭防火墙并安装好jdk8
本次安装的机器为192.168.56.111~192.168.56.116 共6台机器
3、解压apache-cassandra-3.11.6-bin.tar.gz 至/cluster/cassandra/
4、创建所需存储目录
useradd cassandra
chmod 777 -R /cluster/cassandra
chown -R cassandra: /cluster/cassandra/apache-cassandra-3.11.6/
su - cassandra
mkdir /cluster/cassandra/data
mkdir /cluster/cassandra/commitlog
mkdir /cluster/cassandra/saved_caches
5、修改配置文件
vi /cluster/cassandra/apache-cassandra-3.11.6/conf/cassandra.yaml
修改 cassandra.yaml 配置文件,配置111~113为seeds。
192.168.56.111配置:
cluster_name: 'zipkin cassandra cluster'
data_file_directories:
- /cluster/cassandra/data
commitlog_directory: /cluster/cassandra/commitlog
saved_caches_directory: /cluster/cassandra/saved_caches
- seeds: "192.168.56.111,192.168.56.112,192.168.56.113"
listen_address: 192.168.56.111
start_rpc: true
rpc_address: 192.168.56.111
192.168.56.112配置:
cluster_name: 'zipkin cassandra cluster'
data_file_directories:
- /cluster/cassandra/data
commitlog_directory: /cluster/cassandra/commitlog
saved_caches_directory: /cluster/cassandra/saved_caches
- seeds: "192.168.56.111,192.168.56.112,192.168.56.113"
listen_address: 192.168.56.112
start_rpc: true
rpc_address: 192.168.56.112
192.168.56.113配置:
cluster_name: 'zipkin cassandra cluster'
data_file_directories:
- /cluster/cassandra/data
commitlog_directory: /cluster/cassandra/commitlog
saved_caches_directory: /cluster/cassandra/saved_caches
- seeds: "192.168.56.111,192.168.56.112,192.168.56.113"
listen_address: 192.168.56.113
start_rpc: true
rpc_address: 192.168.56.113
192.168.56.114配置:
cluster_name: 'zipkin cassandra cluster'
data_file_directories:
- /cluster/cassandra/data
commitlog_directory: /cluster/cassandra/commitlog
saved_caches_directory: /cluster/cassandra/saved_caches
- seeds: "192.168.56.111,192.168.56.112,192.168.56.113"
listen_address: 192.168.56.114
start_rpc: true
rpc_address: 192.168.56.114
192.168.56.115配置:
cluster_name: 'zipkin cassandra cluster'
data_file_directories:
- /cluster/cassandra/data
commitlog_directory: /cluster/cassandra/commitlog
saved_caches_directory: /cluster/cassandra/saved_caches
- seeds: "192.168.56.111,192.168.56.112,192.168.56.113"
listen_address: 192.168.56.115
start_rpc: true
rpc_address: 192.168.56.115
192.168.56.116配置:
cluster_name: 'zipkin cassandra cluster'
data_file_directories:
- /cluster/cassandra/data
commitlog_directory: /cluster/cassandra/commitlog
saved_caches_directory: /cluster/cassandra/saved_caches
- seeds: "192.168.56.111,192.168.56.112,192.168.56.113"
listen_address: 192.168.56.116
start_rpc: true
rpc_address: 192.168.56.116
6、linux系统文件连接数修改
vi /etc/sysctl.conf
vm.zone_reclaim_mode=0
vm.max_map_count = 262144
vm.swappiness = 1
sysctl -p
vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
7、启动
然后重启启动,先启动seed
/cluster/cassandra/apache-cassandra-3.11.6/bin/cassandra
启动完成后,可使用
/cluster/cassandra/apache-cassandra-3.11.6/bin/nodetool status
查看集群状态
[root@cassandra-1 bin]# ./nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 192.168.56.111 388.77 KiB 256 33.6% 3b9bdc01-8213-4187-b963-ebe1409abb22 rack1
UN 192.168.56.112 238.42 KiB 256 31.5% 49638809-0c16-46f5-b87e-002177644ab2 rack1
UN 192.168.56.113 156.5 KiB 256 35.1% 0fa46853-1a0a-45d0-a553-c08b05532ef1 rack1
UN 192.168.56.114 218.69 KiB 256 33.0% da86ed1c-0635-4404-b948-af04e118fa42 rack1
UN 192.168.56.115 181.74 KiB 256 36.1% c4498f24-09af-46ec-851b-d3d94e8e2713 rack1
UN 192.168.56.116 187.38 KiB 256 30.8% 29efd6eb-2a46-43ea-93f9-169745201f99 rack1
[cassandra@cassandra-1 bin]$ ./cqlsh 192.168.56.111
Connected to zipkin cassandra cluster at 192.168.56.111:9042.
[cqlsh 5.0.1 | Cassandra 3.11.6 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>
8、开机启动配制
vi /usr/lib/systemd/system/cassandra.service
添加以下内容
[Unit]
Description=Cassandra Server Service
After=network.service
[Service]
Type=simple
PIDFile=/var/run/cassandra.pid
#新建一个用户和用户组,Cassandra无法使用root账号启动
User=cassandra
#Group=cassandra
#此处为Cassandra包解压后的路径
ExecStart=/cluster/cassandra/apache-cassandra-3.11.6/bin/cassandra -f -p /var/run/cassandra.pid
StandardOutput=journal
StandardError=journal
LimitNOFILE=100000
LimitMEMLOCK=infinity
LimitNPROC=32768
LimitAS=infinity
[Install]
WantedBy=multi-user.target
#更新
systemctl systemctl daemon-reload
# 设置为开机启动
systemctl enable cassandra
在cassandra执行以下脚本
https://github.com/openzipkin/zipkin/tree/master/zipkin-storage/cassandra/src/main/resources
zipkin服务端搭建
1、创建服务器目录
mkdir /cluster
cd /cluster
mkdir zipkin
cd zipkin
2、下载zipkin.jar
https://dl.bintray.com/openzipkin/maven/io/zipkin/java/zipkin-server/2.12.9/zipkin-server-2.12.9-exec.jar
3、开机启动脚本
(zipkin用cassandra集群存储)
zipkin.sh
#!/bin/bash
nohup java -jar /cluster/zipkin/zipkin-server-2.12.9-exec.jar --STORAGE_TYPE="cassandra3" --CASSANDRA_CONTACT_POINTS="192.168.56.111,192.168.56.112,192.168.56.113" --rm -p 9411:9411 >/cluster/zipkin/log.txt &
/etc/systemd/system/zipkin.service
[Unit]
Description=zipkin
After=network.target
[Service]
Type=forking
ExecStart=/cluster/zipkin/zipkin.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
开机启动systemctl enable zipkin
启动 systemctl start zipkin