使⽤docker部署project-exam-system(3)

docker-compose.yml

vim ./pes/docker-compose
version: "3"
services:
weba:
container_name: web0
image: nginx:latest
#ports:
#- "80:80"
expose:
- 80
volumes:
- ./web/src/dist/:/usr/share/nginx/html/
webb:
container_name: web1
image: nginx:latest
#ports:
#- "80:80"
expose:
- 80
volumes:
- ./web/src/dist/:/usr/share/nginx/html/
webc:
container_name: web2
image: nginx:latest
#ports:
#- "80:80"
expose:
- 80
volumes:
- ./web/src/dist/:/usr/share/nginx/html/
javaa:
container_name: java0
build: ./java #这个java⽬录下必须要有Dockerfile
#ports:
#- "8080:8080"
expose:
- 8080
volumes:
- ./java/src/:/java/src/
javab:
container_name: java1
build: ./java #这个java⽬录下必须要有Dockerfile
#ports:
#- "8080:8080"
expose:
- 8080
volumes:
- ./java/src/:/java/src/
mysql:
container_name: mysql0
image: mysql:5.7.44
ports:
- "3306:3306"
expose:
- 3306
volumes:
- ./mysql/data/:/var/lib/mysql/
haproxy:
container_name: haproxy0
image: haproxy:latest
ports:
- "8888:8888"
- "5000:5000"
- "8080:8080"
volumes:
-
./haproxy/haproxy/haproxy.cfg:/usr/local/etc/haprox
y/haproxy.cfg
links:
- web0
- web1
- web2
- java0
- java1

配置haproxy.cfg

######## 监控界⾯配置 #################
listen admin_status
# 监控界⾯访问信息
bind 0.0.0.0:8888
mode http
# URI相对地址
stats uri /dbs
# 统计报告格式
stats realm Global\ statistics
# 登录账户信息
stats auth admin:123456
########frontend配置##############
######## 代理nginx服务 ###############
listen proxy-web
bind 0.0.0.0:5000
mode http
# 负载均衡算法
# static-rr 权重, leastconn 最少连接, source
请求IP, 轮询 roundrobin
balance roundrobin
# ⽇志格式
option tcplog
# 在 mysql 创建⼀个没有权限的haproxy⽤户,密码为
空。 haproxy⽤户
# create user 'haproxy'@'%' identified by
''; FLUSH PRIVILEGES;
#option mysql-check user haproxy
# 这⾥是容器中的IP地址,由于配置的是轮询
roundrobin,weight 权重其实没有⽣效
server web0 web0:80 check weight 1 maxconn
2000
server web1 web1:80 check weight 1 maxconn
2000
server web2 web2:80 check weight 1 maxconn
2000
#server MYSQL_3 192.168.130.102:3306 check
weight 1 maxconn 2000
# 使⽤keepalive检测死链
# option tcpka
#########################################
######## java的负载均衡配置 ###############
listen proxy-java
bind 0.0.0.0:8080
mode http
# 负载均衡算法
# static-rr 权重, leastconn 最少连接, source
请求IP, 轮询 roundrobin
balance roundrobin
# ⽇志格式
option tcplog
# 在 mysql 创建⼀个没有权限的haproxy⽤户,密码为
空。 haproxy⽤户
# create user 'haproxy'@'%' identified by
''; FLUSH PRIVILEGES;
#option mysql-check user haproxy
# 这⾥是容器中的IP地址,由于配置的是轮询
roundrobin,weight 权重其实没有⽣效
server javaa java0:8080 check weight 1
maxconn 2000
server javab java1:8080 check weight 1
maxconn 2000
#server MYSQL_3 192.168.130.102:3306 check
weight 1 maxconn 2000
# 使⽤keepalive检测死链
# option tcpka
#########################################

配置Application.properties

spring.datasource.url=jdbc:mysql://192.168.71.10:33
06/project_exam_system
spring.datasource.username=zhangmin
spring.datasource.password=zhangmin
spring.datasource.driver-class
name=com.mysql.cj.jdbc.Driver

注意事项

1. web
1. 直接使⽤或者下载nginx:latest,如果你觉得下载速度太慢,
可以⾃⼰配置⾮安全私有仓库(registy镜像,活着harbor都
可以,)但是在调⽤奖项的时候
(192.168.71.11/libary/nginx:latest)
2. nginx容器的资源⽂件默认在/usr/share/nginx/html
3. nginx容器的配置⽂件默认在/etc/nginx/nginx.conf
4. 有时候我们需要挂载配置⽂件和资源⽂件就需要挂载两个⽬
volumes:
- ./web/nginx.conf:/etc/nginx/nginx.conf
- ./web/src/dist/:/usr/share/nginx/html/
5. expose⽤于容器向宿主暴露端⼝,保证宿主内部的容器能够
相互访问
6. ports ⽤于将容器的端⼝映射到宿主的端⼝,容易重复,所
以需要谨慎
7. Container_name 容器名称,不允许重复
8. image是要调⽤的镜像,如果在当前宿主上没有主机的镜
像,会⾃动下载,如果没有指定标签的镜像,会默认从公⽹
仓库下载
2. java
1. build 如果没有现成的镜像,需要我们⾃⼰创建新的进项,
就需要我们写⼀个Dockerfile,build指向Dockerfile所在的⽬
2. java的配置⽂件application.properties|yml
3. 在运维的时候,主要是配置的datasource
1. url
1. ip
2. 端⼝
2. driver ⼀般不需要修改,特殊情况是换了数据库软件
mysql sqlserver oracle
3. username
4. Password
5. 尽量把java的war,jar和配置放在⼀起,在执⾏启动命
令的时候,需要将⽬录跳转到资源⽂件所有的⽬录,在
启动的同时会读取配置⽂件(application.properties)
6. java有多个版本,需要开发⼈员提供版本号
1. Java17.0.12
2. ⾼版本兼容低版本,⼀般来说,22版本⼀般来说可
以运⾏17开发的程序
3. 要求都在同⼀个⼤版本之内
3. mysql
1. ⽤于容器创建和销毁,所以持久化的数据,应该保存在宿主
2. Mysql5.7.44的资源⽂件/var/lib/mysql
3. 在容器中也是可以做主从复制以及读写的分离的。(需要⼤
家⾃⼰完成)
4. docker-compose的⽂件⽬录
[root@docker pes]# tree -L 2
.
"## docker-compose.yml
"## haproxy
$ %## haproxy.cfg
"## java
$ "## Dockerfile
$ "## jdk
$ "## src
$ %## start.sh
"## mysql
$ "## data
$ %## project_exam_system.sql
%## web
%## src
  • 18
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值