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

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

Redis介绍:

Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库。

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

环境准备:

yum install -y openssl gcc

 

Redis安装:

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

下载最新稳定版本。

本文章用到的是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

添加用户:

[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配置文件:

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

[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 -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> 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄