**- 基于keepalived部署milvus高可用问题:
双写冷备:两个写节点不能同时启动,否则会导致数据重复,通过增加与网关的连通性来解决可能同时启动的问题,但不能完全保证没有特殊情况的存在。另外宕机时可能会导致数据丢失。
一写一读:可以同时启动,但是写节点宕机时,数据不能写入。
** - 基于minio的共享存储,写入速度比本地磁盘慢,如果数据量较大需要适当减小index_file_size,默认1024M,可设置为512M。**
一、milvus安装
docker pull milvus
新建目录
/data/milvus/db
/home/milvus/wal
/home/milvus/conf
/home/milvus/logs
/home/milvus/wal
其中db位于minio挂载到本地的目录,其他为本地磁盘目录,conf下存放server_config.yaml
启动:
docker run -d --name milvus -p 19530:19530 -p 19121:19121 -p 9091:9091 -v /data/milvus/db:/var/lib/milvus/db -v /home/milvus/conf:/var/lib/milvus/conf -v /home/milvus/logs:/var/lib/milvus/logs -v /home/milvus/wal:/var/lib/milvus/wal milvusdb/milvus:0.9.0-cpu-d051520-cb92b1
若docker启动报错Cannot set property TasksAccounting
执行:yum update
二、keepalived
1. 安装
yum install keepalived
2. 双写冷备配置
主备节点milvus不能同时启动。
Keepalived监控milvus,vip发生迁移时,首先停掉非vip节点的milvus,然后启动vip节点的milvus。
主节点恢复正常后,vip不从冷备节点转移至主节点,只有冷备节点异常后才转移。
主节点配置:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id sol01 #主机路由ID
}
vrrp_script monit_milvus
{
script "/home/monit_milvus.sh"
interval 3
}
vrrp_instance VI_SERVER {
state BACKUP # 主机服务器模式,备机设为BACKUP
interface eth0 # 主机监控网卡实例
virtual_router_id 39 # VRRP组名,主备机设置必须完全一致
priority 110 # 优先级(1-254),主机设置必须比备机高,备机可设为90
nopreempt # 不抢占,只在优先级高的机器上设置即可,优先级低的机器不设置
authentication { # 认证信息,主备机必须完全一致
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { # 虚拟IP地址,主备机必须完全一致
192.168.16.244/24 # 注意配置子网掩码
}
track_script
{
monit_milvus
}
notify_master "/home/start_milvus.sh"
}
冷备节点配置:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id sol02 # 备机路由ID
}
vrrp_script monit_milvus
{
script "/home/monit_milvus.sh"
interval 3
}
vrrp_instance VI_SERVER {
state BACKUP # 主机服务器模式,备机设为BACKUP
interface eth0 # 备机监控网卡实例
virtual_router_id 39 # VRRP组名,主备机设置必须完全一致
priority 91 # 优先级(1-254),主机设置必须比备机高,备机可设为90
authentication { # 认证信息,主备机必须完全一致
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { # 虚拟IP地址,主备机必须完全一致
192.168.16.244/24 # 注意配置子网掩码
}
track_script
{
monit_milvus
}
notify_master "/home/start_milvus.sh"
}
3. 监控脚本
monit_milvus.sh
#!/bin/bash
# 判断是否获取vip,并且vip与网关是否通
minio=http://192.168.16.41:9000
CHECK_TIME=3
VIP=192.168.16.244
GATEWAY=192.168.16.1
eth=eth0
#另外一台节点的host
host=type1-08
# 判断与网关的连通性
/sbin/arping -I $eth -c 2 -s $VIP $GATEWAY >/dev/null 2>&1
#为vip且通,不为vip时返回值为2
if [ $? = 0 ] ; then
echo "是vip且通" >>/home/monit.log
# 判断Minio是否挂载
miniocount=`df | grep /data/milvus | wc -l`
if [[ $miniocount == 0 ]]; then
s3fs -o passwd_file=/etc/passwd-s3fs -o use_path_request_style -o url=$minio -o allow_other -o bucket=milvusdata /data/milvus
fi
# 检测并启动milvus
RUNNING_STATUS=$(docker inspect --format '{{.State.Running}}' milvus)
if [[ "${RUNNING_STATUS}" != "true" ]];then
ssh root@$host "docker kill milvus"
docker start milvus
echo starting >>/home/monit.log
fi
echo started >>/home/monit.log
fi
4. notify_master脚本
start_milvus.sh
#!/bin/bash
VIP=192.168.16.244
GATEWAY=192.168.16.1
eth=eth0
#另外一台节点的host
host=type1-08
echo "-----------" >>/home/start.log
echo "start monit" >>/home/start.log
/sbin/arping -I $eth -c 1 -s $VIP $GATEWAY >/dev/null 2>&1
if [ $? = 0 ] ;then
RUNNING_STATUS=$(docker inspect --format '{{.State.Running}}' milvus)
if [[ "${RUNNING_STATUS}" != "true" ]];then
ssh root@$host "docker kill milvus"
docker start milvus
echo "start milvus" >>/home/start.log
fi
else
RUNNING_STATUS=$(docker inspect --format '{{.State.Running}}' milvus)
if [[ "${RUNNING_STATUS}" == "true" ]];then
docker kill milvus
echo "kill milvus" >>/home/start.log
fi
fi
启动:
systemctl enable keepalived
systemctl start keepalived