信息来源链接:
http://blog.csdn.net/ludonqin/article/details/47211109
安装
# 从redis官网http://redis.io下载redis安装包
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
# 解压安装包
tar -zxvf redis-3.2.8.tar.gz
# 编译、安装
cd redis-3.2.8
make
make install
[root@iZ28nvy56w8Z redis-3.2.8]# make
cd src && make all
make[1]: Entering directory `/root/redis-3.2.8/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
make[2]: Entering directory `/root/redis-3.2.8/deps'
……
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/root/redis-3.2.8/src'
[root@iZ28nvy56w8Z redis-3.2.8]# make install
cd src && make install
make[1]: Entering directory `/root/redis-3.2.8/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/root/redis-3.2.8/src'
查看安装redis版本
# 通过redis-server -v查看redis版本信息
redis-server -v
[root@iZ28nvy56w8Z redis-3.2.8]# redis-server -v
Redis server v=3.2.8 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=f5348b547d6fe30f
配置redis
# 创建配置文件目录
cd /etc/
mkdir redis
cd /var/
mkdir redis
cd redis/
mkdir data log run
# 拷贝安装包下redis.conf至/etc/redis/
cp redis-3.2.8/redis.conf /etc/redis/
cd /etc/redis/
# 修改redis.conf文件
vi redis.conf
# 修改pid目录文件
pidfile /var/redis/run/redis.pid
# 修改dump目录文件
dir /var/redis/data
# 修改log目录文件
logfile /var/redis/log/redis.log
# 修改redis服务后台运行
daemonize yes
启动redis
redis-server /etc/redis/redis.conf
使用客户端连接redis
# 使用redis-cli连接redis
redis-cli
[root@iZ28nvy56w8Z run]# redis-cli
127.0.0.1:6379>
配置redis服务
# 将redis压缩包目录utils目录下启动脚本复制到/etc/init.d/下
cp redis_init_script /etc/init.d/
# 修改服务名
mv redis_init_script redis
# 修改脚本
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/redis/run/redis.pid
CONF="/etc/redis/redis.conf"
# 使用service redis start启动服务
service redis start
# 使用service redis stop停止服务
service redis stop
[root@iZ28nvy56w8Z redis]# service redis start
Starting Redis server...
[root@iZ28nvy56w8Z redis]# service redis stop
Stopping ...
Redis stopped
配置开机启动
# 修改/etc/init.d/redis配置,增加# chkconfig: 2345 90 10
chkconfig redis on
#!/bin/sh
#
# chkconfig: 2345 90 10
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
[root@iZ28nvy56w8Z redis]# chkconfig redis on
[root@iZ28nvy56w8Z redis]# chkconfig --list redis
redis 0:off 1:off 2:on 3:on 4:on 5:on 6:off
配置文件名展示端口信息
# 修改/etc/init.d/redis配置为
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/redis/run/redis_${REDISPORT}.pid
CONF="/etc/redis/redis_${REDISPORT}.conf"
# 修改redis配置文件名为redis_6379.conf
# 修改redis配置文件中pid为/var/redis/run/redis_6379.pid