使用CentOS 6.4构建Cassandra 1.2.6
首先
我們在 CentOS 6.4 環境下使用 tarball 安裝 Cassandra 1.2.6,以下是安裝步驟備忘錄。在確保基本運作後,我們會先使用五台物理伺服器(10.0.0。[1-5])並進行 CentOS 6.4 的乾淨安裝。
★ Kernel を確認する
$ uname -a
Linux localhost 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
★ ディストリビューションを確認する
$ cat /etc/redhat-release
CentOS release 6.4 (Final)
安装
安装Cassandra所需的Java。在本次安装的Cassandra 1.2.6版本中,发现使用OpenJDK-1.6.0_0在启动时会出现段错误的情况,因此使用由Oracle提供的SunJDK 1.6.0_45。
★ SunJDK をインストールする
$ chmod +x ./jdk-6u45-linux-x64-rpm.bin && sudo ./jdk-6u45-linux-x64-rpm.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u45-linux-amd64.rpm
inflating: sun-javadb-common-10.6.2-1.1.i386.rpm
inflating: sun-javadb-core-10.6.2-1.1.i386.rpm
inflating: sun-javadb-client-10.6.2-1.1.i386.rpm
inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm
inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm
inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm
準備中... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
Installing JavaDB
準備中... ########################################### [100%]
1:sun-javadb-common ########################################### [ 17%]
2:sun-javadb-core ########################################### [ 33%]
3:sun-javadb-client ########################################### [ 50%]
4:sun-javadb-demo ########################################### [ 67%]
5:sun-javadb-docs ########################################### [ 83%]
6:sun-javadb-javadoc ########################################### [100%]
Done.
★ バージョンを確認する
$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
可以安装Cassandra。安装可以使用DataStax提供的RPM,但是由于Cassandra经常需要单独应用补丁,所以最好避免,本次安装将从tarball安装到/opt/cassandra目录下。
★ tarball をダウンロードする
$ wget http://www.fightrice.com/mirrors/apache/cassandra/1.2.6/apache-cassandra-1.2.6-bin.tar.gz
★ 展開後に /opt/cassandra 以下に移動する
$ tar xvzf apache-cassandra-1.2.6-bin.tar.gz && sudo mv ./apache-cassandra-1.2.6 /opt/ && sudo ln -s /opt/apache-cassandra-1.2.6 /opt/cassandra
★ ログとデータディレクトリを作成する
$ sudo mkdir -p /var/log/cassandra && sudo mkdir -p /var/lib/cassandra
设定
配置Cassandra。为了暂时使其工作,需要更改三个位置的 “seeds”、”listen_address” 和 “rpc_address”。本次设置中,将使用四台物理服务器中的三台作为种子节点。此外,”listen_address”需要指定能够互相连接的IP地址。
★ 設定を変更する (サーバ 10.0.0.1 の場合の設定例)
$ sudo vim /opt/cassandra/conf/cassandra.yaml
... (snip) ...
# any class that implements the SeedProvider interface and has a
# constructor that takes a Map<String, String> of parameters will do.
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.0.0.1, 10.0.0.2, 10.0.0.3"
... (snip) ...
# Address to bind to and tell other Cassandra nodes to connect to. You
# _must_ change this if you want multiple nodes to be able to
# communicate!
#
# Leaving it blank leaves it up to InetAddress.getLocalHost(). This
# will always do the Right Thing _if_ the node is properly configured
# (hostname, name resolution, etc), and the Right Thing is to use the
# address associated with the hostname (it might not be).
#
# Setting this to 0.0.0.0 is always wrong.
listen_address: 10.0.0.1
... (snip) ...
# The address to bind the Thrift RPC service to -- clients connect
# here. Unlike ListenAddress above, you _can_ specify 0.0.0.0 here if
# you want Thrift to listen on all interfaces.
#
# Leaving this blank has the same effect it does for ListenAddress,
# (i.e. it will be based on the configured hostname of the node).
rpc_address: 0.0.0.0
... (snip) ...
创建一个启动脚本来启动Cassandra。实际上只需要调用 /opt/cassandra/bin/cassandra shell,但是由于一些繁琐的操作,我们可以先简单地创建一个脚本。通过文件管理Cassandra的PID,并将标准输出和标准错误输出重定向到日志文件中。
★ 起動スクリプトを作成する
$ sudo cat << 'EOS' > /etc/init.d/cassandra && sudo chmod +x /etc/init.d/cassandra
#!/bin/sh
CASSANDRA_ROOT_DIR=/opt/cassandra
CASSANDRA_BIN_DIR=${CASSANDRA_ROOT_DIR}/bin
CASSANDRA_LOG_DIR=/var/log/cassandra
CASSANDRA_RUN_DIR=/var/run/cassandra
case "$1" in
start)
if [ ! -d ${CASSANDRA_LOG_DIR} ]; then
mkdir ${CASSANDRA_LOG_DIR}
fi
if [ ! -d ${CASSANDRA_RUN_DIR} ]; then
mkdir ${CASSANDRA_RUN_DIR}
fi
if [ -e ${CASSANDRA_RUN_DIR}/cassandra.pid ]; then
if [ 1 -ne $(ps $(cat ${CASSANDRA_RUN_DIR}/cassandra.pid) | wc -l) ]; then
echo "NG: already running (pid=$(cat ${CASSANDRA_RUN_DIR}/cassandra.pid))"
exit 1
fi
fi
${CASSANDRA_BIN_DIR}/cassandra -p ${CASSANDRA_RUN_DIR}/cassandra.pid >> ${CASSANDRA_LOG_DIR}/cassandra.log 2>&1
echo "OK: running cassandra (pid=$(cat ${CASSANDRA_RUN_DIR}/cassandra.pid))"
;;
stop)
kill $(cat ${CASSANDRA_RUN_DIR}/cassandra.pid)
echo "OK: stopped cassandra"
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "Usage: `basename $0` start|stop|restart"
esac
exit 0
EOS
确认动作
启动Cassandra节点。首先要启动的节点必须是通过seeds参数设置的任何一个节点。只要集群中有任何一个节点被设置为seeds节点,接下来要启动的节点可以是任意一个。最后可以使用附带的nodetool命令获取集群的信息。
★ ノードを起動する (同様に他のサーバでも行なう)
$ sudo /etc/init.d/cassandra start
OK: running cassandra (pid=24225)
★ 接続されているノードのステータスを表示する
$ /opt/cassandra/bin/nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Owns (effective) Host ID Token Rack
UN 10.0.0.1 76.43 KB 35.2% 52bdee4a-d815-4bf5-9795-9cb4c489a6f7 6225635841253981655 rack1
UN 10.0.0.2 68.81 KB 8.5% 1d9329f3-3632-4697-bb2c-a96a3d306d0d -263408352895507995 rack1
UN 10.0.0.3 50.6 KB 4.2% a46cc725-9a32-42a8-9290-e9c721769221 -2605039640550962807 rack1
UN 10.0.0.4 62.12 KB 47.9% b6fd7064-6da8-436e-ae53-1190f18ebcf9 -3385583403102781077 rack1
UN 10.0.0.5 78.88 KB 4.2% cb379e54-a0ec-42ce-a77e-98271502f4eb -1824495877999144536 rack1
★ 接続されているノードのリングを表示する
$ /opt/cassandra/bin/nodetool ring
Datacenter: datacenter1
==========
Replicas: 1
Address Rack Status State Load Owns Token
-1824495877999144536
10.0.0.1 rack1 Up Normal 76.43 KB 35.18% 6225635841253981655
10.0.0.2 rack1 Up Normal 68.81 KB 8.46% -263408352895507995
10.0.0.3 rack1 Up Normal 50.6 KB 4.23% -2605039640550962807
10.0.0.4 rack1 Up Normal 62.12 KB 47.90% -3385583403102781077
10.0.0.5 rack1 Up Normal 78.88 KB 4.23% -1824495877999144536
★ 接続されているノードの情報を表示する
$ /opt/cassandra/bin/nodetool info
Token : 6225635841253981655
ID : 52bdee4a-d815-4bf5-9795-9cb4c489a6f7
Gossip active : true
Thrift active : true
Load : 76.43 KB
Generation No : 1373623266
Uptime (seconds) : 1331
Heap Memory (MB) : 123.28 / 3696.00
Data Center : datacenter1
Rack : rack1
Exceptions : 0
Key Cache : size 824 (bytes), capacity 104857600 (bytes), 24 hits, 34 requests, 0.706 recent hit rate, 14400 save period in seconds
Row Cache : size 0 (bytes), capacity 0 (bytes), 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds
最后
暂时先在CentOS 6.4上成功安装了Cassandra 1.2.6。接下来我会调查Cassandra 1.2系列的功能,还有在节点故障时的行为。一旦有一定的结果,我会考虑在另一篇文章中发布。
参考文献等
-
- Datastax Apache Cassandra 1.2
-
- Apache Cassandra 1.1.0のインストールと動作確認
-
- Cassandraセットアップ
-
- Apache CassandraでNoSQLに挑戦 前編
-
- Cassandraメモその1(インストール、データモデル、データ操作について)
- Cassandra の自動起動 Shellscript