CentOS7.9 部署 redis 最新稳定版
- 安装包存储目录:/opt/source
- redis 安装目录: /opt/redis
- 目录结构如下:
/opt/redis/
├── bin
│ ├── redis-benchmark
│ ├── redis-check-aof -> redis-server
│ ├── redis-check-rdb -> redis-server
│ ├── redis-cli
│ ├── redis-sentinel -> redis-server
│ └── redis-server
├── conf
│ └── redis.conf
├── data
│ ├── appendonlydir
│ └── dump.rdb
└── logs
└── redis.log
请记得修改 requirepass 后面的密码(此脚本密码为R2d1ss#!1324 )
#! /bin/bash
echo "开始检查gcc 版本"
gcc -v
if [ ! $? -eq 0 ];then
echo "开始安装gcc"
yum install gcc -y
fi
mkdir -p /opt/source
echo "开始下载redis 最新稳定版"
wget -P /opt/source https://download.redis.io/redis-stable.tar.gz
echo " 解压redis"
tar -xzvf /opt/source/redis-stable.tar.gz -C /opt/source
cd /opt/source/redis-stable
make MALLOC=jemalloc && make install PREFIX=/opt/redis
if [ ! $? -eq 0 ];then
echo "redis 部署异常"
else
mkdir -p /opt/redis/data /opt/redis/conf /opt/redis/logs
fi
cat > /opt/redis/conf/redis.conf << EOF
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/opt/redis/logs/redis.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /opt/redis/data
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
replica-priority 100
acllog-max-len 128
requirepass R2d1ss#!1324
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 yes
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
slowlog-log-slower-than 10000
slowlog-max-len 128
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 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
EOF
echo "将redis配置为服务"
cat > /usr/lib/systemd/system/redis.service << EOF
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/opt/redis/bin/redis-server /opt/redis/conf/redis.conf
ExecStop=/opt/redis/bin/redis-cli shutdown
[Install]
WantedBy=multi-user.target
EOF
echo "将redis 设置为开机启动 "
systemctl daemon-reload
systemctl start redis
if [ ! $? -eq 0 ]; then
echo " redis 启动出现异常"
else
systemctl enable redis
fi
sleep 10
ss -ntualp |grep 6379
if [ $? -eq 0 ];then
echo "redis 部署已完成"
fi