Cassandra集群配置

[color=blue]版本:apache-cassandra-1.0.6

机器1:10.16.233.27
机器2:10.16.233.41
机器3:10.16.233.45
机器4:10.16.233.36
机器5:10.16.233.39
机器6:10.16.233.66

机器1和机器2作为seed_provider
java jdk已经安装并且设置过JAVA_HOME
ssh已经设置
1.解压 apache-cassandra-1.0.6-bin.tar.gz 到/usr/cassandra 目录
设置CASSANDRA_HOME,打开profile文件
命令:vim /etc/profile
设置如下:
JAVA_HOME=/usr/java/jdk1.6.0_30
CASSANDRA_HOME=/usr/cassandra
CLASSPATH=.:$JAVA_HOME/lib:$CASSANDRA_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$CASSANDRA_HOME/bin

export JAVA_HOME
export CASSANDRA_HOME
export PATH
export CLASSPATH

2.按需要修改6台机器的conf/cassandra.yaml文件

修改conf/cassandra.yaml
2.1设置cluster_name 这里我们命名为E3E4
# The name of the cluster. This is mainly used to prevent machines in
# one logical cluster from joining another.
cluster_name: 'E3E4'

2.2设置数据文件 提交日志 缓存文件 路径
# directories where Cassandra should store data on disk.
data_file_directories:
- /usr/cassandra/data
# commit log
commitlog_directory: /usr/cassandra/commitlog
# saved caches
saved_caches_directory: /usr/cassandra/saved_caches

2.3设置endpoint_snitch
# endpoint_snitch -- Set this to a class that implements
# IEndpointSnitch, which will let Cassandra know enough
# org.apache.cassandra.locator.PropertyFileSnitch:
# - Proximity is determined by rack and data center, which are
# explicitly configured in cassandra-topology.properties.
endpoint_snitch: org.apache.cassandra.locator.PropertyFileSnitch

2.4设置init_token,注:这里要通过算法程序来计算
算法代码如下:
#! /usr/bin/python
import sys
if(len(sys.argv)>1):
num=int(sys.argv[1])
else:
num=int(raw_input(""))
for i in range(0,num):
print 'token %d:%d'%(i,(i*(2**127)/num))
计算结果(6台机器):
token 0:0
token 1:28356863910078205288614550619314017621
token 2:56713727820156410577229101238628035242
token 3:85070591730234615865843651857942052864
token 4:113427455640312821154458202477256070485
token 5:141784319550391026443072753096570088106
算好后,依据输出设置initial_token,PS initial_token冒号后有个空格。
# If blank, Cassandra will request a token bisecting the range of
# the heaviest-loaded existing node. If there is no load information
# available, such as is the case with a new cluster, it will pick
# a random token, which will lead to hot spots.
initial_token: 85070591730234615865843651857942052864

2.5设置seed_provider
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: "10.16.233.41,10.16.233.27"


2.6 设置listen_address rpc_address为本机IP,这里机器3,机器4的设置如下
机器3:
listen_address: 10.16.233.36
rpc_address: 10.16.233.36
机器4:
listen_address: 10.16.233.39
rpc_address: 10.16.233.39

2.7修改6台机器:conf/cassandra-topology.properties
# Cassandra Node IP=Data Center:Rack
10.16.233.41=DC1:RAC1
10.16.233.27=DC2:RAC1
10.16.233.45=DC1:RAC1
10.16.233.39=DC2:RAC1
10.16.233.36=DC1:RAC2
10.16.233.66=DC2:RAC2
# default for unknown nodes
default=DC1:RAC1

2.8 修改conf/log4j-server.properties 设置日志目录:/usr/cassandra/log/system.log
# rolling log file
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.maxFileSize=20MB
log4j.appender.R.maxBackupIndex=50
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n
# Edit the next line to point to your logs directory
log4j.appender.R.File=/usr/cassandra/log/system.log

3设置hosts
# vim /etc/hosts
内容如下:
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
10.16.233.41 tt.cassandra.xa.01
10.16.233.27 tt.cassandra.xa.02
10.16.233.45 tt.cassandra.xa.03
10.16.233.39 tt.cassandra.xa.04
10.16.233.36 tt.cassandra.xa.05
10.16.233.66 tt.cassandra.xa.06

4设置network
# vim /etc/sysconfig/network
内容如下:
NETWORKING=yes
HOSTNAME=tt.cassandra.xa.04

5 清空数据并且重启机器
rm -rf /usr/cassandra/data/*
rm -rf /usr/cassandra/saved_caches/*
rm -rf /usr/cassandra/commitlog/*
rm -rf /usr/cassandra/log/*
6一定要记住关闭防火墙
# iptables -F:关闭防火

启动Cassandra 并查看:
#在cassandra的bin目录,10.16.233.39是本机IP
# ./nodetool -h 10.16.233.39 ring

[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值