1、Redis的下载地址
1.1 官网的下载地址为:http://www.redis.io/download
1.2 在linux下,下载Redis的命令如下
wget http://download.redis.io/releases/redis-3.2.3.tar.gz
2、对 linux 上的 redis 文件进行解压。命令如下:
#进行解压
tar -zxvf redis-3.2.4.tar.gz -C /usr/local/
3、进行make && make install 操作
#进行make && make install
cd /usr/local/redis-3.2.4
make && make install
4、建立两个文件夹分别存放redis的配置文件和执行命令
mkdir -p /usr/local/redis/etc
mkdir -p /usr/local/redis/bin
cp redis.conf /usr/local/redis/etc/
#关于配置文件的一些修改
1、以后台形式,启动redis的服务
daemonize yes
2、修改,数据文件dump.rdb文件存放的路径
dir /usr/local/redis/etc
6、把redis-3.2.4/src下的mkreleasehdr.sh,redis-benchmark,redis-check-aof,redis-cli ,redis-server 移动到/usr/local/redis/bin
cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server /usr/local/redis/bin
[root@localhost src]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
8、将Redis相关的命令,加入到环境变量里面
8.1 修改 /etc/profile文件
#set redis path
Redis_Path=/usr/local/redis/bin
export PATH=$PATH:$Redis_Path
8.2 重新执行 /etc/profile文件的内容,是的配置生效
source /etc/profile
9、验证是否启动成功
9.1 使用 ps 命令
[root@localhost redis-3.2.4]# ps -ef | grep redis
root 15224 2598 0 23:49 pts/1 00:00:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379
root 15255 15236 0 23:50 pts/3 00:00:00 /usr/local/redis/bin/redis-cli
root 15299 11969 0 23:54 pts/2 00:00:00 grep redis
9.2 使用 netstat 命令
[root@localhost redis-3.2.4]# netstat -tunpl | grep redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 15224/redis-server
10、将redis安装为一个服务
10.1 复制脚本到/etc/init.d目录(系统在启动的时候,会自动加载/etc/rc.d目录下的可执行脚本)
#复制脚本文件,并改名字为redis
cp /usr/local/src/redis/utils/redis_init_script /etc/rc.d/init.d/redis
10.2 更改,redis脚本文件,增加下面的内容
(注意配置文件的位置)
#!/bin/sh
#chkconfig: 2345 80 90
#设置开机状态的启动
#设置redis服务重新启动
restart)
$0 stop
$0 start
;;
10.3 增加redis服务到开机启动项
chkconfig --add redis
service redis start
service redis stop
service redis restart
10.5 完整版的脚本文件,如下:
#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/etc/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Please use start or stop as first argument"
;;
esac
11、关闭redis服务
[root@localhost etc]# /usr/local/redis/bin/redis-cli shutdown
12、参考的博客地址
http://www.cnblogs.com/_popc/p/3684835.html
13、redis学习的相关资料下载