一、基本操作
1、登录集群
cd /app/redis_cls/6370
./redis-cli -h ..**.31 -p 6370 -a 密码
./redis-cli -h 127.0.0.1 -p 6370 -a 密码
2、重启服务
执行sudo service redisBoot stop命令,可停止服务。
执行sudo service redisBoot restart命令,可重启服务。
ps -ef | grep redis
服务器规划说明
6台机器对比3台机器,提供更高可靠性保证.3台机器下。在1台机器故障修复加入集群后,有概率同一台机器内出现同一机器上有2个主节点。当2个主节点机器发生故障后,那么就造成集群不可写入。所以通常采用6台机器集群避免此类情况发生。
二、集群检查
1.集群状态
..**.31:6370>cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:13
cluster_my_epoch:10
cluster_stats_messages_ping_sent:44554057
cluster_stats_messages_pong_sent:46214308
cluster_stats_messages_sent:90768365
cluster_stats_messages_ping_received:46214308
cluster_stats_messages_pong_received:4455
2.集群节点信息
...31:6370>cluster nodes
3d140a874eecd5831dc0f36ba88dd7c7e1b50e88 ...26:6370@16370 slave af9b571d931c19d305fb3bbc135e504172d8bf99 0 1620784986288 8 connected
d385a6814d9e2597c9a06861c45a6670ac32065d ...29:6370@16370 master - 0 1620784986000 11 connected 10923-16383
518562a7fbc31f1806fb6fbc40148a4598097280 ...31:6370@16370 myself,master - 0 1620784986000 10 connected 5461-10922
a089b75de3465d4e43c094642bdc9d7e3a4ff138 ...28:6370@16370 slave d385a6814d9e2597c9a06861c45a6670ac32065d 0 1620784987000 11 connected
84794f334339f2efb9565860c4e22d0318efe44d ...27:6370@16370 slave 518562a7fbc31f1806fb6fbc40148a4598097280 0 1620784987290 10 connected
af9b571d931c19d305fb3bbc135e504172d8bf99 ..**.30:6370@16370 master - 0 1620784988293 8 connected 0-5460
3、查看每个节点客户端连接数
允许最大连接数:config get maxclients
..**.31:6370>info clients
如果数值过大,查询下系统连接数,定位那个业务系统发起大量连接,可以初步判断哪个系统引起连接异常
Root用户下执行:netstat -an | wc -l
查出哪个IP地址连接最多,进行后续处理.
netstat -na|grep ESTABLISHED|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r
netstat -na|grep SYN|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r
netstat -na|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r
4.节点内存、cpu、key数量等信息(每个节点都需查看)
Info
5.从redis集群中查看key(只需要连接master节点查看)
a.查看该节点的所有key
redis-cli -h ip -p 9379 -a password keys *
b.查看key的value值
redis-cli -h ip -p 9379 -a password -c get key
c.查看key值得有效期
redis-cli -h ip -p 9379 -a password -c ttl key
查看 redis 中存的数据
1.ssh root@ip
2.Password: password
3.keys *
4.查看存储的数据剩余过期时间
ttl key
4.查看key的类型(string,set,list,hash)
type key
5.查看key的值(string类型)
get key
6.查看key的值(set类型)
scard key //获取 set 集合中元素的数量
smembers key //查看 set 中的内容
7.查看key的值(hash类型)
hlen key //获取 key 键的字段数量
hgetall key //返回 key 键的所有字段及其值
hkeys key //获取 key 键中所有字段的名字
hvals key //获取 key 键中所有字段的值
三、集群参数优化
1、连接空闲超时30s
vi /app/redis_cls/6370/redis.conf
timeout 30
2、redis默认连接数最大值为10000,中心业务此参数满足,如果出现过大,检查业务系统连接是否异常
四、集群异常,重新加入
1、在集群上看,发现它已脱离集群,且id都已发生了变化:
/若id没发生变化,直接重启下该从节点就能解决/
...36:6390> cluster nodes
c9631aa4d3499ea1d4c5d11cf79b797f32fcd548 ...36:6370@16370 master - 0 1633919930862 1 connected 0-5460
01df710782e716717c82ba33e09abbf7d434cfd3 ...37:6370@16370 master - 0 1633919928855 3 connected 5461-10922
0331601f3bbb7fdca8c4090acaad3ef78a411a87 ...37:6390@16390 slave c9631aa4d3499ea1d4c5d11cf79b797f32fcd548 0 1633919929859 1 connected
a2eb2f921dca8d23768a84fe0d9d29f5d46a740d :0@0 slave,noaddr 01df710782e716717c82ba33e09abbf7d434cfd3 1633917310841 1633917306000 3 disconnected
8908144e78f73388609b322f9593b32394df3b3d :0@0 master,fail,noaddr - 1633917041380 1633917036334 5 disconnected
b5c700c693ef2d258d8311f431290ae8ceaf64f9 ..**.36:6390@16390 myself,master - 0 1633919928000 7 connected 10923-16383
(注意以新加节点为slave)
2、将该从节点剔出集群
...36:6390> cluster forget a2eb2f921dca8d23768a84fe0d9d29f5d46a740d
OK
...36:6390> cluster forget 8908144e78f73388609b322f9593b32394df3b3d
OK
3、重新将该节点加入集群
...36:6390> cluster meet ...38 6370
OK
...36:6390> cluster meet ...38 6390
OK
4、查看状态
...36:6390> cluster nodes
8698f4127959eb416772b2beb30e0cc14c060237 ...38:6390@16390 slave 01df710782e716717c82ba33e09abbf7d434cfd3 0 1633920233015 3 connected
0524da49d016e6e6d2aaa17b108ab76e194b9577 ...38:6370@16370 slave b5c700c693ef2d258d8311f431290ae8ceaf64f9 0 1633920235022 7 connected
c9631aa4d3499ea1d4c5d11cf79b797f32fcd548 ...36:6370@16370 master - 0 1633920234019 1 connected 0-5460
01df710782e716717c82ba33e09abbf7d434cfd3 ...37:6370@16370 master - 0 1633920234000 3 connected 5461-10922
0331601f3bbb7fdca8c4090acaad3ef78a411a87 ...37:6390@16390 slave c9631aa4d3499ea1d4c5d11cf79b797f32fcd548 0 1633920233000 1 connected
b5c700c693ef2d258d8311f431290ae8ceaf64f9 ..**.36:6390@16390 myself,master - 0 1633920234000 7 connected 10923-16383