RedisをCentOSにインストールして起動スクリプトを書いてみた

| コメント(0) | トラックバック(1) | RedisをCentOSにインストールして起動スクリプトを書いてみた | この記事をはてなブックマークに登録 このエントリのはてなブックマーク数

自分用にメモ。

Key-Value StorageのRedisを試してみた。

インストールは簡単で起動も簡単だけど、サーバリブート時にどうしよう?と思って探してみたら Redis 起動時 Tips というサイトがあったので、参考にさせていただきながらCentOSの起動時のスクリプトに登録するところまで書いてみた。

インストール

インストール(コンパイル)はQuickStartどおり。

私の環境の場合は、makeしたあとそのディレクトリを/usr/local/lib/redisに置いてみた。(あってるのかな?)

続きには、confファイルや起動スクリプト、CentOSの起動時スクリプトへの登録について書いてます。

redis.conf

起動時にデーモン化したり、ログファイルを作ったりするように、オリジナルに変更を加えています。

% diff -u redis.conf.org redis.conf
--- redis.conf.org      2009-12-24 23:41:51.000000000 +0900
+++ redis.conf  2010-04-24 19:19:26.000000000 +0900
@@ -2,7 +2,7 @@

 # By default Redis does not run as a daemon. Use 'yes' if you need it.
 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
-daemonize no
+daemonize yes

 # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
 # You can specify a custom pid file location here.
@@ -24,12 +24,12 @@
 # debug (a lot of information, useful for development/testing)
 # notice (moderately verbose, what you want in production probably)
 # warning (only very important / critical messages are logged)
-loglevel debug
+loglevel notice

 # Specify the log file name. Also 'stdout' can be used to force
 # the demon to log on the standard output. Note that if you use standard
 # output for logging but daemonize, logs will be sent to /dev/null
-logfile stdout
+logfile /var/log/radis

 # Set the number of databases. The default database is DB 0, you can select
 # a different one on a per-connection basis using SELECT  where

起動・停止・再起動とかのスクリプト

redis-serverredis.confの場所は環境によって違うと思うので適宜読み替えてください。

radis という名前のファイルとして保存

#!/bin/sh
#
# redis
#
# chkconfig: 2345 90 35
# description: redis-server start/stop script

# Source function library.
. /etc/rc.d/init.d/functions

start() {
    # Start daemon
    if [ -f /var/run/redis.pid ]; then
        echo "redis-server is already started"
    else
        /usr/local/lib/redis/redis-server /usr/local/lib/redis/redis.conf
    fi
}

stop() {
    # Stop daemon
    if [ -f /var/run/redis.pid ]; then
        kill `cat /var/run/redis.pid`
        rm -f /var/run/redis.pid
    else
        echo "redis-server is not running"
    fi
}

status() {
    /usr/local/lib/redis/redis-stat
}

case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        status
        ;;
    *)
        echo "Usage: redis {start|stop|restart|status}"
        ;;
esac

CentOSの起動時スクリプトとして登録

  • $ chmod +x redis:上記の起動・停止・再起動スクリプトに実行権限を付与
  • $ sudo mv redis /etc/rc.d/init.d/redis:起動時スクリプトとして設置
  • $ sudo /etc/rc.d/init.d/redis start:起動する
  • $ sudo chkconfig --add redis:起動時スクリプトに追加
  • $ sudo chkconfig redis on:起動時スクリプトに登録
  • $ sudo chkconfig --list redis:ランレベルを確認
redis           0:off   1:off   2:on    3:on    4:on    5:on    6:off

トラックバック(1)

トラックバックURL: http://blog.fulltext-search.biz/mt/mt-tb.cgi/76

■コマンド wget http://redis.googlecode.com/files/redis-1.2.6.tar.gz tar xvzf redi... 続きを読む

コメントする

カテゴリ

  • サービス

あわせてなかのひとのはてな

あわせて読みたい
この日記のはてなブックマーク数
OpenID対応しています OpenIDについて

このブログ記事について

このページは、noriakiが2010年4月24日 21:00に書いたブログ記事です。

ひとつ前のブログ記事は「Tweet and order Amazon - Amazon.co.jp上でツイートできるGreasemonkeyを@Anywhereでつくってみた」です。

次のブログ記事は「ブラウザベースでは無いアプリケーションからtwitterのOAuth認証するシンプルな方法(Ruby)」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。