JPAAS采用Docker离线部署
前提
需要安装docker, docker-compose,推荐服务器系统为Centos7.6 64位以上.
部署步骤
1.将所有模块打包成jar包或者获取系统的jar包
mvn clean package
2.将所有jar包上传到服务器中
建议每个模块都创建一个对应的文件夹,然后将jar包上传到对应的文件夹中
3.在每个文件夹中都创建Dockerfile文件
示例如下:
FROM adoptopenjdk/openjdk8-openj9:alpine-slim
MAINTAINER ***@qq.com
RUN mkdir -p /jpaas/gateway
WORKDIR /jpaas/gateway
EXPOSE 9900
ADD ./target/sc-gateway.jar ./sc-gateway.jar
CMD java -jar -server -Xms1g -Xmx1g sc-gateway.jar --nacos.address=172.30.0.48:8848
4.在每个文件夹下构建镜像
示例如下:
docker build -t sc-gateway .
5.返回模块文件夹的上一级目录
6.创建docker-compose.yml文件
示例如下:
version: '3'
services:
mysql:
restart: always
image: mysql:8
container_name: mysql8
ports:
- 3306:3306
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--default-time-zone=+8:00
environment:
MYSQL_ROOT_PASSWORD: "root"
volumes:
- ./mysql/db:/var/lib/mysql
- ./mysql/conf/my.cnf:/etc/my.cnf
- ./mysql/init:/docker-entrypoint-initdb.d/
- ./mysql/sql:/opt/sql
networks:
jpaas_net:
ipv4_address: 172.30.0.3
redis:
image: redis:5.0.8-alpine
hostname: "jpaas-redis"
environment:
- TZ=Asia/Shanghai
ports:
- 3379:6379
volumes:
- ./redis/data:/data
command: "redis-server --appendonly yes"
privileged: true
restart: always
tty: true # 这里可以加
networks:
jpaas_net:
ipv4_address: 172.30.0.4
nacos:
image: nacos/nacos-server:1.3.2 # 镜像`nacos/nacos-server:latest`
container_name: nacos_server # 容器名为'nacos_server'
restart: always # 指定容器退出后的重启策略为始终重启
volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录
- ./nacos/logs/:/home/nacos/logs
- ./nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties
environment:
# 设置环境变量,相当于docker run命令中的-e
PREFER_HOST_MODE: hostname
MODE: standalone # 单机模式启动
SPRING_DATASOURCE_PLATFORM: mysql
MYSQL_SERVICE_HOST: 172.30.0.3 # 注:这里不能为`127.0.0.1`或`localhost`方式!!!
MYSQL_SERVICE_DB_NAME: nacos_config # 所需sql脚本位于 `nacos-mysql/nacos-mysql.sql`
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_USER: root
MYSQL_SERVICE_PASSWORD: root
JVM_XMS: 512m
JVM_MMS: 320m
ports: # 映射端口
- 8848:8848
depends_on:
- mysql
networks:
jpaas_net:
ipv4_address: 172.30.0.48
seata:
image: seataio/seata-server
hostname: "seata-server"
ports:
- 8091:8091
depends_on:
- nacos
environment:
- SEATA_CONFIG_NAME=file:/root/seata-config/registry
- SEATA_PORT=8091
- STORE_MODE=file
#- SEATA_IP=192.168.0.200
- TZ=Asia/Shanghai
volumes:
- ./seata/conf:/root/seata-config
- ./seata/logs:/root/logs
- /etc/localtime:/etc/localtime
networks:
jpaas_net:
ipv4_address: 172.30.0.68
nginx:
image: nginx:stable-alpine-perl
hostname: "web-nginx"
environment:
- TZ=Asia/Shanghai
ports:
- 8080:8080
volumes:
- ./nginx/web/html:/usr/share/nginx/html
- ./nginx/web/nginx.conf:/etc/nginx/nginx.conf
privileged: true
restart: always
networks:
- jpaas_net
gateway:
image: "sc-gateway"
environment:
- TZ=Asia/Shanghai
privileged: true
restart: always
depends_on:
- seata
- mysql
- nacos
- redis
networks:
jpaas_net:
ipv4_address: 172.30.0.81
auth:
image: "jpaas-auth"
environment:
- TZ=Asia/Shanghai
privileged: true
restart: always
depends_on:
- mysql
- nacos
- redis
- seata
networks:
jpaas_net:
ipv4_address: 172.30.0.91
user:
image: "jpaas-user"
environment:
- TZ=Asia/Shanghai
privileged: true
restart: always
depends_on:
- mysql
- nacos
- redis
- seata
networks:
- jpaas_net
system:
image: "jpaas-system"
environment:
- TZ=Asia/Shanghai
privileged: true
restart: always
depends_on:
- mysql
- nacos
- redis
- seata
networks:
- jpaas_net
bpm:
image: "jpaas-bpm"
environment:
- TZ=Asia/Shanghai
privileged: true
restart: always
depends_on:
- mysql
- nacos
- redis
- seata
networks:
- jpaas_net
form:
image: "jpaas-form"
environment:
- TZ=Asia/Shanghai
privileged: true
restart: always
depends_on:
- mysql
- nacos
- redis
- seata
networks:
- jpaas_net
portal:
image: "jpaas-portal"
environment:
- TZ=Asia/Shanghai
privileged: true
restart: always
depends_on:
- mysql
- nacos
- redis
- seata
networks:
- jpaas_net
job:
image: "job-admin"
environment:
- TZ=Asia/Shanghai
privileged: true
restart: always
ports:
- 7878:7878
depends_on:
- mysql
- nacos
- redis
networks:
jpaas_net
ipv4_address: 172.30.0.78
networks:
jpaas_net:
driver: bridge
ipam:
config:
- subnet: 172.30.0.0/16
7.基础软件结构
示例如下:
8.上传前端代码编译文件
示例如下:
9.运行基础软件容器
docker-compose up -d mysql redis nacos seata-server nginx
10.运行JPAAS容器
docker-compose up -d
文档更新时间: 2022-01-11 23:18 作者:zyg