源地址:http://my.oschina.net/haoqoo/blog/464247
<span><
/span
>
#无wget,请通过命令yum install wget安装
wget http:
//download
.redis.io
/releases/redis-3
.0.1.
tar
.gz
tar
xzf redis-3.0.1.
tar
.gz
cd
redis-3.0.1
make
#如果无make命令,请下载yum install <span></span>gcc make
make
test
make
install
安装好了redis后,须注意拷贝bin文件到usr/local/bin(这步很重要,无这步会报错)
cd src
cp
redis-server
/usr/local/bin/
cp
redis-cli
/usr/local/bin
之后 修改redis.conf,打开后台运行选项:
daemonize
yes
运行命令:
cp -r redis-3.0.6 /usr/local 拷贝整个目录
mv redis-3.0.6 redis 重命名文件
编写启动shell:vim /etc/init.d/redis(copy网上的)
# chkconfig: 2345 10 90
# description: Start and Stop redis
PATH=
/usr/local/bin
:
/sbin
:
/usr/bin
:
/bin
REDISPORT=6379
#实际环境而定
EXEC=
/usr/local/redis/src/redis-server
#实际环境而定
REDIS_CLI=
/usr/local/redis/src/redis-cli
#实际环境而定
PIDFILE=
/var/run/redis
.pid
CONF=
"/usr/local/redis/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 exists, 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
注意:将上面这段文字拷贝到/etc/init.d/redis后,一定要使用notepad++将文件格式转换为unix格式。(因为linux和windows的换行不一样)编辑->档案格式转换->转换为UNIX格式:
赋予权限chmod +x /etc/init.d/redis
设置开机启动:
# 尝试启动或停止redis
service redis start
service redis stop
# 开启服务自启动
chkconfig redis on
搞定。