技术学苑 技术学苑
首页
  • 大模型

    • ChatGPT (opens new window)
    • 文心一言 (opens new window)
  • 算力平台

    • AutoDL (opens new window)
  • 开源平台

    • 魔搭社区 (opens new window)
    • Hugging Face (opens new window)
关于我
友情链接
  • 分类
  • 标签
  • 归档

首页
  • 大模型

    • ChatGPT (opens new window)
    • 文心一言 (opens new window)
  • 算力平台

    • AutoDL (opens new window)
  • 开源平台

    • 魔搭社区 (opens new window)
    • Hugging Face (opens new window)
关于我
友情链接
  • 分类
  • 标签
  • 归档
  • 【Docker】常用安装脚本

    • 1 前言
      • 2 docker-compose安装脚本
        • 2.1 Mysql
        • 2.2 Redis
        • 2.3 nginx【http】
        • 2.3.1 docker-compose
        • 2.3.2 nginx.conf
        • 2.4 nginx【https】
        • 2.4.1 docker-compose
        • 2.4.2 nginx.conf
        • 2.5 nacos
    fenglm
    2024-02-03
    Docker
    目录

    【Docker】常用安装脚本原创

    # 1 前言

      本文将专注于使用 Docker Compose 来安装和配置一些最常用的服务,如 Nginx 和 MySQL等,旨在提供一个实用的参考,帮助开发者快速搭建开发和生产环境。
      通过具体的示例和简明的步骤,我将引导您如何轻松地通过 Docker Compose 配置和运行这些服务,无论您是 Docker 的新手还是有经验的用户,都能从中获得有价值的信息和技巧。

    # 2 docker-compose安装脚本

    # 2.1 Mysql

    version: "3"
    services:
      mysql8:
        image: mysql:8
        restart: always
        privileged: true
        command:
          --character-set-server=utf8mb4
          --collation-server=utf8mb4_unicode_ci
          --lower_case_table_names=1
          --sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
        environment:
          - MYSQL_ROOT_HOST=%
          - MYSQL_ROOT_PASSWORD=aC2urd42
          - MYSQL_DATABASE=jeecg-boot
          - MYSQL_USER=ptuser
          - MYSQL_PASSWORD=lAVSRqYhd
        ports:
          - '3306:3306'
        volumes:
         - ./mysql/conf:/etc/mysql/conf.d
         - ./mysql/logs:/logs
         - ./mysql/data:/var/lib/mysql
    
      redis:
        image: redis
        command: redis-server --requirepass rds2024
        restart: always
        volumes:
          - ./redis/data:/data
          - ./redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
          - ./redis/logs:/logs
        ports:
          - "6379:6379"
        environment:
          - REDIS_PASSWORD=rds2024
          - REDIS_SAVE=60 1
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37

    # 2.2 Redis

    version: "3"
    services:
      redis:
        image: redis
        command: redis-server --requirepass rds2024
        restart: always
        volumes:
          - ./redis/data:/data
          - ./redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
          - ./redis/logs:/logs
        ports:
          - "6379:6379"
        environment:
          - REDIS_PASSWORD=rds2024
          - REDIS_SAVE=60 1
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    # 2.3 nginx【http】

    🥰 nginx不带SSL证书配置

    # 2.3.1 docker-compose

    version: "3"
    services:
      nginx:
        restart: always
        image: nginx
        ports:
          - 80:80
        volumes:
          - /opt/myxm/nginx-webui/html/dist:/usr/share/nginx/html/webui
          - /opt/myxm/nginx-webui/html/ui:/usr/share/nginx/html/fileui
          - /opt/myxm/nginx-webui/www:/var/www
          - /opt/myxm/nginx-webui/logs:/var/log/nginx
          - /opt/myxm/nginx-webui/nginx.conf/:/etc/nginx/nginx.conf
          - /opt/myxm/nginx-webui/conf.d:/etc/nginx/conf.d
        environment:
          - NGINX_PORT=80
          - PROXY_URL=http://192.168.1.10:8080/
        privileged: true
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    # 2.3.2 nginx.conf

    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        
        # Gzip Compression
        gzip on;
        gzip_types text/plain application/xml application/json text/css application/javascript;
        gzip_proxied any;
        
        map $http_upgrade $connection_upgrade {
            default upgrade;
            ''  close;
        }
        server {
            listen       80;
            server_name  192.168.1.10;
    
            # 加载前端dist页面
            location / {
                root   /usr/share/nginx/html/webui;
                try_files $uri $uri/ /index.html;
                index  index.html index.htm;
            }
    
            # 加载html静态页面(部署单体框架这里不需要,可以拿掉)
            location /ui {
                alias /usr/share/nginx/html/fileui;
                autoindex on;  # 启用目录列表
                try_files $uri $uri/ =404;
            }
    
            # 后端
            location /prod-api/ {
                client_max_body_size 100m;
                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 ${PROXY_URL};
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56

    目录结构参考

    nginx01.png

    # 2.4 nginx【https】

    🥰 nginx带SSL证书配置

    # 2.4.1 docker-compose

    version: "3"
    services:
      nginx:
        restart: always
        image: nginx
        ports:
          - 80:80
          - 443:443
        volumes:
          - /opt/myxm/nginx/html/dist:/usr/share/nginx/html
          - /opt/myxm/nginx/www:/var/www
          - /opt/myxm/nginx/logs:/var/log/nginx
          - /opt/myxm/nginx/nginx.conf/:/etc/nginx/nginx.conf
          - /opt/myxm/nginx/cert:/etc/nginx/cert
          - /opt/myxm/nginx/conf.d:/etc/nginx/conf.d
        environment:
          - NGINX_PORT=80
          - PROXY_URL=http://121.21.24.11:8080/
        privileged: true
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    # 2.4.2 nginx.conf

    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        gzip on;
        gzip_types text/plain text/css application/json application/javascript application/xml;
    
        server {
            listen       80;
            server_name  121.21.24.11;
            rewrite ^(.*)$ https://$host$1 permanent;
        }
    
        server {
            listen 443 ssl;
            server_name  test.com.cn;
    
            client_max_body_size 100m;
            ssl_certificate      /etc/nginx/cert/test.com.cn_bundle.crt;
            ssl_certificate_key  /etc/nginx/cert/test.com.cn.key;
            ssl_session_cache    shared:SSL:1m;
            ssl_session_timeout  5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers  HIGH:!aNULL:!MD5;
            ssl_prefer_server_ciphers  on;
    
            location / {
                root   /usr/share/nginx/html;
                try_files $uri $uri/ /index.html;
                index  index.html index.htm;
                if ($request_uri = /favicon.ico) {
                    return 204;
                }
                expires 1d;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            }
    
            location /prod-api/ {
                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_set_header X-NginX-Proxy true;
                proxy_pass ${PROXY_URL};
                proxy_redirect default; 
                proxy_connect_timeout 500;
                proxy_read_timeout 1000;
                proxy_send_timeout 1000;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root  html;
            }
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63

    # 2.5 nacos

    version: "3"
    services:
      nacos:
        image: nacos/nacos-server:v2.3.0
        environment:
          - NACOS_AUTH_ENABLE=true
          - NACOS_AUTH_CACHE_ENABLE=true
          - NACOS_AUTH_IDENTITY_KEY=example
          - NACOS_AUTH_IDENTITY_VALUE=example
          - NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
          - PREFER_HOST_MODE=hostname
          - MODE=standalone
          - SPRING_DATASOURCE_PLATFORM=mysql
          - MYSQL_SERVICE_HOST=192.168.1.210
          - MYSQL_SERVICE_DB_NAME=nacos-config
          - MYSQL_SERVICE_PORT=3306
          - MYSQL_SERVICE_USER=nacos
          - MYSQL_SERVICE_PASSWORD=nacos@2024
          - MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
        ports:
          - "8848:8848"
          - "9848:9848"
        volumes:
          - ./nacos/nacos-data:/home/nacos/data
          - ./nacos/nacos-logs:/home/nacos/logs
        restart: always
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    后续持续更新,敬请期待~_~

    #实用脚本
    上次更新: 2024/02/08, 02:08:06
    最近更新
    01
    【Linux】JDK安装脚本 原创
    02-03
    02
    【Linux】Java程序开机自启 原创
    02-03
    03
    今日分享:2024-02-03
    02-03
    更多文章>
    Theme by Vdoing
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式