總結:整理不易,如果對你有幫助,可否點贊關注一下?
更多詳細內容請參考:《Linux運維篇:Linux系統運維指南》
一、環境信息
環境信息如下:
主機IP | 操作系統 | Redis版本 | CPU架構 |
---|---|---|---|
192.168.1.111 | Kylin Linux Advanced Server V10 (Tercel) | 7.2.6 | 4.19.90-17.5.ky10.aarch64 |
二、創建啟動用戶
[root@localhost ~]# groupadd --gid 1301 redis
[root@localhost ~]# useradd -u 1301 -g 1301 -d /home/redis -s /usr/sbin/nologin -m redis
三、編譯安裝
1、安裝環境依賴
[root@localhost ~]# yum install gcc make glibc-devel openssl-devel systemd-devel tcl -y
2、安裝包下載
[root@localhost ~]# wget https://download.redis.io/releases/redis-7.2.6.tar.gz
3、把redis安裝到指定目錄
[root@localhost ~]# tar axf redis-7.2.6.tar.gz
[root@localhost ~]# cd redis-7.2.6
# 啟用對systemd的支持
[root@localhost redis-7.2.6]# BUILD_WITH_SYSTEMD=yes
[root@localhost redis-7.2.6]# make install PREFIX=/opt/redis7
說明:這時候,我們就能在/opt/redis7下面看到一個bin目錄,redis的可執行文件都被復制到這里。
4、創建配置文件目錄、數據目錄、日志目錄
[root@localhost ~]# mkdir /opt/redis7/conf
[root@localhost ~]# mkdir /opt/redis7/data
[root@localhost ~]# mkdir /opt/redis7/logs
5、目錄授權
[root@localhost ~]# chown redis:redis /opt/redis7 -R
[root@localhost ~]# chmod 755 /opt/redis7
說明:由于銀河麒麟V10操作系統新創建目錄權限均是最小化,如果你創建的目錄是多級目錄,請確保redis7的上層目錄權限為755,比如,你創建的數據目錄為/data/basic-data/redis/data,請確保/data/basic-data/redis/data這四層目錄的每一層目錄權限均為755。
6、把redis執行文件加入到path中
[root@localhost ~]# vim /etc/profile
export REDIS_HOME=/opt/redis7
export PATH=$PATH:$REDIS_HOME/bin
[root@localhost ~]# source /etc/profile
7、修改redis配置文件
參考:redis配置文件詳解
[root@localhost ~]# cp redis-7.2.6/redis.conf /opt/redis7/conf/redis.conf
[root@localhost ~]# vim /opt/redis7/conf/redis.conf
bind 127.0.0.1 192.168.1.111
protected-mode yes
port 47000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised systemd
pidfile /var/run/redis.pid
loglevel notice
logfile "/opt/redis7/logs/redis.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
locale-collate ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /opt/redis7/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 JHFkjSXYK6eXF3L3
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 noslowlog-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
set-max-listpack-entries 128
set-max-listpack-value 64
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
ignore-warnings ARM64-COW-BUG
四、配置systemd管理redis
[root@localhost ~]# vim /etc/systemd/system/redis.service
[Unit]
Description=Redis Server
After=network.target
[Service]
User=redis
Group=redis
Type=notify
LimitNOFILE=65535
ExecStart=/opt/redis7/bin/redis-server /opt/redis7/conf/redis.conf
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
五、啟動redis服務
[root@localhost ~]# systemctl daemon-reload && systemctl start redis && systemctl enable redis
總結:整理不易,如果對你有幫助,可否點贊關注一下?
更多詳細內容請參考:《Linux運維篇:Linux系統運維指南》