ミライハック
  • Home
  • Categories
  • About

>> Home / LInux

Redis2.6のインストール

∵ Takayoshi Saito ∴ 2013-02-27 ∞ 4'

Redis2.6のインストール方法

以下のコマンドを実行します。

$ wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
$ tar xzf redis-2.6.10.tar.gz
$ cd redis-2.6.10
$ make

これで$ src/redis-serverというファイルが出来て、Redisサーバーを起動させることはできます。

# redis-server
[10385] 28 Feb 02:18:04.274 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[10385] 28 Feb 02:18:04.275 * Max number of open files set to 10032
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.6.10 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 10385
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

[10385] 28 Feb 02:18:04.276 # Server started, Redis version 2.6.10
[10385] 28 Feb 02:18:04.276 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[10385] 28 Feb 02:18:04.276 * The server is now ready to accept connections on port 637

ワーニング(overcommit_memory is set to 0)が一個出ていますが、これはOOM Killerに関するもので、/etc/sysctl.confに vm.overcommit_memory=1 と記述するとワーニングが出なくなります(OOM Killerが発動しなくなります)。

ただ、これだけでは起動時に不便ですので、起動スクリプトを作りましょう。

Redis2.6の起動スクリプト

Redis起動スクリプトを作成するシェルは、utils/install-server.sh にありますので、これを実行します。途中、質問をいくつか聞かれますが、特にこだわりがなければエンターキーを押して先に進んで問題ありません。

# sh ./utils/install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name  
Selected default - /etc/redis/6379.conf
Please select the redis log file name  
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance  
Selected default - /var/lib/redis/6379
Please select the redis executable path  
s#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#;
Copied /tmp/6379.conf =/\

これで起動スクリプトやconfが配備されるのですが、このinstall-server.shにはバグがあって、以下のコマンドを実行してもエラーになります。

$ sudo /etc/init.d/redis_6379 start
 exists, process is already running or crashed

これは/etc/init.d/redis_6379の最初の行がバグのため、以下のようになってしまっているためです。

#/bin/sh\n #Configurations injected by install_server below....\n\n EXEC=/usr/local/redis/src/redis-server\n CLIEXEC=/usr/local/redis/src/redis-cli\n PIDFILE=/var/run/redis_6379.pid\n CONF="/etc/redis/6379.conf"\n\n REDISPORT="6379"\n\n ###############\n\n

case "$1" in
    start)

これでは動きません。とりあえず改行コードを正しく改行に修正し、各設定項目が動くようにします。私は冒頭を下記のように書き換えましました。

#/bin/sh
# /etc/init.d/redis
#
### BEGIN INIT INFO
# Provides:          redis
# Required-Start:    $syslog $remote_fs
# Should-Start:
# Required-Stop:     $syslog $remote_fs
# Should-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Redis server
# Description:       Starts and stops the Redis daemon
### END INIT INFO

EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/etc/redis/6379.conf"
REDISPORT="6379"
###############

これはopenSUSEの書き方ですが、CentOSの場合もchkconfigで制御できるようになると思います。これで正常にRedisの起動を行うことが出来るようになりました。

# /etc/init.d/redis start
Starting Redis server...

Redis2.4からRedis2.6へのアップグレード

Redisのデータを消さずにRedis2.4からRedis2.6へアップグレードする方法は今回は試しませんでした。今度CentOSでRedisをアップグレードさせるので、その時に試してみようと思います。

Redis2.6のRPM(YUMインストール)

CentOS用にRedis2.6のRPMを作成しました。以下の私のYUMレポジトリに置いてあります(64bitのみ。utilsは同梱されていません。Redisの起動は、redis-serverコマンドで行なってください)。

http://www.testvps.info/centos6/rpm/

openSUSE版のRPMも作りました。

http://www.geek.sc/opensuse/rpm/

私の野良YUMレポジトリの使い方は、野良YUMレポジトリを構築しましたをご参照ください。それでは、快適なKVSライフを!

Search

Categories
  • LInux
  • インターネット
  • インフラ
  • エッセイ
  • ゲーム
  • システム開発
  • セキュリティ
  • データサイエンス
  • 国際関係
  • 政治
  • 歴史
  • 社会学
  • 自己紹介
  • 行ってきた

Pages
  • 齊藤貴義
  • 職務経歴
  • スクレイピング・ハッキング・ラボ サポートページ
  • 『爆速開発を支えるClaude Code上級者テクニック』サポートページ

2026 © Takayoshi Saito | Twitter GitHub | Built on Zola