阅读原文: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
来源: 简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。