官网下载

问题

说一下,安装 redis 碰到的问题

1
2
3
4
5
Q:zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
A:make MALLOC=libc

Q:You need tcl 8.5 or newer in order to run the Redis test
A:yum -y install tcl

配置

文件配置的不同点

  1. port 端口号
  2. pidfile pid文件名
  3. logfile日志文件名
  4. cluster-config-file 自维护配置名
  5. dir 存储数据目录

贴下配置,除了必要更改部分其余为默认

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes #后台启动
supervised no
pidfile /var/run/redis_6379.pid #pid文件位置
loglevel notice
logfile "/opt/redis/logs/1/redis.log" #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
dir /opt/redis/data/1 #数据存储目录
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly yes #启用AOF
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 no
lua-time-limit 5000
cluster-enabled yes #原本为注释,启用集群
cluster-config-file nodes-6379.conf #注意每个redis会自己维护这个nodes文件,但配置时候名称要不同
cluster-node-timeout 15000
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
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

注意请不要直接使用此配置,建议手动修改

大部分参数为官方默认,我并未修改

初始化

初始化集群和redis版本也有关系

If you are using Redis 5, this is very easy to accomplish as we are helped by the Redis Cluster command line utility embedded into redis-cli, that can be used to create new clusters, check or reshard an existing cluster, and so forth.

For Redis version 3 or 4, there is the older tool called redis-trib.rb which is very similar. You can find it in the src directory of the Redis source code distribution. You need to install redis gem to be able to run redis-trib.

这是官方文档的描述

意思为3和4 版本 redis 需要gem安装redis 才能使用redis-trib

但5版本直接使用redis-cli即可

我测试为 4 版本

安装ruby和gem

1
2
3
4
5
6
7
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
#为什么执行两次gpg2 ? 第一次获取公钥失败,显示结果为第二条命令 执行后获取成功
curl -sSL https://get.rvm.io | bash -s stable --rails
source /usr/local/rvm/scripts/rvm
ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

使用gem

1
gem install redis

初始化集群

1
2
3
4
5
6
redis-trib.rb create --replicas 1 192.168.227.142:6379 192.168.227.142:7000 192.168.227.142:7001 192.168.227.142:7003 192.168.227.142:7004 192.168.227.142:7005
输入yes后,会展示如下
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

出现OK即为成功

连接redis节点

1
2
redis-cli -c -p 6379
经测试如果不加-c会无法连接其他 节点,无法获取数据 但本节点数据可以获取

gem
redis cluster