LoginSignup
3
2

More than 5 years have passed since last update.

OS X上でRedisをデーモンとして動かす

Last updated at Posted at 2015-06-26

インストール

HomebrewでRedisをインストール

brew install redis

実行グループ作成

使用されているグループIDを確認する

dscl . -list /Groups gid | sort -k 2 -n

未使用グループIDを指定してグループを作成する(今回の場合グループIDは246)

sudo dscl . -create /Groups/_redis PrimaryGroupID 246

実行ユーザー作成

使用されているユーザーIDを確認する

dscl . -list /Users UniqueID | sort -k 2 -n

未使用ユーザーIDを指定してログイン不可ユーザーを作成する(今回の場合ユーザーIDは247)

sudo dscl . -create /Users/_redis UniqueID 247
sudo dscl . -create /Users/_redis UserShell /usr/bin/false

先ほど作成したグループのグループIDをPrimaryGroupIDとして指定する

sudo dscl . -create /Users/_redis PrimaryGroupID 246

ユーザーをwheelグループにも追加する

sudo dscl . -append /Groups/wheel GroupMembership _redis

plistファイル作成

launchdで実行する為plistファイルを作成する

sudo vim /Library/LaunchDaemons/io.redis.redis.plist
io.redis.redis.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>io.redis.redis</string>
        <key>Program</key>
        <string>/usr/local/bin/redis-server</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/redis-server</string>
            <string>/usr/local/etc/redis.conf</string>
        </array>
        <key>UserName</key>
        <string>_redis</string>
        <key>GroupName</key>
        <string>_redis</string>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <dict>
            <key>SuccessfulExit</key>
            <false/>
        </dict>
    </dict>
</plist>

起動

作成したplistファイルをlaunchdに読み込ませると(問題がなければ)自動起動する

sudo launchctl load /Library/LaunchDaemons/io.redis.redis.plist

起動しない場合、以下のディレクトリに実行ユーザー/グループでの読み書き権限があるかチェックする

  • (設定でdaemonize=yesにしている場合)pidファイルの出力先(/usr/local/var/run/)
  • (設定でログを出力するようにしている場合)ログ出力先ディレクトリ
  • rdbファイルの出力先(/use/local/db/redis/)
3
2
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
3
2