Linux下安装Redis4.0版本(简便方法)

 

Redis介绍:

Redis 是彻底开源免费的,遵照BSD协议,是一个高性能的key-value数据库。redis

Redis 与其余 key - value 缓存产品有如下三个特色:数据库

  • Redis支持数据的持久化RDB和AOF,能够将内存中的数据保存在磁盘中,重启的时候能够再次加载进行使用。
  • Redis不单单支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
  • Redis支持数据的备份,即master-slave模式的数据备份。
  • 性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s 。
  • 丰富的数据类型 – Redis支持二进制案例的 Strings, Lists, Hashes, Sets 及 Ordered Sets 数据类型操做。
  • 原子 – Redis的全部操做都是原子性的,意思就是要么成功执行要么失败彻底不执行。单个操做是原子性的。多个操做也支持事务,即原子性,经过MULTI和EXEC指令包起来。
  • 丰富的特性 – Redis还支持 publish/subscribe, 通知, key 过时等等特性。

安装环境:

  • 操做系统:CentOS Linux release 7.7.1908 (Core)
  • IP地址:192.168.85.16
  • 配置文件:/data/redis/conf/redis.conf
  • 日志目录:/data/redis/log/redis.log
  • 数据目录:/data/redis/data/
  • 服务:/data/redis/bin/redis-server

环境准备:

yum install -y openssl gcc

 

Redis安装:

官网地址:http://redis.io/download缓存

下载最新稳定版本。bash

本文章用到的是4.0.11版本,下载并安装:数据结构

cd /data
wget http://download.redis.io/releases/redis-4.0.11.tar.gz tar zxvf redis-4.0.11.tar.gz

添加用户:tcp

[root@localhost data]# useradd -M -s /sbin/nologin redis

#查看redisid信息:性能

[root@localhost data]# id redis uid=1000(redis) gid=1000(redis) groups=1000(redis)

#设置redis用户密码
测试

[root@localhost data]# passwd redis

建立相关目录:

[root@localhost conf]# mkdir -p /data/redis/{log,conf,data}
[root@localhost conf]# chown -R redis:redis /data/redis

编译安装:

[root@localhost redis-4.0.11]# pwd /data/redis-4.0.11
[root@localhost redis-4.0.11]# make
[root@localhost redis-4.0.11]# cd src/
#指定编译安装路径
[root@localhost src]# make PREFIX=/data/redis install
[root@localhost src]# cp ../redis.conf /data/redis/conf

配置环境变量:

[root@localhost src]# vi ~/.bash_profile
[root@localhost src]# PATH=$PATH:$HOME/.local/bin:/data/redis/bin:$HOME/bin
[root@localhost src]# source ~/.bash_profile

调整redis配置文件:

这个按需设置,我这里列出仅供参考基本的参数ui

[root@localhost src]# vi /data/redis/conf/redis.conf
#daemonize yes
#守护进程模式
daemonize yes
#日志文件目录
logfile "/data/redis/log/redis.log"
#redis密码 requirepass tse123
bind 192.168.85.16

启停redis服务:

[root@localhost log]# /data/redis/bin/redis-server /data/redis/conf/redis.conf
#查看服务是否启动成功 [root@localhost log]# netstat
-lntp|grep redis tcp 0 0 192.168.85.16:6379 0.0.0.0:* LISTEN 5613/redis-server 1
#中止redis实例服务 /data/redis/bin/redis-cli -h 192.168.85.16 -p 6379 -a 密码 shutdown

客户端链接测试:

[root@localhost log]# /data/redis/bin/redis-cli -h 192.168.85.16 -p 6379 -a 密码
Warning: Using a password with '-a' option on the command line interface may not be safe.
192.168.85.16:6379> PING
PONG
192.168.85.16:6379>