Cassandra集群搭建
1谢揪、下載安裝包
http://archive.apache.org/dist/cassandra/3.11.6/
apache-cassandra-3.11.6-bin.tar.gz
2、確保各機器已經(jīng)配置好網(wǎng)絡IP及hostname關(guān)閉防火墻并安裝好jdk8
本次安裝的機器為192.168.56.111~192.168.56.116 共6臺機器
3著恩、解壓apache-cassandra-3.11.6-bin.tar.gz 至/cluster/cassandra/
4洒嗤、創(chuàng)建所需存儲目錄
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系統(tǒng)文件連接數(shù)修改
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
查看集群狀態(tài)
[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
添加以下內(nèi)容
[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執(zhí)行以下腳本
https://github.com/openzipkin/zipkin/tree/master/zipkin-storage/cassandra/src/main/resources
zipkin服務端搭建
1低矮、創(chuàng)建服務器目錄
mkdir /cluster
cd /cluster
mkdir zipkin
cd zipkin
2、下載zipkin.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