CentOS 7 安装 redis

CentOS 7 安装 redis

1. 下载 redis 源码包

wget http://download.redis.io/releases/redis-5.0.2.tar.gz

 

2. 解压

tar -zxvf redis-5.0.2.tar.gz

 

3. 进入redis文件夹

cd redis-5.0.2

 

4. 编译 && 安装

# 编译
make

# 安装 (默认安装在 /usr/local/bin 目录下)
make install

 

5. 创建 /opt/redis_conf 配置文件夹

mkdir -p /opt/redis_conf

cd /opt/redis_conf

vim redis-6379.conf

6. 配置文件添加以下内容(最好在配置文件中去掉中文注释)

port 6379                         # 运行在6379的redis数据库实例
daemonize yes                     # 后台运行redis  
pidfile /data/6379/redis.pid      # 存放redis pid的文件
loglevel notice                   # 日志等级
logfile "/data/6379/redis.log"    # 指定redis日志文件的生成目录
dir /data/6379                    # 指定redis数据文件夹的目录
protected-mode yes                # 安全模式
requirepass   admin               # 设置redis的密码

 

7. 运行 redis 服务

redis-server /opt/redis_conf/redis-6379.conf

 

8. 连接 redis

# 使用 redis-cli 命令进行连接
# 参数:
        redis-cli -p 6379 -a admin
            -p 设置 redis 的链接端口
            -a 填写密码
            --raw 使用原始格式

[root@localhost redis_conf]# redis-cli -p 6379
127.0.0.1:6379> auth admin
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

 

8.创建多个配置文件,则可以同时运行多个不同端口的 redis 进程(配置文件注意修改端口号)

-rw-r--r--. 1 root root 155 Dec 26 16:58 redis-6379.conf
-rw-r--r--. 1 root root 155 Dec 26 17:00 redis-6380.conf
-rw-r--r--. 1 root root 155 Dec 26 17:00 redis-6381.conf
posted @ 2019-12-26 17:21  心随我动丶  阅读(119)  评论(0编辑  收藏  举报