LoginSignup
7
7

More than 5 years have passed since last update.

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

Posted at

目的

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

Redisのインストール

yum install redis

初回のみ実施すること

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

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

ポートごとの設定

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

cp -uvp /etc/redis.conf /etc/redis_6379.conf
mkdir /var/lib/redis_6379 && chown redis: /var/lib/redis_6379
cp -upv /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis_6379.service

systemctlのユニットファイルを以下のように書き換え。

/usr/lib/systemd/system/redis_6379.service
[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/redis-server /etc/redis_6379.conf --daemonize no
ExecStop=/usr/bin/redis-cli -p 6379 shutdown
User=redis
Group=redis

[Install]
WantedBy=multi-user.target

configファイルの書き換え。

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

自動起動設定。

systemctl stop redis.service # 既存のRedisを停止
systemctl disable redis.service # 既存のRedisを削除
systemctl start redis_6379.service
systemctl enable redis_6379.service

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

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

参考

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