0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS 6.4 に Cassandra 1.2.6 を構築する

Posted at

はじめに

CentOS 6.4 環境に Cassandra 1.2.6 を tarball からインストールする手順メモを残しておく。とりあえず動作することを確認するところまで。今回は 5 台の物理サーバ (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 を使用すると起動時に SEGMENT FAULT が発生してしまう挙動が確認できたため、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" の 3 カ所を変更する。今回は 4 台の物理サーバのうち、3 台を seed とする。また "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 シェルを呼び出すだけだが、いろいろと面倒なので簡易的に作成しておく。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 で設定したどれかである必要がある。Cluster 内に seeds に設定した ノードが 1 台でもあれば良いため、次に起動するノードはどれでもかまわない。最後に付属の nodetool コマンドで Cluster の情報が取得する。

★ ノードを起動する (同様に他のサーバでも行なう)
$ 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 系で出来ることを調べたりやら、ノード障害時の挙動やらを調べていくことになると思う。ある程度ためせたら、また別記事で投稿しようと思います。

参考にした文献など

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?