Cassandra 之多数据中心集群搭建

1. 集群架构如下:

准备5台RHL 7.2 的VM servers
模拟4台在数据中心TJPDC,一台在数据中心WHDRC
此次安装的cassandra 版本是 apache-cassandra-2.2.7
数据中心机器列表
TJPDC192.168.1.180,192.168.1.181,192.168.1.182,192.168.1.183
WHDRC192.168.1.190

2. 配置集群管理工具pdsh

下载地址 https://sourceforge.net/projects/pdsh/
解压安装包
[cassandra@localhost ~]$ tar -xjf pdsh-2.26.tar.bz2

3. 创建cassandra 用户

[root@localhost ~]# useradd cassandra
[root@localhost ~]# passwd cassandra
Changing password for user cassandra.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
passwd: all authentication tokens updated successfully.

4. 创建JAVA_HOME和CASSANDRA_HOME的路径

[root@localhost ~]# mkdir -p /opt/java
[root@localhost ~]# mkdir -p /opt/cassandra
[root@localhost ~]# chown -R cassandra /opt/java/
[root@localhost ~]# chown -R cassandra /opt/cassandra/

解压安装包
[cassandra@localhost cassandra]$ tar -xzvf apache-cassandra-2.2.7-bin.tar.gz
[cassandra@localhost java]$ tar -xzvf jdk-8u162-linux-x64.tar.gz
设置环境变量
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
JAVA_HOME=/opt/java/jdk1.8.0_162
CASSANDRA_HOME=/opt/cassandra/apache-cassandra-2.2.7


PATH=$JAVA_HOME/bin:$CASSANDRA_HOME/bin:$PATH:$HOME/.local/bin:$HOME/bin

export PATH

5. 配置cassandra 集群信息

创建data file ,commit log file and cached files 相关的目录
[cassandra@localhost ~]$ mkdir -p /opt/cassandra/commitlog
[cassandra@localhost ~]$ mkdir -p /opt/cassandra/data
[cassandra@localhost ~]$ mkdir -p /opt/cassandra/saved_caches
修改cassandra 的配置文件 $CASSANDRA_HOME/conf/cassandra.yaml
参数名称指定值
data_file_directories/opt/cassandra/data
saved_caches_directory/opt/cassandra/saved_caches
commitlog_directory/opt/cassandra/commitlog
data_file_directories/opt/cassandra/data
cluster_name‘Cassandra Cluster’
endpoint_snitchGossipingPropertyFileSnitch
seed_providerseeds: “192.168.1.180,192.168.1.181,192.168.1.182,192.168.1.183”
listen_address192.168.1.18(0,1,2,3),192.168.1.190
cluster_name: 'Cassandra Cluster'
data_file_directories:
    - /opt/cassandra/data
commitlog_directory: /var/lib/cassandra/commitlog
saved_caches_directory: /opt/cassandra/saved_caches
endpoint_snitch: GossipingPropertyFileSnitch
seed_provider:
    # Addresses of hosts that are deemed contact points.
    # Cassandra nodes use this list of hosts to find each other and learn
    # the topology of the ring.  You must change this if you are running
    # multiple nodes!
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
      parameters:
          # seeds is actually a comma-delimited list of addresses.
          # Ex: "<ip1>,<ip2>,<ip3>"
          - seeds: "192.168.1.180,192.168.1.181,192.168.1.182,192.168.1.183"
listen_address: 192.168.1.180
修改数据中心信息 cassandra-rackdc.properties

数据中心1:TJPDC

[cassandra@localhost conf]$ vi cassandra-rackdc.properties
# These properties are used with GossipingPropertyFileSnitch and will
# indicate the rack and dc for this node
dc=TJPDC
rack=TJrack

数据中心2:WHDRC

[cassandra@localhost conf]$ vi cassandra-rackdc.properties
# These properties are used with GossipingPropertyFileSnitch and will
# indicate the rack and dc for this node
dc=WHDRC
rack=WHrack

6. 启动集群

[cassandra@localhost conf]$ cassandra

7. 查看集群节点状态

[cassandra@localhost conf]$ nodetool status
Datacenter: TJPDC
=================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address        Load       Tokens       Owns (effective)  Host ID                               Rack
UN  192.168.1.180  84.71 KB   256          41.2%             46df8118-75a7-4981-9981-e88648b0cee6  TJrack
UN  192.168.1.181  67.76 KB   256          41.9%             1f323b75-4e6c-41bc-9539-c03228fd82d3  TJrack
UN  192.168.1.182  84.74 KB   256          37.1%             80e51164-b528-498d-9452-422f0d2c67ec  TJrack
UN  192.168.1.183  67.7 KB    256          39.1%             3fefac26-a193-40ba-9d84-3b2cdb9527ca  TJrack
Datacenter: WHDRC
=================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address        Load       Tokens       Owns (effective)  Host ID                               Rack
UN  192.168.1.190  67.78 KB   256          40.7%             ba843b11-6db6-4a82-9ac4-febc229e82da  WHrack
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值