铭飞MS部署docker-compose方式

官网文档只有docker部署文档,给了一点启发,在此上部署一下用docker-compose,出个教程,方便大家学习

version: '3'

services:
  nginx-web:
    image: nginx:1.21.3
    container_name: nginx-web
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    ports:
      - "80:80"
      - "8080:8080"
      - "8585:8585"
      - "8181:8181"
      - "443:443"
    volumes:
      # 证书映射
      - /etc/letsencrypt:/etc/nginx/cert
      - /opt/docker/nginx/certbot:/usr/share/certbot/www
      # 配置文件映射
      - /opt/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      # 日志目录
      - /opt/docker/nginx/log:/var/log/nginx
    privileged: true
    restart: always
    networks:
      - kxmall_net

  mysql:
    container_name: mysql57
    image: mysql:5.7.31
    ports:
      - 3306:3306
    privileged: true
    volumes:
      - $PWD/mysql57/log:/var/log/mysql
      - $PWD/mysql57/conf/my.cnf:/etc/mysql/my.cnf
      - $PWD/mysql57/data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "xxxxxxx"
    command: [
        '--character-set-server=utf8mb4',
        '--collation-server=utf8mb4_general_ci',
        '--max_connections=3000'
    ]
    restart: always
    networks:
      kxmall_net:
        ipv4_address: 172.30.0.59


  ms-mcms:
    container_name: ms-mcms
    image: anapsix/alpine-java:8
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    volumes:
      # 配置文件
      - /opt/docker/server/logs/:/ms/server/logs/
      - /opt/docker/server/mcms:/home
    working_dir: /home
    command: java -jar ms-mcms.jar
    privileged: true
    restart: always
    networks:
      kxmall_net:
        ipv4_address: 172.30.0.60

networks:
  kxmall_net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.30.0.0/16

其中,nginx的配置文件内容

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;
    client_max_body_size 10M;  # 设置为10MB
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
       listen       80;
       server_name  a.xxxx.vip;
	   try_files $uri $uri/ /index.html;
        # Load configuration files for the default server block.
       include /etc/nginx/default.d/*.conf;
	   gzip  on;
	   gzip_min_length  1k;
	   gzip_buffers     4 16k;
	   gzip_http_version 1.1;
	   gzip_comp_level 9;
	   gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php application/javascript application/json;
	   gzip_disable "MSIE [1-6]\.";
	   gzip_vary on;
        error_page 404 /404.html;
        location = /404.html {
        }

	    location / {
                     proxy_set_header Host $http_host;
                     proxy_set_header X-Real-IP $remote_addr;
                     proxy_set_header REMOTE-HOST $remote_addr;
                     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                     proxy_pass http://server/;
        }

       location ~ /(static/mdiy) {
            proxy_pass http://localhost:8080;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            add_header Access-Control-Allow-Origin $http_origin;
            add_header Access-Control-Allow-Credentials true;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }


    upstream server {
            ip_hash;
            server 172.30.0.60:8080;
    }


	server {
        listen       443 ssl;
        server_name  a.kxmall.vip;
	   # 配置服务器证书
        ssl_certificate  /etc/nginx/cert/live/a.xxx.vip/fullchain.pem;
        # 配置服务器私钥
        ssl_certificate_key /etc/nginx/cert/live/a.xxx.vip/privkey.pem;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;


        location / {
              proxy_set_header Host $http_host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header REMOTE-HOST $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_pass http://server/;
        }

       location ~ /(static/mdiy) {
            proxy_pass http://localhost:8080;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            add_header Access-Control-Allow-Origin $http_origin;
            add_header Access-Control-Allow-Credentials true;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

其中,mysql的my.cnf文件

#!/bin/bash
mkdir -p /opt/mysql57/{conf,data,log}  #创建本地文件夹


#新建配置文件
tee /opt/mysql57/conf/my.cnf<<-'EOF'
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
lower_case_table_names=1 #实现mysql不区分大小(开发需求,建议开启)
# By default we only accept connections from localhost
bind-address   = 0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
default-time_zone = '+8:00'

# 更改字符集 如果想Mysql在后续的操作中文不出现乱码,则需要修改配置文件内容
symbolic-links=0
character-set-server=utf8mb4
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4

EOF

项目结构

第一步:启动mysql,导入脚本

第二步:启动所有程序即可

第三步:如果访问不了,可以看下服务器的端口,安全组是否有开通。

相关推荐
肖永威7 分钟前
CentOS环境上离线安装python3及相关包
linux·运维·机器学习·centos
mengao123412 分钟前
centos 服务器 docker 使用代理
服务器·docker·centos
布鲁格若门14 分钟前
CentOS 7 桌面版安装 cuda 12.4
linux·运维·centos·cuda
Eternal-Student19 分钟前
【docker 保存】将Docker镜像保存为一个离线的tar归档文件
运维·docker·容器
不是二师兄的八戒21 分钟前
本地 PHP 和 Java 开发环境 Docker 化与配置开机自启
java·docker·php
dessler22 分钟前
云计算&虚拟化-kvm-扩缩容cpu
linux·运维·云计算
DC_BLOG26 分钟前
Linux-Apache静态资源
linux·运维·apache
码农小丘27 分钟前
一篇保姆式centos/ubuntu安装docker
运维·docker·容器
耗同学一米八1 小时前
2024 年河北省职业院校技能大赛网络建设与运维赛项样题二
运维·网络·mariadb
Eternal-Student1 小时前
【1.2 Getting Started--->Installation Guide】
docker