さくらのVPSにredisをインストール
redisのインストール
yumでのインストールもできますが、最新をインストールしたかったので、
ソースファイルをダウンロードしてきてインストールします
wget http://redis.googlecode.com/files/redis-2.4.5.tar.gz tar zxvf redis-2.4.5.tar.gz cd redis-2.4.5 make sudo make install
これでインストールは完了です。
動作確認
redis-server これでサーバが起動します。 起動させたまま、別のターミナルで redis-cli redis> ping PONG redis> set foo bar OK redis> get foo "bar" redis> quit
このように動作すればとりあえずインストールはOK
起動スクリプトの設定
起動スクリプトのやり方は2通り書いておきます。
私は方法1.を使用しています。
方法1.yumでインストールした場合に作成される起動スクリプトを使用する
まず、redisを使用するユーザーとグループを作成する
sudo groupadd redis sudo useradd -s /sbin/nologin -M -g redis redis
GID、UIDをサーバで指定したい場合は、上記コマンドに追加して設定師てください。
こちらのファイルを
「/etc/init.d/redis」の名前で設定する
#!/bin/sh
#
# redis init file for starting up the redis daemon
#
# chkconfig: - 20 80
# description: Starts and stops the redis daemon.
# Source function library.
. /etc/rc.d/init.d/functions
name="redis-server"
exec="/usr/sbin/$name"
pidfile="/var/run/redis/redis.pid"
REDIS_CONFIG="/etc/redis.conf"
[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
[ -f $REDIS_CONFIG ] || exit 6
[ -x $exec ] || exit 5
echo -n $"Starting $name: "
daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $name: "
killproc -p $pidfile $name
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
false
}
rh_status() {
status -p $pidfile $name
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"
exit 2
esac
exit $?
これで完了です。
自動起動設定
sudo chkconfig redis on
これで、サーバが再起動しても自動起動します。
方法2.install_server.shを使用する
起動スクリプトの設定ですが、「utils/install_server.sh」を動作させてインストールします。
zshを使って私がやっているとそのままでは上手く動作しなかったので以下の修正をしました。
32行目を追加
# Interactive service installer for redis server # this generates a redis config file and an /etc/init.d script, and installs them # this scripts should be run as root # PATH=$PATH:/usr/local/bin
139行目を修正(-eを追加)
-echo $REDIS_INIT_HEADER > $TMP_FILE && cat $INIT_TPL_FILE >> $TMP_FILE || die "Could not write init script to $TMP_FILE" +echo -e $REDIS_INIT_HEADER > $TMP_FILE && cat $INIT_TPL_FILE >> $TMP_FILE || die "Could not write init script to $TMP_FILE"
これで、install_server.shの修正は終了です。
実行します。
cd utils sudo ./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 [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... ./install_server.sh: line 147: update-rc.d: command not found Starting Redis server... Installation successful!
色々聞かれますが、全てデフォルトでインストールしました。
起動確認
redis起動
sudo /etc/init.d/redis_6379 start
redis停止
sudo /etc/init.d/redis_6379 stop
これでredisが動作していれば大丈夫です。
次は、MongoDBのインストールです。
関連する記事:
- さくらのVPSのCentOS6.2への環境構築
- さくらのVPSにMongoDBをインストール
- さくらのVPSにmysqlのインストールと設定
- さくらのVPSでdenyhostsを設定
- さくらのVPSでsshdのポート変更
コメント 0