阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.5安装Redis及开机启动脚本

243次阅读
没有评论

共计 2882 个字符,预计需要花费 8 分钟才能阅读完成。

一:CentOS 6.5 下载安装 Redis

1、下载源码,解压缩后编译源码

# wget http://download.redis.io/releases/redis-2.8.3.tar.gz
# tar xzf redis-2.8.3.tar.gz
# cd redis-2.8.3
# make

2、进入安装目录的 src 文件夹下,有四个可执行文件 redis-server、redis-benchmark、redis-cli 和 redis.conf, 复制到同一个目录下

# mkdir /usr/redis
# cp redis-server  /usr/redis
# cp redis-benchmark /usr/redis
# cp redis-cli  /usr/redis
# cp redis.conf  /usr/redis
# cd /usr/redis

3、启动 Redis 服务。

# cd /usr/redis
# ./redis-server redis.conf

启动异常
情况一:
[17496] 08 Oct 11:48:09.153 # Server started, Redis version 2.8.17
[17496] 08 Oct 11:48:09.153 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.
[17496] 08 Oct 11:48:09.153 * The server is now ready to accept connections on port 6379

解决办法:编辑 /etc/sysctl.conf,添加一项 vm.overcommit_memory = 1,重启生效。

4、客户端测试。

redis 127.0.0.1:6379>  #显示此行意味着安装成功。

二:设置 redis 开机启动

环境:Linux 系统为 CentOS 6.6

1. 编写启动脚本

注意:默认的 redis.conf 文件参数是前台启动的,修改 daemonize no 为 daemonize yes 则为后台启动。

脚本的编码格式在 Windows 上编码放在 Linux 可能不识别,可以用 UltraEdit 转换下格式“文件 –> 转换 –>DOS 转 UNIX“

#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis
 
PROGDIR=/usr/redis #安装路径
PROGNAME=redis-server
DAEMON=$PROGDIR/$PROGNAME
CONFIG=/usr/redis/redis.conf
PIDFILE=/var/run/redis.pid
DESC=”redis daemon”
SCRIPTNAME=/etc/rc.d/init.d/redis
 
start()
{
        if test -x $DAEMON
        then
        echo -e “Starting $DESC: $PROGNAME”
                  if $DAEMON $CONFIG
                  then
                            echo -e “OK”
                  else
                            echo -e “failed”
                  fi
        else
                  echo -e “Couldn’t find Redis Server ($DAEMON)”
        fi
}
 
stop()
{
        if test -e $PIDFILE
        then
                  echo -e “Stopping $DESC: $PROGNAME”
                  if kill `cat $PIDFILE`
                  then
                            echo -e “OK”
                  else
                            echo -e “failed”
                  fi
        else
                  echo -e “No Redis Server ($DAEMON) running”
        fi
}
 
restart()
{
    echo -e “Restarting $DESC: $PROGNAME”
    stop
        start
}
 
list()
{
        ps aux | grep $PROGNAME
}
 
case $1 in
        start)
                  start
        ;;
        stop)
        stop
        ;;
        restart)
        restart
        ;;
        list)
        list
        ;;
 
        *)
        echo “Usage: $SCRIPTNAME {start|stop|restart|list}” >&2
        exit 1
        ;;
esac
exit 0

把 redis 脚本文件放在 /etc/rc.d/init.d/ 目录下

2、增加服务并开机启动

# chmod +x /etc/rc.d/init.d/redis
# chkconfig –add redis
# chkconfig –level 345 redis on
# chkconfig –list redis

3、重启测试。

下面关于 Redis 的文章您也可能喜欢,不妨参考下:

Ubuntu 14.04 下 Redis 安装及简单测试 http://www.linuxidc.com/Linux/2014-05/101544.htm

Redis 主从复制基本配置 http://www.linuxidc.com/Linux/2015-03/115610.htm

Redis 集群明细文档 http://www.linuxidc.com/Linux/2013-09/90118.htm

Ubuntu 12.10 下安装 Redis(图文详解)+ Jedis 连接 Redis http://www.linuxidc.com/Linux/2013-06/85816.htm

Redis 系列 - 安装部署维护篇 http://www.linuxidc.com/Linux/2012-12/75627.htm

CentOS 6.3 安装 Redis http://www.linuxidc.com/Linux/2012-12/75314.htm

Redis 安装部署学习笔记 http://www.linuxidc.com/Linux/2014-07/104306.htm

Redis 配置文件 redis.conf 详解 http://www.linuxidc.com/Linux/2013-11/92524.htm

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-04/130076.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计2882字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中