Cassandra集群配置
生活随笔
收集整理的這篇文章主要介紹了
Cassandra集群配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
版本: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
[root@tt bin]# 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
[root@tt bin]# 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一定要記住關閉防火墻
[root@tt bin]# iptables -F:關閉防火
啟動Cassandra 并查看:
#在cassandra的bin目錄,10.16.233.39是本機IP
[root@tt bin]# ./nodetool -h 10.16.233.39 ring
機器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
[root@tt bin]# 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
[root@tt bin]# 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一定要記住關閉防火墻
[root@tt bin]# iptables -F:關閉防火
啟動Cassandra 并查看:
#在cassandra的bin目錄,10.16.233.39是本機IP
[root@tt bin]# ./nodetool -h 10.16.233.39 ring
轉載于:https://www.cnblogs.com/jeriffe/archive/2011/12/23/2299382.html
總結
以上是生活随笔為你收集整理的Cassandra集群配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MyEclipse+Tomcat 启动时
- 下一篇: 程序员在群询问破解软件