码迷,mamicode.com
首页 > 其他好文 > 详细

redis 在centos下的安装部署

时间:2015-06-17 11:00:12      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

安装的redis版本是 redis-3.0.2

请严格按照以下步骤进行

可以免除以下错误

1 make[2]: cc: Command not found

 异常原因:没有安装gcc

 解决方案:yum install gcc-c++

2 redis 服务不支持 chkconfig

 异常原因 /etc/init.d/redis 没有添加chkconfig的代码

 

 

=====正式开始=====

1 redis 依赖环境

gcc

yum install gcc -y

 

tcl

yum install tcl -y

 

2 下载相应的tar包.解压,安装

cd /usr/local
# redis-3.0.2.tar.gz 放在/usr/local 目录,个人喜好....
tar -zxvf redis-3.0.2.tar.gz
cd redis-3.0.2
make
make test
make install

 

3 复制redis-cli redis-server 到/etc/redis

--在make成功以后,会在src目录下多出一些可执行文件:redis-server,redis-cli等等

cd src
cp redis-server /usr/local/bin/

cp redis-cli /usr/local/bin/

# 然后新建目录,存放配置文件

mkdir /etc/redis

mkdir /var/redis

mkdir /var/redis/log

mkdir /var/redis/run

mkdir /var/redis/6379

4 copy配置文件到/etc/redis ,并修改

cd ..
cp redis.conf /etc/redis/6379.conf
cd /etc/redis/

6379配置文件 需要 修改的地方

daemonize yes  #后台服务

pidfile /var/redis/run/redis_6379.pid

logfile /var/redis/log/redis_6379.log

dir /var/redis/6379

 

5 启动

cd /user/local/redis-3.0.2/src/
redis-server /etc/redis/6379.conf

 

6 测试

redis-cli -h 127.0.0.1 -p 6379
set name "xiaoshou" //设值  ==> ok
get name //取值 ==>  "xiaoshou"

 

 

7 开机启动redis

这里需要添加redis 为服务

在 /etc/init.d/增加 redis文件

cd /etc/init.d/
vim reids

# redis文件内容如下
###########################
#chkconfig: 2345 10 90
#description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
   
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
   
PIDFILE=/var/run/redis.pid
CONF="/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
        if [ "$?"="0" ] 
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac
##############################

 

8 给予执行权限

chmod +x /etc/init.d/redis

 

9 添加服务

cd /etc/int.d/
chkconifg  --add redis
chkconfig redis on 

 

10 redis 服务的开关

service redis start
service redis stop

 

redis 在centos下的安装部署

标签:

原文地址:http://www.cnblogs.com/sheapchen/p/4582548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!