1. 集群架构如下 准备5台RHL 7.2 的VM servers 模拟4台在数据中心TJPDC,一台在数据中心WHDRC 此次安装的cassandra 版本是 apache-cassandra-2.2.7 数据中心 机器列表 TJPDC 192.168.1.180192.168.1.181192.168.1.182192.168.1.183 WHDRC 192.168.1.190 2. 配置集群管理工具pdsh 下载地址 https://sourceforge.net/projects/pdsh/ 解压安装包 [cassandralocalhost ~]$ tar -xjf pdsh-2.26.tar.bz2 1 3. 创建cassandra 用户 [rootlocalhost ~]# useradd cassandra [rootlocalhost ~]# 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的路径 [rootlocalhost ~]# mkdir -p /opt/java [rootlocalhost ~]# mkdir -p /opt/cassandra [rootlocalhost ~]# chown -R cassandra /opt/java/ [rootlocalhost ~]# chown -R cassandra /opt/cassandra/
解压安装包 [cassandralocalhost cassandra]$ tar -xzvf apache-cassandra-2.2.7-bin.tar.gz [cassandralocalhost 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 相关的目录 [cassandralocalhost ~]$ mkdir -p /opt/cassandra/commitlog [cassandralocalhost ~]$ mkdir -p /opt/cassandra/data [cassandralocalhost ~]$ 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: ",," - 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 数据中心1TJPDC
[cassandralocalhost conf]$ vi cassandra-rackdc.properties # These properties are used with GossipingPropertyFileSnitch and will # indicate the rack and dc for this node dcTJPDC rackTJrack 数据中心2WHDRC
[cassandralocalhost conf]$ vi cassandra-rackdc.properties # These properties are used with GossipingPropertyFileSnitch and will # indicate the rack and dc for this node dcWHDRC rackWHrack 6. 启动集群 [cassandralocalhost conf]$ cassandra 1 7. 查看集群节点状态 [cassandralocalhost conf]$ nodetool status Datacenter: TJPDC StatusUp/Down |/ StateNormal/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 StatusUp/Down |/ StateNormal/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-