1. 程式人生 > >Cassandra 之多資料中心叢集搭建

Cassandra 之多資料中心叢集搭建

1. 叢集架構如下:

準備5臺RHL 7.2 的VM servers
模擬4臺在資料中心TJPDC,一臺在資料中心WHDRC
此次安裝的cassandra 版本是 apache-cassandra-2.2.7
資料中心 機器列表
TJPDC 192.168.1.180,192.168.1.181,192.168.1.182,192.168.1.183
WHDRC 192.168.1.190

2. 配置叢集管理工具pdsh

下載地址 https://sourceforge.net/projects/pdsh/
解壓安裝包
[[email protected] ~]$ tar -xjf pdsh-2.26.tar.bz2

3. 建立cassandra 使用者

[[email protected] ~]# useradd cassandra
[[email protected] ~]# 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的路徑

[[email protected] ~]# mkdir -p /opt/java
[[email protected] ~]# mkdir -p /opt/cassandra
[[email protected] ~]# chown -R cassandra /opt/java/
[[email protected] ~]# chown -R cassandra /opt/cassandra/
解壓安裝包
[[email protected] cassandra]$ tar -xzvf apache-cassandra-2.2.7-bin.tar.gz
[[email protected] 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 相關的目錄
[[email protected] ~]$ mkdir -p /opt/cassandra/commitlog
[[email protected] ~]$ mkdir -p /opt/cassandra/data
[[email protected] ~]$ 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_snitch GossipingPropertyFileSnitch
seed_provider seeds: “192.168.1.180,192.168.1.181,192.168.1.182,192.168.1.183”
listen_address 192.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

[[email protected] 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

[[email protected] 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. 啟動叢集

[[email protected] conf]$ cassandra

7. 檢視叢集節點狀態

[[email protected] 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