redis在rhel7/centos7环境下的安装与配置指导

redis安装包资源

通过redis官方下载源 https://download.redis.io/releases/,获取需要的安装包资源 。请优先选择新的大版本、选择更新的小版本。

环境兼容性验证

本文提供的指导,已在rhel7.6/rhel7.9系统上,针对redis6、redis7版本做了编译安装验证测试。本文以redis7进行示例,同时提供了redis6、redis7版本分别适用的推荐配置文件。

检查并配置系统环境

选定系统用户
禁止使用root用户安装和运行redis服务。请优先使用普通权限用户。如果项目组未指定,则默认使用redisapp作为管理redis安装、配置与运行的系统用户账号。

useradd redisapp

检查数据盘路径

默认地,将redis部署在主机的数据盘上面。一般来说,常用的数据盘挂载路径是/data。需对以上使用信息进行评估,然后确定部署redis的位置。在这里,我们以/data作为数据盘挂载路径进行举例。

配置redis编译环境

yum -y install gcc gcc-c++ glibc-devel cpp python3

编译安装redis

初始化部署路径
使用redisapp用户执行以下所有的命令:

mkdir -p /data/redis/bin /data/redis/conf /data/redis/run /data/redis/data /data/redis/src

上传安装包文件
将安装包上传到/data/redis/src路径并解压:

cd /data/redis/src
tar -xf redis-7.0.15.tar.gz

编译安装

cd /data/redis/src/redis-7.0.15
make
make install PREFIX=/data/redis

一般来说,在编译安装后不需要执行make test进行测试。如果希望执行该测试命令,那么需要先安装一个测试用的工具tcl,yum install tcl

更新redis配置文件

从下文redis的推荐配置中取一份配置文件redis.conf,放置到自定义的配置文件路径下,建议清除所有的注释项:

cp ./redis7.conf /data/redis/conf/redis_6379.conf

以下两个参数需要根据实际情况进行调整:

# modify the following 2 parameters to your custom env.
# Generally,the pass need to be complicated and the maxmemory should be 1/2 to 2/3 of the avalible memory.
requirepass CHANGE_TO_YOURSELF
maxmemory 1GB

redis7 版本配置基线推荐:

bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 2048
timeout 120
tcp-keepalive 300
daemonize yes
supervised no
pidfile ./run/redis_6379.pid
logfile "redis_6379.log"
dbfilename dump_6379.rdb
dir ./data

# modify the following 2 parameters to your custom env.
# Generally,the pass need to be complicated and the maxmemory should be 1/2 to 2/3 of the avalible memory.
requirepass CHANGE_TO_YOURSELF
maxmemory 1GB

loglevel notice
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
save 3600 1 300 100 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
rdb-del-sync-files no
acllog-max-len 128
maxclients 10000
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-diskless-sync-max-replicas 0
repl-diskless-load disabled
repl-disable-tcp-nodelay no
repl-backlog-size 10mb
repl-backlog-ttl 3600
replica-priority 100
replica-ignore-maxmemory yes
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
aof-timestamp-enabled no
shutdown-timeout 10
slowlog-log-slower-than 100000
slowlog-max-len 512
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-listpack-entries 512
hash-max-listpack-value 64
list-max-listpack-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-listpack-entries 128
zset-max-listpack-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 512mb 128mb 120
client-output-buffer-limit pubsub 64mb 16mb 120
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
# replicaof <masterip> <masterport>
# masterauth <master-password>

redis6 版本配置基线 :

bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 2048
timeout 120
tcp-keepalive 300
daemonize yes
supervised no
pidfile ./run/redis_6379.pid
logfile "redis_6379.log"
dbfilename dump_6379.rdb
dir ./data

# modify the following 2 parameters to your custom env.
# Generally,the pass need to be complicated and the maxmemory should be 1/2 to 2/3 of the avalible memory.
requirepass CHANGE_TO_YOURSELF
maxmemory 1GB

loglevel notice
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
save 3600 1 300 100 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
rdb-del-sync-files no
acllog-max-len 128
maxclients 10000
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 512mb 128mb 120
client-output-buffer-limit pubsub 64mb 16mb 120
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
# replicaof <masterip> <masterport>
# masterauth <master-password>

redis服务的启停方法

redis服务建议不要配置成为系统自启动的服务。因为在主从、集群同步关系中,redis实例的启动有先后顺序的依赖关系,集群配置、哨兵服务中存在自动的主节点漂移等。以下为手工管理redis服务的方法,以下方法应通过在业务机redis部署家目录中放置一份readme.txt文件来为后续的redis运维管理提供操作指导。

假定redis部署的家目录是/data/redis,则查看cat /data/redis/readme.txt文件内容如下:

## 先检查系统用户,确认使用正确的管理redis服务的系统用户账号。
## 启动redis服务的方法
cd /data/redis
./bin/redis-server ./conf/redis_6379.conf
## 检查redis服务的方法
ps -ef|grep redis
cd /data/redis
./bin/redis-cli -p 6379
127.0.0.1:6379> AUTH CHANGE_TO_YOURSELF
127.0.0.1:6379> info
127.0.0.1:6379> quit
## 关闭redis服务的方法
cd /data/redis
./bin/redis-cli -p 6379
127.0.0.1:6379> AUTH CHANGE_TO_YOURSELF
127.0.0.1:6379> shutdown
not connected> quit

相关推荐

  1. redisrhel7/centos7环境安装配置指导

    2024-01-26 22:48:05       32 阅读
  2. CentOS 7 安装Jdk 配置环境变量

    2024-01-26 22:48:05       38 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-26 22:48:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-26 22:48:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-26 22:48:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-26 22:48:05       18 阅读

热门阅读

  1. 前端笔试题(十)

    2024-01-26 22:48:05       40 阅读
  2. 69.x 的平方根(力扣LeetCode)

    2024-01-26 22:48:05       29 阅读
  3. mysql sql查询

    2024-01-26 22:48:05       39 阅读
  4. 学习 canvas标签 这一篇文章足以

    2024-01-26 22:48:05       23 阅读
  5. Git的常用命令

    2024-01-26 22:48:05       36 阅读
  6. JVM实战(33)——内存溢出之内存使用率过高

    2024-01-26 22:48:05       39 阅读