CentOS に Redis(インメモリKVS)をインストールしたので、基本的な情報のみとなりますが手順を記載しています。
環境
OSは、CentOS 6.5 です。
Redisは PHPで利用予定です。PHPは 5.5系(remi)を使っています。
Redisのバージョンは、現時点ではこだわりはないので、yum(rpm)を使って、epel の「2.4.10」をインストールします。
インストール
以下のyumコマンドでインストールしました。
# yum install redis --enablerepo=epel # yum install php-pecl-redis.x86_64 --enablerepo=remi-php55
rpmは下記になります。
$ rpm -qa | grep redis php-pecl-redis-2.2.5-5.el6.remi.5.5.x86_64 redis-2.4.10-1.el6.x86_64 $
インストールは以上です。
Redis起動
chkconfig で自動起動にしておきます。
# /sbin/chkconfig --list redis redis 0:off 1:off 2:off 3:off 4:off 5:off 6:off # /sbin/chkconfig redis on # /sbin/chkconfig --list redis redis 0:off 1:off 2:on 3:on 4:on 5:on 6:off #
Redisを起動します。
# /etc/init.d/redis start redis-server を起動中: [ OK ] # /etc/init.d/redis status redis-server (pid 13891) を実行中... # ps -awef|grep redis | grep -v grep redis 13891 1 0 16:45 ? 00:00:00 /usr/sbin/redis-server /etc/redis.conf # ls -la /etc/redis.conf -rw-r--r-- 1 root root 21130 4月 1 23:56 2012 /etc/redis.conf # # netstat -anp | grep redis tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 13891/redis-server #
結構すんなり起動できます。
Redis設定ファイル
/etc/redis.conf が設定ファイルです。初期設定の抜粋は下記です。
$ cat /etc/redis.conf | grep -v '^#' | grep -v '^$' daemonize yes pidfile /var/run/redis/redis.pid port 6379 bind 127.0.0.1 timeout 0 loglevel notice logfile /var/log/redis/redis.log databases 16 save 900 1 save 300 10 save 60 10000 rdbcompression yes dbfilename dump.rdb dir /var/lib/redis/ slave-serve-stale-data yes appendonly no appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb slowlog-log-slower-than 10000 slowlog-max-len 1024 vm-enabled no vm-swap-file /tmp/redis.swap vm-max-memory 0 vm-page-size 32 vm-pages 134217728 vm-max-threads 4 hash-max-zipmap-entries 512 hash-max-zipmap-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 activerehashing yes $
Redis簡易操作
Redisのコマンドライン「redis-cli」で簡易操作を行ってみます。
$ redis-cli redis 127.0.0.1:6379> get domain (nil) redis 127.0.0.1:6379> set domain checksite.jp OK redis 127.0.0.1:6379> get domain "checksite.jp" redis 127.0.0.1:6379> del domain (integer) 1 redis 127.0.0.1:6379> get domain (nil) redis 127.0.0.1:6379> exit $