CentOS7 cassandra安装与测试

2020-08-06 19:27:11 浏览数 (1)

代码语言:javascript复制
3节点分别安装(192.168.6.117,192.168.6.118,192.168.6.119)

#下载
http://mirrors.hust.edu.cn/apache/cassandra/3.11.7/apache-cassandra-3.11.7-bin.tar.gz

tar -xvf apache-cassandra-3.11.7-bin.tar.gz -C /opt
cd /opt/apache-cassandra-3.11.7/

sed -i 's$#MAX_HEAP_SIZE="4G"$MAX_HEAP_SIZE="2G"$g' /opt/apache-cassandra-3.11.7/conf/cassandra-env.sh
sed -i 's$#HEAP_NEWSIZE="800M"$HEAP_NEWSIZE="400M"$g' /opt/apache-cassandra-3.11.7/conf/cassandra-env.sh
sed -i 's$Test Cluster$cx cluster$g' /opt/apache-cassandra-3.11.7/conf/cassandra.yaml
sed -i 's$start_rpc: false$start_rpc: true$g' /opt/apache-cassandra-3.11.7/conf/cassandra.yaml

#节点分配:192.168.6.117,192.168.6.118分配为seeds,三节点配置完全一样
sed -i 's$seeds: "127.0.0.1"$seeds: "192.168.6.117,192.168.6.118"$g' /opt/apache-cassandra-3.11.7/conf/cassandra.yaml

#下面两步替换为当前节点ip
sed -i 's$listen_address: localhost$listen_address: 192.168.6.117$g' /opt/apache-cassandra-3.11.7/conf/cassandra.yaml
sed -i 's$rpc_address: localhost$rpc_address: 192.168.6.117$g' /opt/apache-cassandra-3.11.7/conf/cassandra.yaml

启动

#先启动seeds节点(192.168.6.117,192.168.6.118)再启动非seeds节点
/opt/apache-cassandra-3.11.7/bin/cassandra -R

#查看集群状态
/opt/apache-cassandra-3.11.7/bin/nodetool status
如果集群中任意节点状态不是UN,则查看日志:
tail -f  /opt/apache-cassandra-3.11.7/logs/system.log
测试

#连接到Cassandra
/opt/apache-cassandra-3.11.7/bin/cqlsh 192.168.6.117

Connected to cx cluster at 192.168.6.117:9042.
[cqlsh 5.0.1 | Cassandra 3.11.7 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> CREATE SCHEMA testdb WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };
cqlsh> use testdb;
cqlsh:testdb> CREATE TABLE ack_message_status (messageId varchar PRIMARY KEY,totalNum int, unreadNum int, sendTime timestamp);
cqlsh:testdb> 

设置为开机启动

cat >/usr/lib/systemd/system/cassandra.service <<"EOF"
[Unit]  
Description=Cassandra Server Service  
After=network.service  
  
[Service]
Type=simple
PIDFile=/var/run/cassandra.pid    
ExecStart=/opt/apache-cassandra-3.11.7/bin/cassandra -R -f -p /var/run/cassandra.pid  
StandardOutput=journal  
StandardError=journal  
LimitNOFILE=100000  
LimitMEMLOCK=infinity  
LimitNPROC=32768  
LimitAS=infinity  
  
[Install]  
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable cassandra

0 人点赞