• docker-compose部署Nacos集群


    docker-compose部署Nacos集群

    1、前置准备:docker、nacos的数据库

    2、创建nacos目录

    mkdir -p /apps/nacos
    
    • 1

    3、切换到nacos目录下,创建并写nginx.conf配置文件

    # 切换到nacos目录
    cd /apps/nacos
    
    # 创建nginx配置文件
    touch nginx.conf
    
    # 写nginx.conf文件信息
    vim nginx.conf
    
    以下为nginx.conf内容
    user  nginx;
    worker_processes  auto;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections  4096;
    }
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        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;
        keepalive_timeout  65;
    
        # include /etc/nginx/conf.d/*.conf;
        # 添加负载均衡配置
    
        upstream nacos {
            server nacos-server01:8846 weight=1 max_fails=2 fail_timeout=10s;
            server nacos-server02:8847 weight=1 max_fails=2 fail_timeout=10s;
            server nacos-server03:8848 weight=1 max_fails=2 fail_timeout=10s;
        }
    
        server {
            listen       80;
            listen  [::]:80;
            # 修改为宿主机的 IP地址
            server_name  10.1.125.145;
    
            # To allow special characters in headers
            ignore_invalid_headers off;
            # Allow any size file to be uploaded.
            # Set to a value such as 1000m; to restrict file size to a specific value
            client_max_body_size 0;
            # To disable buffering
            proxy_buffering off;
            proxy_request_buffering off;
    
            location / {
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
    
                proxy_connect_timeout 300;
                # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
                proxy_http_version 1.1;
                proxy_set_header Connection "";
                chunked_transfer_encoding off;
                # 添加代理配置
    
                proxy_pass http://nacos;
            }
        }
    }
    
    • 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
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

    4、创建并写docker-compose.yaml配置文件

    # 切换到nacos目录
    cd /apps/nacos
    
    # 创建docker-compose.yaml文件
    touch docker-compose.yaml
    
    # 写docker-compose.yaml文件信息
    vim docker-compose.yaml
    
    # 以下为docker-compose.yaml内容,注意MYSQL_SERVICE_*相关为数据库配置,nacos-nginx的volumes为挂载读取同目录下的nginx.conf配置
    version: "3"
    
    services: 
        nacos1:
            container_name: nacos-server01
            hostname: nacos-server01
            image: nacos/nacos-server:2.0.3
            environment: 
                - MODE=cluster
                - PREFER_HOST_MODE=hostname
                - NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
                - SPRING_DATASOURCE_PLATFORM=mysql
                - MYSQL_SERVICE_HOST=Mysql的Ip
                - MYSQL_SERVICE_PORT=端口
                - MYSQL_SERVICE_USER=用户
                - MYSQL_SERVICE_PASSWORD=密码
                - MYSQL_SERVICE_DB_NAME=nacos_config nacos数据库
                - JVM_XMS=128m
                - JVM_XMX=128m
                - JVM_XMN=128m
            volumes: 
                - ./cluster-logs/nacos1:/home/nacos/logs
                - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
            ports: 
                - 8846:8848
                - 9848:9848
                - 9555:9555
            restart: on-failure
    
        nacos2:
            container_name: nacos-server02
            hostname: nacos-server02
            image: nacos/nacos-server:2.0.3
            environment: 
                - MODE=cluster
                - PREFER_HOST_MODE=hostname
                - NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
                - SPRING_DATASOURCE_PLATFORM=mysql
                - MYSQL_SERVICE_HOST=192.168.120.253
                - MYSQL_SERVICE_PORT=3306
                - MYSQL_SERVICE_USER=root
                - MYSQL_SERVICE_PASSWORD=root
                - MYSQL_SERVICE_DB_NAME=nacos_config
                - JVM_XMS=128m
                - JVM_XMX=128m
                - JVM_XMN=128m
            volumes: 
                - ./cluster-logs/nacos1:/home/nacos/logs
                - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
            ports: 
                - 8847:8848
                - 9849:9848
            restart: on-failure
    
        nacos3:
            container_name: nacos-server03
            hostname: nacos-server03
            image: nacos/nacos-server:2.0.3
            environment: 
                - MODE=cluster
                - PREFER_HOST_MODE=hostname
                - NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
                - SPRING_DATASOURCE_PLATFORM=mysql
                - MYSQL_SERVICE_HOST=192.168.120.253
                - MYSQL_SERVICE_PORT=3306
                - MYSQL_SERVICE_USER=root
                - MYSQL_SERVICE_PASSWORD=root
                - MYSQL_SERVICE_DB_NAME=nacos_config
                - JVM_XMS=128m
                - JVM_XMX=128m
                - JVM_XMN=128m
            volumes: 
                - ./cluster-logs/nacos1:/home/nacos/logs
                - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
            ports: 
                - 8848:8848
                - 9850:9848
            restart: on-failure
    
        nacos-nginx: 
            container_name: nacos-nginx
            image: nginx:1.21.1
            volumes: 
                - ./nginx.conf:/etc/nginx/nginx.conf:ro
            ports: 
                - 8845:80
            restart: on-failure 
    
    • 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
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97

    5、编排docker-compose.yaml

    请添加图片描述

    # 编排docker-compose.yaml
    # docker-compose -f <编排文件路径> up -d
    docker-compose -f docker-compose.yaml up -d
    
     # 查看运行情况
    docker ps -n 5
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

    6、地址:http:{ip}:8845/nacos 账号密码都为nacos

    在这里插入图片描述

    先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦

  • 相关阅读:
    串口调试助手和网络调试助手使用总结
    安全可信 | 首批 天翼云通过可信云安全云工作负载保护平台评估
    深入探讨AJAX接口进度监控:实现步骤、代码示例与技术原理
    Maven聚合项目配合Springcloud案例
    在 Qt 框架中,有许多内置的信号可用于不同的类和对象\triggered
    猿创征文|筚路蓝缕启山林,栉风沐雨砥砺行——我的区块链之路
    HTML中已经过时的标签
    Redis进阶:图文讲解Redis底层数据结构之embstr,raw,ziplist,quicklist和hashtable (带源码讲解)
    软件外包公司真的去不得吗?
    封阳台窗户怎么选
  • 原文地址:https://blog.csdn.net/emgexgb_sef/article/details/126070981