前端之家收集整理的这篇文章主要介绍了
centos下的Redis的安装和使用,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
简介
Redis 是一个高性能的key-value数据库。
准备
- 下载:http://redis.io/download 下载 redis-3.2.0.tar.gz 的文件
- 系统环境 yum -y install gcc-c++ tcl
安装
- install redis
tar xzf redis-3.2.0.tar.gz
cd redis-3.2.0
./configure
make && make test
make install
服务配置
-
设置为服务
保存以下代码到/etc/init.d/redis (在utils/redis_init_script脚本基础上修改的)
#!/bin/sh
#
# chkconfig: 2345 90 10
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/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
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist,process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
- 默认配置文件
mkdir -p /etc/redis
cp redis.conf /etc/redis
vi /etc/redis/redis.conf
把 daemonize no 一行换成
daemonize yes
- 设置开机启动
chkconfig --add redis
chkconfig redis on #设置开机启动
service redis start
基本使用
- redis 目录相关可执行文件列表
/usr/local/bin/redis-benchmark ## 性能测试工具
/usr/local/bin/redis-check-aof ## 用于修复出问题的AOF文件
/usr/local/bin/redis-check-dump ## 用于修复出问题的dump.rdb文件
/usr/local/bin/redis-check-rdb ## 用于修复出问题的rdb文件
/usr/local/bin/redis-cli ## 客户端程序
/usr/local/bin/redis-server ## 服务端程序
- 测试连接
[root@vagrant-centos64 /]# ./usr/local/bin/redis-cli
127.0.0.1:6379> set ff aaa
OK
127.0.0.1:6379> get ff
"aaa"
127.0.0.1:6379> set key value [EX seconds] [PX milliseconds] [NX|XX]
扩展阅读
原文链接:https://www.f2er.com/centos/381887.html