安装redis6.0.5

下载与解压

wget http://download.redis.io/releases/redis-6.0.5.tar.gz

tar -xvf redis-6.0.5.tar.gz

cd redis-6.0.5

编译安装

需要gcc 5.3以上

cd deps/

make *

../

make

进入并且置顶安装目录

cd src/
make install PREFIX=/usr/local/redis

启动服务

/usr/local/redis/bin/redis-server 启动服务

解决启动时候redis的提示信息

sysctl vm.overcommit_memory=1
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 512 >  /proc/sys/net/core/somaxconn

修改配置文件

如果是本地测试环境、可以允许任何来源访问,请设置为

**bind 0.0.0.0
protected-mode no**

关于 maxmemory参数

此参数单位是可根据内存大小换算1KB=1024btyes

网络计算工具:https://www.bejson.com/convert/filesize/

请输入图片描述

bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel warning
logfile "/usr/local/redis/log/redis_6379.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /usr/local/redis/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
maxmemory 2147483648
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
io-threads 6
io-threads-do-reads yes
appendonly yes
appendfilename "redis_data_6379.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 128mb
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 "Ex"
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
jemalloc-bg-thread yes

在redis6.0.5中新增了几个配置

io-threads 3
io-threads-do-reads yes

io-threads 根据cpu的核数一般3-4数值,如果4核心设置3。如果8核心设置6。超过8性能提升不大

查看cpu是几核心

lscpu

把redis添加到系统服务

[root@localhost bin]# vi /etc/systemd/system/redis.service

设置开机启动


systemctl daemon-reload

systemctl start redis.service

systemctl enable redis.service

下面的适用与centos8

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking

ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

安装过程中出现的错误

cc: 错误:../deps/hiredis/libhiredis.a:没有那个文件或目录
cc: 错误:../deps/lua/src/liblua.a:没有那个文件或目录
cc: 错误:../deps/jemalloc/lib/libjemalloc.a:没有那个文件或目录
make[1]: *** [Makefile:271:redis-server] 错误 1
make[1]: 离开目录“/root/redis-6.0.5/src”
make: *** [Makefile:6:all] 错误 2


进入源码包目录下的deps目录中执行

cd ../deps/
make  hiredis
make  jemalloc
make  linenoise
make  lua

Last modification:November 17, 2020
如果觉得我的文章对你有用,请随意赞赏