Redis安装及基本配置

Redis安装

# 下载源码
[root@192.168.32.130 /data/app]$ wget http://download.redis.io/releases/redis-3.2.12.tar.gz

# 解压
[root@192.168.32.130 /data/app]$ tar zxf redis-3.2.12.tar.gz

# 编译...
[root@192.168.32.130 /data/app]$ cd redis-3.2.12
[root@192.168.32.130 /data/app/redis-3.2.12]$ make 

# 启动服务
[root@192.168.32.130 /data/app/redis-3.2.12]$ src/redis-server & 

# 创建软连接
[root@192.168.32.130 /data/app/redis/src]$ ln -s /data/app/redis/src/redis-cli /usr/bin/

# 客户端连接测试
[root@192.168.32.130 /data/app/redis-3.2.12]$ src/redis-cli 

127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"

# 配置系统服务
[root@192.168.32.130 /data/app]$ mv redis-3.2.12 redis
[root@192.168.32.130 /data/app]$ vim /etc/init.d/redis
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/data/app/redis/src/redis-server
CLIEXEC=/data/app/redis/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
PWD="root"

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)
        #PID=$(cat $PIDFILE)
        echo "Stopping ..."
        $CLIEXEC -a ${PWD} -p $REDISPORT shutdown
        echo "Redis stopped"
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac
chkconfig redis on

Redis基本管理操作

基础配置文件介绍

[root@192.168.32.130 /data/app/redis]$ mkdir -p /etc/redis/
[root@192.168.32.130 /data/app/redis]$ vim /etc/redis/6379.conf

daemonize yes
port 6379
bind 127.0.0.1
logfile /etc/redis/redis.log
dir /etc/redis/
dbfilename dump.rdb
# 设置redis访问密码
requirepass root

save 900 1
save 300 10
save 60 10000

+++++++++++配置文件说明++++++++++++++
redis.conf
是否后台运行:
daemonize yes
默认端口:
port 6379
绑定ip:
bind 127.0.0.1
日志文件位置
logfile /etc/redis/redis.log
持久化文件存储位置
dir /etc/redis/
RDB持久化数据文件:
dbfilename dump.rdb
设置redis密码
requirepass root        

900秒(15分钟)内有1个更改
300秒(5分钟)内有10个更改
60秒内有10000个更改
save xx xx
+++++++++++++++++++++++++

连接测试

[root@192.168.32.130 /etc/redis]$ redis-cli -a root
127.0.0.1:6379> set a b
OK
127.0.0.1:6379> get a
"b"
127.0.0.1:6379> 
127.0.0.1:6379> auth root
OK
127.0.0.1:6379> 

在线查看所有配置
127.0.0.1:6379> CONFIG GET *

临时修改密码
CONFIG GET requirepass
CONFIG SET requirepass 123456

redis多实例安装配置略。。。

posted @ 2019-12-01 15:57  GeminiMp  阅读(220)  评论(0编辑  收藏  举报