铭飞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,导入脚本

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

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

相关推荐
Youkiup10 分钟前
【linux 常用命令】
linux·运维·服务器
qq_2975046114 分钟前
【解决】Linux更新系统内核后Nvidia-smi has failed...
linux·运维·服务器
_oP_i19 分钟前
.NET Core 项目配置到 Jenkins
运维·jenkins·.netcore
weixin_4373982127 分钟前
Linux扩展——shell编程
linux·运维·服务器·bash
小燚~29 分钟前
ubuntu开机进入initramfs状态
linux·运维·ubuntu
年薪丰厚36 分钟前
如何在K8S集群中查看和操作Pod内的文件?
docker·云原生·容器·kubernetes·k8s·container
小林熬夜学编程36 分钟前
【Linux网络编程】第十四弹---构建功能丰富的HTTP服务器:从状态码处理到服务函数扩展
linux·运维·服务器·c语言·网络·c++·http
zhangj112537 分钟前
K8S Ingress 服务配置步骤说明
云原生·容器·kubernetes
岁月变迁呀38 分钟前
kubeadm搭建k8s集群
云原生·容器·kubernetes
墨水\\39 分钟前
二进制部署k8s
云原生·容器·kubernetes