#!/bin/bash # 服务连通性测试脚本 # tags: kubernetes, k3s, traefik, testing, health-check # description: 测试所有已部署服务的连通性和健康状态 # title: 服务测试脚本 # createdAt: 2025-11-26 # 颜色定义 GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color echo "======================================" echo "服务连通性测试" echo "======================================" echo "" # 定义所有服务 declare -a SERVICES=( "blinko.xiongxiao.me" "chat.xiongxiao.me" "kevisual.xiongxiao.me" "www.xiongxiao.me" "immich.xiongxiao.me" "cloud.xiongxiao.me" "docmost.xiongxiao.me" "drawio.xiongxiao.me" "minio.xiongxiao.me" "npm.xiongxiao.me" "gist.xiongxiao.me" "webdav.xiongxiao.me" "esm.xiongxiao.me" "umami.xiongxiao.me" "pwd.xiongxiao.me" "meilisearch.xiongxiao.me" "memos.xiongxiao.me" "git.xiongxiao.me" ) # 统计 TOTAL=${#SERVICES[@]} SUCCESS=0 FAILED=0 echo "测试 ${TOTAL} 个服务..." echo "" # 测试每个服务 for service in "${SERVICES[@]}"; do printf "%-35s ... " "$service" # 使用 curl 测试,允许不安全的 SSL (因为是自签名) # 设置 5 秒超时 if curl -k -s -o /dev/null -w "%{http_code}" --max-time 5 "https://${service}" | grep -qE "^(200|301|302|401|403)$"; then echo -e "${GREEN}✓ OK${NC}" ((SUCCESS++)) else echo -e "${RED}✗ FAILED${NC}" ((FAILED++)) fi done # 显示结果 echo "" echo "======================================" echo "测试结果" echo "======================================" echo -e "总计: ${TOTAL}" echo -e "${GREEN}成功: ${SUCCESS}${NC}" echo -e "${RED}失败: ${FAILED}${NC}" echo "" if [ $FAILED -eq 0 ]; then echo -e "${GREEN}所有服务测试通过!${NC}" exit 0 else echo -e "${YELLOW}部分服务测试失败,请检查:${NC}" echo "1. Service 和 Endpoints 配置是否正确" echo "2. 后端服务是否正常运行" echo "3. 网络连接是否正常" echo "4. DNS 解析是否正确" echo "" echo "查看详细日志:" echo " kubectl logs -n traefik -l app=traefik" exit 1 fi