【安装Redis】CentOS7 下安装NodeJs+Express+MongoDB+Redis

Redis,V3.2,官网l官方链接:http://www.redis.io/download,参考:http://blog.csdn.net/mlks_2008/article/details/19001595

1、安装Redis

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

2、设置Redis为开机启动

  • redis的命令会被拷贝到/usr/local/bin下面

  cp redis.conf /etc/

  • 创建redis脚本执行文件:vi /etc/init.d/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 [ "$?"="" ]
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
##############################
  • 然后设置此文件的属性

chmod +x /etc/init.d/redis

  • 修改daemonize no 改为 daemonize yes

vim /etc/redis.conf

  •   设置开机启动服务

chkconfig redis on

3、常用命令

启动服务:

/etc/init.d/redis start

停止服务:

/etc/init.d/redis stop

测试命令:

redis-cli

redis 127.0.0.1:6379> set foo 123  

redis 127.0.0.1:6379> get foo  

redis 127.0.0.1:6379> exit 
上一篇:深入浅出的webpack构建工具---DevServer配置项(二)


下一篇:浅谈 trie树 及其实现