-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-setup.sh
More file actions
executable file
·168 lines (144 loc) · 4.58 KB
/
Copy pathdocker-setup.sh
File metadata and controls
executable file
·168 lines (144 loc) · 4.58 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Docker 环境快速设置脚本
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}🐳 Docker 环境设置${NC}"
echo "=================================="
echo
# 检查Docker是否安装
check_docker() {
echo -e "${BLUE}📋 检查Docker环境...${NC}"
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Docker 未安装${NC}"
echo "请先安装Docker: https://docs.docker.com/get-docker/"
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}❌ Docker Compose 未安装${NC}"
echo "请先安装Docker Compose: https://docs.docker.com/compose/install/"
exit 1
fi
echo -e "${GREEN}✅ Docker 环境检查完成${NC}"
}
# 构建镜像
build_images() {
echo -e "${BLUE}🔨 构建Docker镜像...${NC}"
# 构建主镜像
docker-compose build --no-cache
echo -e "${GREEN}✅ 镜像构建完成${NC}"
}
# 启动服务
start_services() {
echo -e "${BLUE}🚀 启动Docker服务...${NC}"
# 启动所有服务
docker-compose up -d
# 等待服务启动
echo -e "${YELLOW}⏳ 等待服务启动...${NC}"
sleep 10
echo -e "${GREEN}✅ 服务启动完成${NC}"
}
# 检查服务状态
check_services() {
echo -e "${BLUE}📊 检查服务状态...${NC}"
echo
# 显示服务状态
docker-compose ps
echo
# 检查隧道服务器
if curl -s http://localhost:8080/health > /dev/null; then
echo -e "${GREEN}✅ 隧道服务器: 运行正常${NC}"
else
echo -e "${RED}❌ 隧道服务器: 启动失败${NC}"
fi
# 检查MySQL
docker-compose exec -T mysql bash -c 'echo -e "[client]\nuser=root\npassword=rootpassword" > /tmp/.my.cnf'
if docker-compose exec -T mysql mysql --defaults-file=/tmp/.my.cnf -e "SELECT 1;" > /dev/null 2>&1; then
echo -e "${GREEN}✅ MySQL: 运行正常${NC}"
else
echo -e "${YELLOW}⚠️ MySQL: 正在启动中...${NC}"
fi
docker-compose exec -T mysql rm -f /tmp/.my.cnf
# 检查Redis
if docker-compose exec -T redis redis-cli ping > /dev/null 2>&1; then
echo -e "${GREEN}✅ Redis: 运行正常${NC}"
else
echo -e "${YELLOW}⚠️ Redis: 正在启动中...${NC}"
fi
# 检查RabbitMQ
if curl -s http://localhost:15672 > /dev/null; then
echo -e "${GREEN}✅ RabbitMQ: 运行正常${NC}"
else
echo -e "${YELLOW}⚠️ RabbitMQ: 正在启动中...${NC}"
fi
}
# 显示访问信息
show_access_info() {
echo
echo -e "${GREEN}🎉 Docker环境设置完成!${NC}"
echo "=================================="
echo
echo -e "${BLUE}📋 服务访问信息:${NC}"
echo "• 隧道服务器: http://localhost:8080"
echo "• 健康检查: http://localhost:8080/health"
echo "• 状态API: http://localhost:8080/api/status"
echo
echo -e "${BLUE}🗄️ 数据库服务:${NC}"
echo "• MySQL: localhost:3306"
echo " - 用户: testuser"
echo " - 密码: testpassword"
echo " - 数据库: testdb"
echo
echo "• Redis: localhost:6379"
echo
echo "• RabbitMQ: localhost:5672 (AMQP)"
echo " - 管理界面: http://localhost:15672"
echo " - 用户: admin"
echo " - 密码: admin123"
echo
echo -e "${BLUE}🔗 客户端使用示例:${NC}"
echo "# MySQL隧道"
echo "./xtunnel client --server ws://localhost:8080/tunnel --local-port 3307 --remote-host mysql --remote-port 3306"
echo
echo "# Redis隧道"
echo "./xtunnel client --server ws://localhost:8080/tunnel --local-port 6380 --remote-host redis --remote-port 6379"
echo
echo "# RabbitMQ隧道"
echo "./xtunnel client --server ws://localhost:8080/tunnel --local-port 5673 --remote-host rabbitmq --remote-port 5672"
echo
echo -e "${BLUE}📝 常用命令:${NC}"
echo "• 查看日志: docker-compose logs -f"
echo "• 停止服务: docker-compose down"
echo "• 重启服务: docker-compose restart"
echo "• 清理环境: make docker-clean"
}
# 主函数
main() {
check_docker
build_images
start_services
check_services
show_access_info
}
# 处理参数
case "${1:-}" in
"build")
build_images
;;
"start")
start_services
;;
"check")
check_services
;;
"info")
show_access_info
;;
*)
main
;;
esac