# 配置Docker 环境
[root@HA-Deploy ha-app]# cat install-docker.sh
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start
# 制作镜像
# 应用一
[root@HA-Deploy ~]# cat Dockerfile-nginx-1
FROM centos
RUN rm -f /etc/yum.repos.d/*;curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
RUN yum install -y traceroute net-tools nginx
RUN yum clean all
RUN echo "<h1>NGINX1</h1>" >/usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
root@HA-Deploy ~]# docker build -t nginx-1 -f Dockerfile-nginx-1 .
# 应用二
[root@HA-Deploy ~]# cat Dockerfile-nginx-2
FROM centos
RUN rm -f /etc/yum.repos.d/*;curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
RUN yum install -y traceroute net-tools nginx
RUN yum clean all
RUN echo "<h1>NGINX2</h1>" >/usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
root@HA-Deploy ~]# docker build -t nginx-2 -f Dockerfile-nginx-2 .
[root@HA-Deploy ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-2 latest 114a77ae3797 6 days ago 345MB
nginx-1 latest d37ef28c3298 6 days ago 345MB
# 创建容器网络
[root@HA-Deploy ~]# docker network create subnet-app --subnet 172.20.0.0/16 --gateway 172.20.0.1
36782a56ef89b574eec9b2cb40523683c7b8b3502b99ab69080e21c7935bdc97
[root@HA-Deploy ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
a798b2660019 bridge bridge local
25210c5ac6b0 host host local
4b4775e29f19 none null local
36782a56ef89 subnet-app bridge local
# 运行应用
[root@HA-Deploy ~]# docker run -dit --name app1 --network subnet-app nginx-1
6f81d2d73bc934647e8ef832492661ff8418360113a7ac0c92d298a4c7c2ae99
[root@HA-Deploy ~]# docker run -dit --name app2 --network subnet-app nginx-2
f126314b8727a810caeb012f0ed0abe154da06f713b3ddcb303820d77b86ae75
[root@HA-Deploy ~]# docker exec -it app1 ip a
16: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:14:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.20.0.2/16 brd 172.20.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@HA-Deploy ~]# docker exec -it app2 ip a
18: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:14:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.20.0.3/16 brd 172.20.255.255 scope global eth0
valid_lft forever preferred_lft forever
[root@HA-Deploy ~]# docker exec -it app2 curl localhost
<h1>NGINX2</h1>
[root@HA-Deploy ~]# docker exec -it app1 curl localhost
<h1>NGINX1</h1>
# 创建DNAT规则
[root@HA-Deploy ~]# iptables -t nat -nL DOCKER
Chain DOCKER (2 references)
target prot opt source destination
RETURN all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
[root@HA-Deploy ~]# iptables -t nat -A DOCKER -d 192.168.3.84 -p tcp --dport 80 -j DNAT --to-destination 172.20.0.2:80
[root@HA-Deploy ha-app]# iptables -t nat -nL DOCKER
Chain DOCKER (2 references)
target prot opt source destination
RETURN all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
DNAT tcp -- 0.0.0.0/0 192.168.3.84 tcp dpt:80 to:172.20.0.2:80
[root@HA-Deploy ~]# curl 192.168.3.84
<h1>NGINX1</h1>
[root@HA-Deploy ~]# iptables -t nat -A DOCKER -d 192.168.3.84 -p tcp --dport 80 -j DNAT --to-destination 172.20.0.3:80
[root@HA-Deploy ha-app]# iptables -t nat -nL DOCKER
Chain DOCKER (2 references)
target prot opt source destination
RETURN all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
DNAT tcp -- 0.0.0.0/0 192.168.3.84 tcp dpt:80 to:172.20.0.3:80
[root@HA-Deploy ~]# curl 192.168.3.84
<h1>NGINX2</h1>
# 开启时钟同步
[root@HA-Deploy ~]# systemctl start chronyd.service
[root@HA-Deploy ~]# chronyc -n sourcestats -v
210 Number of sources = 4
.- Number of sample points in measurement set.
/ .- Number of residual runs with same sign.
| / .- Length of measurement set (time).
| | / .- Est. clock freq error (ppm).
| | | / .- Est. error in freq.
| | | | / .- Est. offset.
| | | | | | On the -.
| | | | | | samples. \
| | | | | | |
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
==============================================================================
202.118.1.81 2 0 2 +0.000 2000.000 +28801s 4000ms
202.162.32.12 2 0 2 +0.000 2000.000 +28801s 4000ms
158.101.221.122 2 0 2 +0.000 2000.000 +28801s 4000ms
94.237.64.20 2 0 3 +0.000 2000.000 +28801s 4000ms
[root@HA-Deploy ~]# date
Tue Apr 11 14:03:51 CST 2023
# 初始化安装环境
[root@HA-Deploy ha-app]# cat switch.cfg
APP1_IP_ADDR=172.20.0.2
APP2_IP_ADDR=172.20.0.3
HOST_IP_ADDR=192.168.3.84
[root@HA-Deploy ha-app]# cat app_init.sh
#!/bin/bash
function logger()
{
current_time=$(date '+%F %T')
log_level=INFO
app_name=${CURRENT_PROCESS}
output_info="default message"
while true;do
case $1 in
-t)
current_time=$2
shift 2
;;
-l)
log_level=$2
shift 2
;;
-n)
app_name=$2
shift 2
;;
-o)
output_info=$2
shift 2
;;
*)
break
;;
esac
done
printf "%s[%s][%s]%s\n" "${current_time}" ${log_level} ${app_name} "${output_info}"
}
function set_env()
{
grep CURRENT_PROCESS /etc/profile > /dev/null
if [ $? -ne 0 ];then
echo "export CURRENT_PROCESS=APP1" >> /etc/profile
source /etc/profile
logger -o "新增环境变量 CURRENT_PROCESS=${CURRENT_PROCESS}"
else
source /etc/profile
logger -o "已存在环境变量 CURRENT_PROCESS=${CURRENT_PROCESS}"
fi
}
function reset_iptables()
{
CURRENT_IP_ADDR=`grep ${CURRENT_PROCESS} switch.cfg |awk -F '=' '{print $2}'`
BACK_UP_IP_ADDR=`grep -vE "${CURRENT_PROCESS}|HOST_IP_ADDR" switch.cfg |awk -F '=' '{print $2}'`
HOST_IP_ADDR=`grep HOST_IP_ADDR switch.cfg |awk -F '=' '{print $2}'`
iptables -t nat -nL DOCKER | grep ${CURRENT_IP_ADDR}
if [ $? -eq 0 ];then
iptables -t nat -D DOCKER -d ${HOST_IP_ADDR} -p tcp --dport 80 -j DNAT --to-destination ${CURRENT_IP_ADDR}:80
logger -o "删除 ${CURRENT_IP_ADDR} 通道"
else
logger -o "不存在 ${CURRENT_IP_ADDR} 通道,无需清空"
fi
iptables -t nat -nL DOCKER | grep ${BACK_UP_IP_ADDR}
if [ $? -eq 0 ];then
iptables -t nat -D DOCKER -d ${HOST_IP_ADDR} -p tcp --dport 80 -j DNAT --to-destination ${BACK_UP_IP_ADDR}:80
logger -o "删除 ${BACK_UP_IP_ADDR} 通道" -n APP2
else
logger -o "不存在 ${BACK_UP_IP_ADDR} 通道,无需清空"
fi
iptables -t nat -A DOCKER -d ${HOST_IP_ADDR} -p tcp --dport 80 -j DNAT --to-destination ${CURRENT_IP_ADDR}:80
logger -o "创建初始化 ${CURRENT_IP_ADDR} 通道"
iptables -t nat -nL DOCKER| grep -vi return
}
function set_network()
{
docker network ls | grep subnet-app
if [ $? -ne 0];then
docker network create subnet-app --subnet 172.20.0.0/16 --gateway 172.20.0.1
else
logger -o "已存在subnet-app网络,无需清空"
fi
}
function app_init
{
set_env # 配置环境变量
reset_iptables # 重置IPTABLES规则
}
app_init
# 应用健康检查
[root@HA-Deploy ha-app]# cat app_ha.sh
#!/bin/bash
function logger() # 格式化日志输出
{
current_time=$(date '+%F %T')
log_level=INFO
app_name=${CURRENT_PROCESS}
output_info="default message"
while true;do
case $1 in
-t)
current_time=$2
shift 2
;;
-l)
log_level=$2
shift 2
;;
-n)
app_name=$2
shift 2
;;
-o)
output_info=$2
shift 2
;;
*)
break
;;
esac
done
printf "%s[%s][%s]%s\n" "${current_time}" ${log_level} ${app_name} "${output_info}"
}
function health_check() # 针对应用做定期检查
{
declare -i check_num=3
declare -i error_num=0
for i in `seq 1 ${check_num}`;do
echo $1
curl --connect-timeout 10 $1 && break || error_num=error_num+1
done
if [ $error_num -eq $check_num ];then
logger -l ERROR -o "节点 $1 异常"
return 1
fi
}
function switch_application() # 应用状态异常时,执行此应用逻辑
{
logger -o "开始进入切换流程"
logger -o "检验备用通道状态"
CURRENT_IP_ADDR=`grep ${CURRENT_PROCESS} switch.cfg |awk -F '=' '{print $2}'`
BACK_UP_IP_ADDR=`grep -vE "${CURRENT_PROCESS}|HOST_IP_ADDR" switch.cfg |awk -F '=' '{print $2}'`
if health_check ${BACK_UP_IP_ADDR};then
logger -o "备用通道正常,具备切换条件,开始切换..."
else
logger -l ERROR -o "备用通道异常,不具备切换条件,当前业务受影响,请及时人工解决。"
exit 1
fi
iptables -t nat -nL DOCKER | grep ${CURRENT_IP_ADDR}
if [ $? -eq 0 ];then
logger -o "正在关闭${CURRENT_PROCESS}通道..."
iptables -t nat -D DOCKER -d 192.168.3.84 -p tcp --dport 80 -j DNAT --to-destination ${CURRENT_IP_ADDR}:80
logger -o "已关闭${CURRENT_PROCESS}通道..."
else
logger -o "不存在${CURRENT_PROCESS}通道,无需关闭"
fi
CURRENT_PROCESS=`grep ${BACK_UP_IP_ADDR} switch.cfg |awk -F '_' '{print $1}'`
echo "=======${CURRENT_PROCESS}"
sed -i "/CURRENT_PROCESS/cexport CURRENT_PROCESS=${CURRENT_PROCESS}" /root/.bashrc
source /root/.bashrc
logger -o "正在开启${CURRENT_PROCESS}通道..."
iptables -t nat -A DOCKER -d 192.168.3.84 -p tcp --dport 80 -j DNAT --to-destination ${BACK_UP_IP_ADDR}:80
iptables -t nat -nL DOCKER | grep ${CURRENT_IP_ADDR}
health_check ${BACK_UP_IP_ADDR}
}
function main() # 主进程运行逻辑
{
WORK_DIR=`dirname "${BASH_SOURCE[0]}"`
cd ${WORK_DIR}
logger -o "当前工作目录 `pwd`"
source app_init.sh
while true;do
CURRENT_IP_ADDR=`grep ${CURRENT_PROCESS} switch.cfg |awk -F '=' '{print $2}'`
health_check ${CURRENT_IP_ADDR}
if [ $? -eq 1 ];then
switch_application
else
logger -o "应用正常,无需切换"
fi
sleep 10
done
}
main
# 创建守护进程
mkdir -p /apps/ha-app/
[root@HA-Deploy ~]# cd /apps/ha-app/
[root@HA-Deploy ha-app]# chmod u+x app_ha.sh
[root@HA-Deploy ha-app]# ll
total 20
-rwxr--r--. 1 root root 2719 Apr 11 22:13 app_ha.sh
-rw-r--r--. 1 root root 2124 Apr 11 21:37 app_init.sh
-rw-r--r--. 1 root root 313 Apr 4 21:43 Dockerfile-nginx-1
-rw-r--r--. 1 root root 313 Apr 4 21:43 Dockerfile-nginx-2
-rw-r--r--. 1 root root 73 Apr 11 21:27 switch.cfg
[root@HA-Deploy ha-app]# cat /etc/systemd/system/ha-app.service
[Unit]
Description= daemon for checking app status
[Service]
User=root
Group=root
WorkingDirectory=/apps/ha-app/
Environment=""
ExecStart=/apps/ha-app/app_ha.sh
ExecReload=/bin/kill -s HUP $MAINPID
RestartSec=5
[Install]
WantedBy=multi-user.target
[root@HA-Deploy ha-app]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f126314b8727 nginx-2 "nginx -g 'daemon of…" 6 hours ago Up 2 seconds 80/tcp app2
6f81d2d73bc9 nginx-1 "nginx -g 'daemon of…" 6 hours ago Up 2 hours 80/tcp app1
[root@HA-Deploy ha-app]# systemctl start ha-app.service
[root@HA-Deploy ha-app]# systemctl status ha-app.service
● ha-app.service - daemon for checking app status
Loaded: loaded (/etc/systemd/system/ha-app.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2023-04-12 01:00:38 CST; 1s ago
Main PID: 39400 (app_ha.sh)
Tasks: 2
Memory: 528.0K
CGroup: /system.slice/ha-app.service
├─39400 /bin/bash /apps/ha-app/app_ha.sh
└─39451 sleep 10
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:00:38[INFO][APP1]创建初始化 172.20.0.2 通道
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: Chain DOCKER (2 references)
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: target prot opt source destination
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: DNAT tcp -- 0.0.0.0/0 192.168.3.84 tcp dpt:80 to:172.20.0.2:80
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: [155B blob data]
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: <h1>NGINX1</h1>
Apr 12 01:00:38 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:00:38[INFO][APP1]应用正常,无需切换
[root@HA-Deploy ha-app]# docker stop app1;date "+%F %T"
app1
2023-04-12 01:05:53
Apr 12 01:05:59 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:05:59 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:05:59 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:06:09 HA-Deploy app_ha.sh[39400]: [866B blob data]
Apr 12 01:06:09 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10005 milliseconds
Apr 12 01:06:09 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:06:09 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:06:09 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:06:19 HA-Deploy app_ha.sh[39400]: [866B blob data]
Apr 12 01:06:19 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10001 milliseconds
Apr 12 01:06:19 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:06:19 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:06:19 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: [866B blob data]
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10002 milliseconds
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:06:29[ERROR][APP1]节点 172.20.0.2 异常
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:06:29[INFO][APP1]开始进入切换流程
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:06:29[INFO][APP1]检验备用通道状态
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 172.20.0.3
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: [155B blob data]
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: <h1>NGINX2</h1>
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:06:29[INFO][APP1]备用通道正常,具备切换条件,开始切换...
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: DNAT tcp -- 0.0.0.0/0 192.168.3.84 tcp dpt:80 to:172.20.0.2:80
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:06:29[INFO][APP1]正在关闭APP1通道...
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:06:29[INFO][APP1]已关闭APP1通道...
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:06:29[INFO][APP2]正在开启APP2通道...
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: 172.20.0.3
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: [155B blob data]
Apr 12 01:06:29 HA-Deploy app_ha.sh[39400]: <h1>NGINX2</h1>
Apr 12 01:06:39 HA-Deploy app_ha.sh[39400]: 172.20.0.3
Apr 12 01:06:39 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:06:39 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:06:39 HA-Deploy app_ha.sh[39400]: [155B blob data]
Apr 12 01:06:39 HA-Deploy app_ha.sh[39400]: <h1>NGINX2</h1>
Apr 12 01:06:39 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:06:39[INFO][APP2]应用正常,无需切换
[root@HA-Deploy ha-app]# docker start app1;date "+%F %T"
app1
2023-04-12 01:13:43
[root@HA-Deploy ha-app]# docker stop app2;date "+%F %T"
app2
2023-04-12 01:14:25
Apr 12 01:14:39 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10004 milliseconds
Apr 12 01:14:39 HA-Deploy app_ha.sh[39400]: 172.20.0.3
Apr 12 01:14:39 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:14:39 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:14:49 HA-Deploy app_ha.sh[39400]: [866B blob data]
Apr 12 01:14:49 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10003 milliseconds
Apr 12 01:14:49 HA-Deploy app_ha.sh[39400]: 172.20.0.3
Apr 12 01:14:49 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:14:49 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:14:59 HA-Deploy app_ha.sh[39400]: [866B blob data]
Apr 12 01:14:59 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10002 milliseconds
Apr 12 01:14:59 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:14:59[ERROR][APP2]节点 172.20.0.3 异常
Apr 12 01:14:59 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:14:59[INFO][APP2]开始进入切换流程
Apr 12 01:14:59 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:14:59[INFO][APP2]检验备用通道状态
Apr 12 01:14:59 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: [155B blob data]
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: <h1>NGINX1</h1>
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:15:00[INFO][APP2]备用通道正常,具备切换条件,开始切换...
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: DNAT tcp -- 0.0.0.0/0 192.168.3.84 tcp dpt:80 to:172.20.0.3:80
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:15:00[INFO][APP2]正在关闭APP2通道...
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:15:00[INFO][APP2]已关闭APP2通道...
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:15:00[INFO][APP1]正在开启APP1通道...
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: [155B blob data]
Apr 12 01:15:00 HA-Deploy app_ha.sh[39400]: <h1>NGINX1</h1>
Apr 12 01:15:10 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:15:10 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:15:10 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:15:10 HA-Deploy app_ha.sh[39400]: [155B blob data]
Apr 12 01:15:10 HA-Deploy app_ha.sh[39400]: <h1>NGINX1</h1>
Apr 12 01:15:10 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:15:10[INFO][APP1]应用正常,无需切换
Apr 12 01:15:20 HA-Deploy app_ha.sh[39400]: 172.20.0.2
[root@HA-Deploy ha-app]# docker stop app1;date "+%F %T"
app1
2023-04-12 01:22:17
Apr 12 01:22:30 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10003 milliseconds
Apr 12 01:22:30 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:22:30 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:22:30 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:22:40 HA-Deploy app_ha.sh[39400]: [866B blob data]
Apr 12 01:22:40 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10003 milliseconds
Apr 12 01:22:40 HA-Deploy app_ha.sh[39400]: 172.20.0.2
Apr 12 01:22:40 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:22:40 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:22:50 HA-Deploy app_ha.sh[39400]: [866B blob data]
Apr 12 01:22:50 HA-Deploy app_ha.sh[39400]: curl: (28) Connection timed out after 10004 milliseconds
Apr 12 01:22:50 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:22:50[ERROR][APP1]节点 172.20.0.2 异常
Apr 12 01:22:50 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:22:50[INFO][APP1]开始进入切换流程
Apr 12 01:22:50 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:22:50[INFO][APP1]检验备用通道状态
Apr 12 01:22:50 HA-Deploy app_ha.sh[39400]: 172.20.0.3
Apr 12 01:22:50 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:22:50 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:22:53 HA-Deploy app_ha.sh[39400]: [293B blob data]
Apr 12 01:22:53 HA-Deploy app_ha.sh[39400]: 172.20.0.3
Apr 12 01:22:53 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:22:53 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:22:56 HA-Deploy app_ha.sh[39400]: [293B blob data]
Apr 12 01:22:56 HA-Deploy app_ha.sh[39400]: 172.20.0.3
Apr 12 01:22:56 HA-Deploy app_ha.sh[39400]: % Total % Received % Xferd Average Speed Time Time Time Current
Apr 12 01:22:56 HA-Deploy app_ha.sh[39400]: Dload Upload Total Spent Left Speed
Apr 12 01:22:59 HA-Deploy app_ha.sh[39400]: [293B blob data]
Apr 12 01:22:59 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:22:59[ERROR][APP1]节点 172.20.0.3 异常
Apr 12 01:22:59 HA-Deploy app_ha.sh[39400]: 2023-04-12 01:22:59[ERROR][APP1]备用通道异常,不具备切换条件,当前业务受影响,请及时人工解决。
Apr 12 01:22:59 HA-Deploy systemd[1]: ha-app.service: main process exited, code=exited, status=1/FAILURE
Apr 12 01:22:59 HA-Deploy systemd[1]: Unit ha-app.service entered failed state.
Apr 12 01:22:59 HA-Deploy systemd[1]: ha-app.service failed.