Skip to content

linux下安装redis7.0.0 (集群)

上传安装包并解压

bash
cd /opt/redis-7.0.0

yum -y install gcc
//需要有gcc环境 可能需要连接外网 编译1分钟左右
make && make install
//默认安装/usr/local/bin
redis-benchmark:性能测试工具
redis-check-aof 修复有问题的aof文件
redis-check-dump  修复有问题的dump.rdb文件
redis-cli
redis-sentinel
redis-server
bash
/opt/redis-7.0.0/redis.conf
redis的配置文件
更改
daemonize yes
protected-mode no
#bind 127.0.0.1
requirepass `密码`
appendonly yes
bash
启动redis
redis-server /myredis/redis7.conf
登录
redis-cli -a 111111
或者
redis-cli 
auth 111111

开启AOF

6之前 dir 
aof有且只有一个
7 multi part 1-3

主从复制

bash
master requirepass 111111
masterauth 111111
1 master 2 node


守护进程
日志
logfile "/myredis/6379.log"

dump

aop

node 才配置
# replicaof 192.168.152.132 6379
# masterauth "111111"


先主后从

之后启动
salveof ip port
slaveof no one

哨兵
投票换主机

哨兵

bash
"sentinel.conf"

sentinel monitor mymaster 127.0.0.1 6379 2

# sentinel auth-pass <master-name> <password>
bind 0.0.0.0
daemonize yes
protected-mode no
port 26380
logfile "/myredis/sentinel26380.log"
pidfile /var/run/redis-sentinel26380.pid
dir /myredis
sentinel monitor mymaster 192.168.152.132 6379 2
sentinel auth-pass mymaster 111111
先主后从再哨兵
bash
集群
16384
0
cluster
3 3从 6380-6386

bind 0.0.0
daemonize yes
protected-mode no
port 6386
logfile "/myredis/cluster/cluster6386.log"
pidfile /myredis/cluster6386.pid
dir /myredis/cluster
dbfilename dump6386.rdb
appendonly yes
appendfilename "appendonly6386.aof"
requirepass 111111
masterauth 111111

cluster-enabled yes
cluster-config-file nodes-6386.conf
cluster-node-timeout 5000

####
[root@node2 cluster]# ps -ef |grep redis
root      19287      1  0 21:04 ?        00:00:20 redis-server *:6379
root      19485      1  0 22:28 ?        00:00:00 redis-server 0.0.0:6385 [cluster]
root      19491      1  0 22:29 ?        00:00:00 redis-server 0.0.0:6386 [cluster]
root      19500  19205  0 22:29 pts/0    00:00:00 grep --color=auto redis

redis-cli -a 111111 --cluster create --cluster-replicas 1 192.168.152.132:6381  192.168.152.132:6382 192.168.152.101:6383 192.168.152.101:6384 192.168.152.102:6385 192.168.152.102:6386

cluster nodes

路由登录
redis-cli -a 111111 -p 6381 -c

 CLUSTER KEYSLOT k1
 
 增加节点
 redis-cli -a 111111 --cluster add-node 192.168.152.102:6387 192.168.152.132:6381
 
检查 
 redis-cli -a 111111 --cluster check 192.168.152.132:6381
 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.152.101:6384 (b623e644...) -> 2 keys | 5461 slots | 1 slaves.
192.168.152.101:6383 (1c74f365...) -> 1 keys | 5462 slots | 1 slaves.
192.168.152.102:6385 (59bc6f9e...) -> 1 keys | 5461 slots | 1 slaves.
192.168.152.102:6387 (e425a958...) -> 0 keys | 0 slots | 0 slaves.

#重新hash
redis-cli -a 111111 --cluster reshard 192.168.152.132:6381

给增加master的添加从节点
redis-cli -a 111111 --cluster add-node 192.168.152.102:6388 192.168.152.102:6387 --cluster-slave --cluster-master-id e425a958092d55cf77116d55208e7b61b5506f9b

#删除从节点
redis-cli -a 111111 --cluster del-node 192.168.152.102:6388 216332b591789cc7f4c6c7e2d83343c6e06d6726
#删除主节点 重新分配solt
先删solt
重新hash 变成node节点
redis-cli -a 111111 --cluster reshard 192.168.152.132:6381
redis-cli -a 111111 --cluster del-node 192.168.152.102:6387 e425a958092d55cf77116d55208e7b61b5506f9b

mset k1{z} z1 k2{z} z2 k3{z} z3

cluster-repuire-full-coverage yes

多线程默认关闭
# So for instance if you have a four cores boxes, try to use 2 or 3 I/O
# threads, if you have a 8 cores, try to use 6 threads. In order to
# enable I/O threads use the following configuration directive:

# io-threads 4

# Setting io-threads to 1 will just use the main thread as usual.
# When I/O threads are enabled, we only use threads for writes, that is
# to thread the write(2) syscall and transfer the client buffers to the
# socket. However it is also possible to enable threading of reads and
# protocol parsing using the following configuration directive, by setting
# it to yes:

# io-threads-do-reads no


for((i=1;i<100*10000;i++)); do echo "set k$i v$i" >> /tmp/redisTest.txt ;done

cat /tmp/redisTest.txt | redis-cli -h 127.0.0.1 -p 6379 -a 111111 --pipe

禁用命令
# rename-command CONFIG ""
rename-command keys  ""
rename-command flushdb ""
rename-command flushall ""


redis-cli -a 111111 -p 6379  --bigkeys


lazyfree-lazy-server-del yes
replica-lazy-flush yes
lazyfree-lazy-user-del yes