wget http://apache.mirrors.hoobly.com/cassandra/3.11.5/apache-cassandra-3.11.5-bin.tar.gz
# 准备三台节点
192.168.100.226
192.168.100.227
192.168.100.228
# ansible配置
# 因为是测试环境,这里就直接配置密码,不去麻烦的配置免密验证了。
[root@master ~]# cat /etc/ansible/hosts
[casd]
192.168.100.226 ansible_ssh_user='root' ansible_ssh_pass='test123'
192.168.100.227 ansible_ssh_user='root' ansible_ssh_pass='test123'
192.168.100.228 ansible_ssh_user='root' ansible_ssh_pass='test123'
# 创建用户
ansible casd -m user -a "name=cassandra state=present"
# 修改密码
ansible casd -m shell -a "echo cassandra | passwd --stdin cassandra"
# 将cassandra二进制包拷贝到部署节点上。
ansible casd -m copy -a "src=apache-cassandra-3.11.5.tar.gz dest=/home/cassandra/apache-cassandra-3.11.5.tar.gz"
# 解压源码包
ansible casd -m shell -a "cd /home/cassandra/; tar -zxvf apache-cassandra-3.11.5.tar.gz"
# 拷贝jdk至部署节点
ansible casd -m copy -a "src=java-1.8.0-amazon-corretto-devel-1.8.0_212.b04-2.x86_64.rpm dest=/root"
# 安装jdk
ansible casd -m shell -a "yum install -y java-1.8.0-amazon-corretto-devel-1.8.0_212.b04-2.x86_64.rpm"
# 验证jdk
``` bash
[root@localhost ~]# java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment Corretto-8.212.04.2 (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM Corretto-8.212.04.2 (build 25.212-b04, mixed mode)
# 切换用户
[root@localhost ~]# su - cassandra
Last login: Fri Dec 6 04:27:53 EST 2019 on pts/1
# 配置环境变量
[cassandra@localhost ~]$ vi .bash_profile
export CASSANDRA_HOME=/home/cassandra/apache-cassandra-3.11.5
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-amazon-corretto
export PATH=$JAVA_HOME/bin:$CASSANDRA_HOME/bin:$PATH
# 加载环境变量
[cassandra@localhost ~]$ source .bash_profile
修改配置文件 /home/cassandra/apache-cassandra-3.11.5/conf/cassandra.yaml
cluster_name: 'test'
data_file_directories:
- /home/cassandra/apache-cassandra-3.11.5/data
commitlog_directory: /home/cassandra/apache-cassandra-3.11.5/data/commitlog
saved_caches_directory: /home/cassandra/apache-cassandra-3.11.5/data/saved_caches
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "192.168.100.226" # 因子
listen_address: 192.168.100.226 # 监听地址,不可以为127.0.0.1
start_rpc: true
rpc_address: 192.168.100.226 # rpc监听地址,不可以为127.0.0.1
各节点的 listen_address
和 rpc_address
需要按节点配置,且不能使用 localhost
,因子 seeds
配置为第一个启动的节点。
First Node
--------------
seeds: "192.168.100.226"
listen_address: 192.168.100.226
rpc_address: 192.168.100.226
Second Node
---------------
seeds: "192.168.100.226"
listen_address: 192.168.100.227
rpc_address: 192.168.100.227
Third Node
---------------
seeds: "192.168.100.226"
listen_address: 192.168.100.228
rpc_address: 192.168.100.228
# 先启动226, 使用-f选项启动在前台
/home/cassandra/apache-cassandra-3.11.5/bin/cassandra
# 再启动其余的节点
/home/cassandra/apache-cassandra-3.11.5/bin/cassandra
/home/cassandra/apache-cassandra-3.11.5/bin/cassandra
使用 nodetool status
验证服务
[cassandra@localhost ~]$/home/cassandra/apache-cassandra-3.11.5/bin/nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 192.168.100.226 302.76 KiB 256 69.2% 723cb923-d19c-4dea-8124-c4503dab4d75 rack1
UN 192.168.100.227 295.05 KiB 256 66.3% 5bbeeb09-9bf4-4e45-a7a1-168e4f87186f rack1
UN 192.168.100.228 239.96 KiB 256 64.5% 78677dd0-797e-45b0-a34a-23842927af35 rack1
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。