最新消息:走过的,离开的,已经错过,新开始2016

centos 6.x安装Redis

技术随笔 果果 4813浏览 0评论

redis

今天在centos6.5下面安装Redis,记录一下,供大家参考。
修改yum源,国内可以使用阿里云,搜狐,163等。

yum 安装一些必要的库和软件

yum install -y unzip wget gcc* tcl

下载 Redis

cd /opt
wget http://download.redis.io/releases/redis-3.0.7.tar.gz

完成后解压安装

tar -zxvf redis-3.0.7.tar.gz
cd redis-3.0.7
make MALLOC=libc

编译完成的执行文件在 src文件夹,拷贝到/usr/local

mkdir /usr/local/redis
mkdir /usr/local/redis/bin
mkdir /usr/local/redis/date
mkdir /usr/local/redis/logs
mkdir /usr/local/redis/etc
cd src
cp -a redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server redis-trib.rb usr/local/redis/bin

建立配置文件

vi /usr/local/redis/etc/redis.conf

写入下面内容

daemonize yes
pidfile "/var/run/redis.pid"
port 6379
bind *
timeout 300
loglevel verbose
logfile stdoutl
logfile "/usr/local/redis/logs/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir "/usr/local/redis/date/"
requirepass 123456
maxclients 10000
maxmemory 4096MB
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec

建立启动脚本

vi /etc/init.d/redis

写入以下内容

#!/bin/sh
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
# redis    Startup script for redis processes
# processname: redis
redis_path="/usr/local/redis/bin/redis-server"
redis_conf="/usr/local/redis/etc/redis.conf"
redis_pid="/var/run/redis.pid"
# Source function library.
. /etc/rc.d/init.d/functions
[ -x $redis_path ] || exit 0
RETVAL=0
prog="redis"
# Start daemons.
start() {
if [ -e $redis_pid -a ! -z $redis_pid ];then
echo $prog" already running...."
exit 1
fi
echo -n $"Starting $prog "
# Single instance for all caches
$redis_path $redis_conf
RETVAL=$?
[ $RETVAL -eq 0 ] && {
touch /var/lock/subsys/$prog
success $"$prog"
}
echo
return $RETVAL
}
# Stop daemons.
stop() {
echo -n $"Stopping $prog "
killproc -d 10 $redis_path
echo
[ $RETVAL = 0 ] && rm -f $redis_pid /var/lock/subsys/$prog
RETVAL=$?
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if test "x`pidof redis`" != x; then
stop
start
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $RETVAL

修改权限启动

chmod +x /etc/init.d/redis
chkconfig redis --add
chkconfig redis on

/etc/init.d/redis start

测试进入控制台

/usr/local/redis/bin/redis-cli -a 123456
info

转载请注明:果果.IT » centos 6.x安装Redis

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址