LoginSignup
1
1

More than 1 year has passed since last update.

CentOS 6でRedisを複数立ち上げる

Last updated at Posted at 2016-10-12

目的

開発でRedisのレプリケーションや複数のRedisへの接続を試す環境を作成するためにCentOS 6上で複数のインスタンスを立ち上げる方法を紹介します。

Redisのインストール

yum install redis

初回のみ実施すること

pidファイルとログ用のディレクトリを作成。

mkdir /var/run/redis/ && chown redis: /var/run/redis/
mkdir /var/log/redis/ && chown redis: /var/log/redis/

ポートごとの設定

データディレクトリ、設定ファイル、起動スクリプトの準備。
実行時はredisユーザーとなるので、ファイルオーナーとグループの設定に気をつけて下さい。

cp -uvp /etc/redis.conf /etc/redis_6379.conf
mkdir /var/lib/redis_6379 && chown redis: /var/lib/redis_6379
cp -upv /etc/init.d/redis /etc/init.d/redis_6379

configファイルの以下の部分を変更

/etc/init.d/redis_6379
# サーバー名をカスタマイズ
name="redis_6379"

# $nameをredis-serverに書き換え
exec="/usr/bin/redis-server"

# pidファイルのパスを指定
pidfile="/var/run/redis/redis_6379.pid"

# configファイルのパスを指定
REDIS_CONFIG="/etc/redis_6379.conf"

stop() {
    echo -n $"Stopping $name: "
    # 以下はコメントアウト
    #[ -x $shut ] && $shut
    #retval=$?
/etc/redis/6379.conf
# ポート番号の指定
port 6379

# pidファイルのパスを指定
pidfile /var/run/redis/redis_6379.pid

# ログファイルのパスを指定
logfile /var/log/redis/redis_6379.log

# データディレクトリを指定
dir /var/lib/redis_6379/

自動起動設定。

chkconfig --del redis # 既存のRedisを削除
chkconfig redis_6379 on

ポート6380の設定を追加する

上記の6379を6380に読み替えて設定してください。

参考

1
1
1

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
1
1