1. docker部署

1.1. Debian\UOS\Ubuntu

#更新系统
sudo apt update
#安装docker-ce
sudo apt install docker-ce

1.2. CentOS

#更新系统
sudo yum update
#安装docker-ce
sudo yum install docker-ce

2. 容器配置

创建统一的docker挂载目录

#mysql文件,容器会自动生成
sudo mkdir /data/mysql
#复制打包好的jar包与项目文件夹
sudo mkdir /data/mcms 
#代理配置
sudo mkdir /data/nginx

[!tip]挂载目录常存放配置文件或常更新的文件

2.1. Docker网络

#创建docker网络,方便固定docker容器ip
docker network create --opt com.docker.network.driver.mtu=1450 \
--opt com.docker.network.bridge.name=docker1 --subnet=172.18.0.1/16 ms

2.2. 安装MySQL

docker run --network=ms --ip 172.18.0.3 --name mysql8  \
-v /data/mysql/data:/var/lib/mysql \
-e TZ="Asia/Shanghai" \
--privileged=true --restart=always -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.13 \
--sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" \
--lower-case-table-names=1 \
--symbolic-links=1 \
--skip-name-resolve=0 \
--max-connections=1000 \

[!tip]通过工具链接到MySQL,将MCms数据库导入到MySQL

2.3. 安装MCms

x86

docker run --name mcms -v /data/mcms:/home \
--network=ms --ip 172.18.0.50 -p 8080:8080  \
--privileged=true  mingsoft/java \
java -jar maven.jar

arm64

docker run --name mcms -d -v /data/mcms:/home \
--network=ms --ip 172.18.0.50 -p 8080:8080 \
-w /home --restart=always --privileged=true \
arm64v8/openjdk  \
java -jar mcms.jar

2.4. 安装Nginx

docker run --name nginx -d \
--network=ms --ip 172.18.0.10 -p 80:80 \
-v /data:/data \
-v /data/nginx/logs:/etc/nginx/logs \
-v /data/nginx/nginx.conf:/etc/nginx/nginx.conf \
--restart=always --privileged=true  \
docker.io/nginx

2.4.1. nginx.conf配置

...

server {
    listen 80;
    server_name www.mcms.com; 
    root /home;

    #启用ssl,去掉#注释
    #listen 443 ssl http2;
    #ssi on;
    #ssi_silent_errors on;
    #ssi_types text/shtml;
    #set $flag 0;

    #if ($server_port !~ 443){
    # set $flag "${flag}1";
    #}
    #if ($request_method !~ ^(POST)$) {
    #    set $flag "${flag}1";
    #}
    #if ($flag = "011"){
    #    rewrite ^(/.*)$ https://$host$1 permanent;
    #}

    #ssl_certificate    mcms.pem;
    #ssl_certificate_key    mcms.key;
    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    #ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    #ssl_prefer_server_ciphers on;
    #ssl_session_cache shared:SSL:10m;
    #ssl_session_timeout 10m;

    location  ~ .*\.(do)$ {
        index index.do;
        proxy_pass http://172.18.0.50: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;
    }


    #静态资源
    location ~ /(static/plugins|html|upload|template){
        #缓存(天)
        expires 12d;
    } 
    location ~ .*\.(gif|jpg|jpeg|png)$ {
        expires 24h;
    }
    #屏蔽
    location ^*/WEB-INF/ {
        deny all;
    }
    access_log logs/mcms.log;
}

...

根据实际的域名进行配置调整

Copyright © mingsoft.net 2021 all right reserved,powered by Gitbook该文件修订时间: 2021-06-16 16:28:25

results matching ""

    No results matching ""

    results matching ""

      No results matching ""