redis集群

集群和哨兵

配置

集群

特点

集群负载均衡

热点数据分片都在同一个槽 (1.重新分片 2.槽节点配置从服务器?)

投票选举

容器

start

重启容器ip变化导致配置不对

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
#!/bin/bash

DIR="$(cd "$(dirname "$0")" && pwd)"
cd $DIR
export LD_LIBRARY_PATH=$DIR:$LD_LIBRARY_PATH


hosts=/etc/hosts
conf=/var/lib/redis/nodes.conf

newip=$(cat $hosts|grep redis-app|awk '{print $1}')
[ "$newip"x != ""x ] || { echo "hosts里没有找到redis-app的ip,退出" && exit 1; }

ckeckConf(){
[ -f "$1" ] || { echo "集群配置文件nodes.conf不存在,集群初始化中..." && return; }


echo "检查nodes.conf文件内容..."
arr="$(cat $1|grep -E "master|slave"|awk '{print $1}')"
len=$(echo "${arr}" | wc -l)
echo -e "$len条clusterid,如下: \n""${arr}"
[ "$len" -ne 1 ] || { echo "集群配置文件clusterid数目不对,请到nfs服务器核查node.conf文件,退出" && exit 1; }


myselfid=$(cat $1 |grep myself|awk '{print $1}')
[ "$myselfid"x != ""x ] || { echo "nodes.conf里没有找到myselfid,退出" && exit 1; }
echo "把新ip写入自身clusterid文件内..."
echo $newip > $PWD/$myselfid
echo "k8s重启后: $myselfid -> $newip";

for i in ${arr};
do
[ -f "./$i" ] || { echo "没有./$i这个目录" && continue; }

checkip=$(cat ./$i)
[ "$checkip"x != ""x ] || { echo "clusterid文件内容为空" && continue; }

echo "执行命令:ping -c1 $checkip"
$DIR/ping -c1 $checkip
[ $? -ne 1 ] || { echo "ping $newip 结果返回ip不通" && continue; }

oldip=$(cat $1 |grep -E "^$i"|awk '{print $2}'|cut -d ":" -f1)
[ "$oldip"x != ""x ] || { echo "clusterid在nodes.conf里没有搜索到ip,退出" && exit 1; }

echo "oldip:$oldip =========== newip:$checkip"
sed -i "s/$oldip/$checkip/g" $1
[ $? -ne 0 ] || { echo "完成替换,clusterid:$i === ip:$checkip" && continue; }

done

echo "配置文件nodes.conf,检查完毕..."
}

echo "$newip 开始检查配置文件nodes.conf"
ckeckConf $conf

[ "$(which redis-server)"x != ""x ] || { echo "找不到redis-server,退出" && exit 1; }
echo "开始启动服务...."
echo "执行命令:redis-server $1 --cluster-announce-ip $newip"
redis-server $1 --cluster-announce-ip $newip

 .
├──  libcap.so.2
├──  libidn.so.11
├──  ping
└──  start.sh

pod

1
2
3
4
5
6
7
8
9
10
11
kubectl -n devops get pods
NAME READY STATUS RESTARTS AGE
redis-app-0 1/1 Running 0 50m
redis-app-1 1/1 Running 0 50m
redis-app-2 1/1 Running 0 44m
redis-app-3 1/1 Running 0 38m
redis-app-4 1/1 Running 0 38m
redis-app-5 1/1 Running 0 38m

kubectl -n devops exec -it redis-app-2 /bin/bash
kubectl -n devops exec -it redis-app-4 /bin/bash

redis-cli -c -p 6379

svc ClusterIP

两次认证?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
cs@debian:~/oss/hexo$ kubectl get svc -n devops
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
jenkins ClusterIP 121.21.92.146 <none> 8081/TCP,50000/TCP 105d
redis-headless-service ClusterIP None <none> 6379/TCP 13d
redis-service ClusterIP 121.21.24.33 <none> 6379/TCP 13d
tomcat ClusterIP 121.21.191.100 <none> 8082/TCP 105d

cs@debian:~/oss/hexo$ kubectl exec -it redis-app-1 -n devops /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
.............
root@redis-app-1:/data# redis-cli -c -h 121.21.24.33 -p 6379
121.21.24.33:6379> auth 123456
OK
121.21.24.33:6379> ping
PONG
121.21.24.33:6379> get test21
-> Redirected to slot [8530] located at 121.21.35.3:6379
(error) NOAUTH Authentication required.
121.21.35.3:6379> auth 123456
OK
121.21.35.3:6379> get test21
"20220721cs"

traefik deploay 配置 redis

1
2
3
4
5
cs@debian:/opt/kubernetes/yaml/k8s/tcp/redis$ redis-cli  -c  -p  6379
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> ping
PONG

127.0.0.1 - 192.168.56.103:6379, 192.168.56.101:6379, 192.168.56.102:6379 - [19/Jul/2022:22:10:12 +0800] 200 0, 0, 82

不通超时

根据podip定位集群pod

1
2
3
cs@debian:~/oss/hexo$  kubectl  get pod --field-selector status.podIP=121.21.35.3 -o wide -n devops
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
redis-app-1 1/1 Running 1 9d 121.21.35.3 node04 <none> <none>
点击打赏
文章目录
  1. 1. 集群和哨兵
    1. 1.1. 集群
  2. 2. 容器
    1. 2.1. start
    2. 2.2. pod
    3. 2.3. svc ClusterIP
    4. 2.4. 不通超时
载入天数...载入时分秒... ,