閱讀原文:https://blog.csdn.net/qq_36737803/article/details/90578860
## 下載官方源碼包后,解壓編譯
# http://www.redis.cn/download/
cd /usr/local/src && wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar zxf /usr/local/src/redis-5.0.5.tar.gz -C /usr/local/
yum install -y gcc-c++ make
## 安裝完可以刪除 yum remove -y gcc-c++ make
cd /usr/local/redis-5.0.5 && make
## 這一步官網沒有,應該是可以省略的
make test && make install
## 也可以使用自帶工具初始化,指定目錄和配置、端口:
sh utils/install_server.sh
mkdir etc bin log
cp redis.conf etc/redis_default.conf
grep -vP '^#|^$' > etc/redis.conf ## 簡化配置,再修改
# tcp-keepalive 時間不能太長,有些服務會異常,默認300s,改為 60s
cp src/mkreleasehdr.sh bin/
cp src/redis-benchmark bin/
cp src/redis-check-aof bin/
cp src/redis-check-rdb bin/
cp src/redis-cli bin/
cp src/redis-sentinel bin/
cp src/redis-server bin/
cp src/redis-trib.rb bin/
## 啟動,並檢查日志
/usr/local/redis-5.0.5/bin/redis-server /usr/local/redis-5.0.5/etc/redis.conf
## """
3733276:M 22 Feb 2022 17:21:35.781 # Server initialized
3733276:M 22 Feb 2022 17:21:35.781 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
3733276:M 22 Feb 2022 17:21:35.781 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
3733276:M 22 Feb 2022 17:21:35.781 * Ready to accept connections
3733276:M 22 Feb 2022 17:21:35.781 * The server is now ready to accept connections at /usr/local/redis-5.0.5/redis.sock
"""
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1 > /dev/null
echo never > /sys/kernel/mm/transparent_hugepage/enabled
### 編寫啟停腳本
## 編寫 bin/startup.sh
#!/bin/bash
# @env
sysctl vm.overcommit_memory=1 > /dev/null
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# startup
/usr/local/redis-5.0.5/bin/redis-server /usr/local/redis-5.0.5/etc/redis.conf
## 編寫 bin/stop.sh
#!/bin/bash
kill -9 `ps -ef |grep 'redis-5.0.5'|grep -v grep|awk '{print $2}'`
## 連接redis,查看
/usr/local/redis-5.0.5/bin/redis-cli.sh -h 127.0.0.1 -p 6379
> keys *
## 配置文件redis.conf
# 配置說明信息可以看未簡化前的配置文件 redis_default.conf
# bind 127.0.0.1 實驗單機測試,不需外聯,保持默認的 127.0.0.1
# logfile /usr/local/redis-5.0.5/logs/redis.log 日志目錄,默認為 ""(空)
# dir /usr/local/redis-5.0.5/ 工作目錄(workdir),默認為 ./
# daemonize 后台啟動,默認為 no,修改為 yes
# protected-mode 屬性未修改,默認為 yes (如需遠程訪問,則要關閉保護模式,設置為 no,不然會阻止遠程訪問,同時修改bind綁定的IP為本機外聯IP(非127.x.x.x))
# requirepass 實驗測試,不啟用密碼
bind 127.0.0.1
unixsocket /usr/local/redis-5.0.5/redis.sock
unixsocketperm 777
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
#tcp-keepalive 300
tcp-keepalive 60
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /usr/local/redis-5.0.5/logs/redis.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
# dbfilename 不能指定路徑,只能指定文件名
dbfilename dump.rdb
#dir ./
dir /usr/local/redis-5.0.5/
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
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
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 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
## 其他參考:
Redis配置說明
Redis的運行依賴於配置,配置不同,Redis的性能也會受到影響。
下面對常用的Redis配置進行簡要說明:
timeout: 空閑客戶端超時時間
Axmemory: 內存容量
maxmemory-policy: 當內存容量超過Maxmemory時的處理策略
hash-max-ziplist-entries ziplist: 最大限制大小
hash-max-ziplist-value: value使用ziplist的最大限制大小
list-max-ziplist-entries: list使用ziplist的最大限制大小
list-max-ziplist-value: list value使用ziplist最大限制大小
set-max-intset-entries: set使用ziplist的最大限制大小
zset-max-ziplist-entries: zset使用ziplist的最大限制大小
zset-max-ziplist-value: zset value使用ziplist最大限制大小
作者: 大大老濕
鏈接: https://www.jianshu.com/p/95b1e3b7d29f
來源: 簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。