美文网首页
Docker实用-安装Nacos

Docker实用-安装Nacos

作者: 轻轻敲醒沉睡的心灵 | 来源:发表于2023-05-23 12:00 被阅读0次

    先给出来官网,方便查阅信息:nacos官网
    docker安装nacos,其实官方已经给出脚本了,而且给的还挺全。但就是太扯淡了,compose.yml中还带数据库了,也就是按他的那个,nacos容器启动了,还给你另起了mysql容器,给的挺全,有支持mysql5.7的脚本,有支持mysql8的脚本。不知道产品经理脑袋是不是被绿提过,就是不给你整合自己原有数据库的脚本,这不扯淡吗,我都要整合数据库了,我自己能没数据库吗,还用你再给我启个mysql容器?
    你要是没有mysql数据库,直接用官方的就行了。我这里就直接给出整合自己原数据库的(但前提是,你自己必须先建好nacos数据库,并导入表,官网都有)。

    1. 单机

    单机和集群一样,也用 docker-compose.yml文件。

    sudo mkdir -p /home/soft/nacos/
    cd /home/soft/nacos
    sudo vim nacos.yml
    

    写入以下配置:

    version: "3.9"
    services:
      nacos:
        hostname: nacos
        container_name: nacos
        image: nacos/nacos-server:v1.4.5
        volumes:
          - /home/soft/nacos/logs:/home/nacos/logs
          - /home/soft/nacos/custom.properties:/home/nacos/init.d/custom.properties
        ports:
          - "8848:8848"
          - "9848:9848"
          - "9555:9555"
        environment:
          PREFER_HOST_MODE: ip
          MODE: standalone
          SPRING_DATASOURCE_PLATFORM: mysql
          MYSQL_SERVICE_HOST: 192.168.20.22
          MYSQL_SERVICE_DB_NAME: nacos
          MYSQL_SERVICE_PORT: 3306
          MYSQL_SERVICE_USER: root
          MYSQL_SERVICE_PASSWORD: mysql123
          MYSQL_SERVICE_DB_PARAM: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
          JVM_XMS: 256m
          JVM_XMX: 512m
          JVM_XMN: 256m
          NACOS_AUTH_IDENTITY_KEY: nacos
          NACOS_AUTH_IDENTITY_VALUE: nacos
          # 2.0以上版本开启鉴权时要添加这个,可以改,位数这么多就行
          # NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
        restart: always
        ## 如果没有自定义网络,下面的networks都可以不写
        networks:
          zrb_network:
            ipv4_address: 192.168.20.30
    ## 已经自定义好的网络
    networks:
      zrb_network: 
        external: true
    

    检查,启动:

    sudo docker compose -f nacos.yml config -q
    sudo docker compose -f nacos.yml up -d
    

    2. 集群

    集群也是一样的。

    sudo mkdir -p /home/soft/nacos-cluster/
    cd /home/soft/nacos
    sudo vim nacos-cluster.yml
    

    写入以下配置:

    version: "3.9"
    services:
      nacos8848: 
        hostname: nacos8848
        container_name: nacos8848
        image: nacos/nacos-server:v1.4.5
        volumes:
          - /home/soft/nacos-cluster/8848/logs:/home/nacos/logs
          - /home/soft/nacos-cluster/8848/custom.properties:/home/nacos/init.d/custom.properties
        environment:
          PREFER_HOST_MODE: ip
          MODE: cluster
          NACOS_SERVER_IP: 182.168.20.31
          NACOS_APPLICATION_PORT: 8848
          NACOS_SERVERS: "192.168.20.31:8848 192.168.20.32:8848 192.168.20.33:8848"
          SPRING_DATASOURCE_PLATFORM: mysql
          MYSQL_SERVICE_HOST: 192.168.20.22
          MYSQL_SERVICE_PORT: 3306
          MYSQL_SERVICE_DB_NAME: nacos
          MYSQL_SERVICE_USER: root
          MYSQL_SERVICE_PASSWORD: mysql123
          JVM_XMS: 256m
          JVM_XMX: 512m
          JVM_XMN: 256m
          NACOS_AUTH_IDENTITY_KEY: nacos
          NACOS_AUTH_IDENTITY_VALUE: nacos
          # 2.0以上版本开启鉴权时要添加这个,可以改,位数这么多就行
          # NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
        ports:
          - "8848:8848"
          - "9848:9848"
          - "9555:9555"
        restart: always  
        networks:
          zrb_network:
            ipv4_address: 192.168.20.31
     
      nacos8849: 
        hostname: nacos8849
        container_name: nacos8849
        image: nacos/nacos-server:v1.4.5
        volumes:
          - /home/soft/nacos-cluster/8849/logs:/home/nacos/logs
          - /home/soft/nacos-cluster/8849/custom.properties:/home/nacos/init.d/custom.properties
        environment:
          PREFER_HOST_MODE: ip
          MODE: cluster
          NACOS_SERVER_IP: 182.168.20.32
          NACOS_APPLICATION_PORT: 8848
          NACOS_SERVERS: "192.168.20.31:8848 192.168.20.32:8848 192.168.20.33:8848"
          SPRING_DATASOURCE_PLATFORM: mysql
          MYSQL_SERVICE_HOST: 192.168.20.22
          MYSQL_SERVICE_PORT: 3306
          MYSQL_SERVICE_DB_NAME: nacos
          MYSQL_SERVICE_USER: root
          MYSQL_SERVICE_PASSWORD: mysql123
          JVM_XMS: 256m
          JVM_XMX: 512m
          JVM_XMN: 256m
          NACOS_AUTH_IDENTITY_KEY: nacos
          NACOS_AUTH_IDENTITY_VALUE: nacos
          # 2.0以上版本开启鉴权时要添加这个,可以改,位数这么多就行
          # NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
        ports:
          - "8849:8848"
          - "9849:9848"
        restart: always  
        networks:
          zrb_network:
            ipv4_address: 192.168.20.32
        
      nacos8850: 
        hostname: nacos8850
        container_name: nacos8850
        image: nacos/nacos-server:v1.4.5
        volumes:
          - /home/soft/nacos-cluster/8850/logs:/home/nacos/logs
          - /home/soft/nacos-cluster/8850/custom.properties:/home/nacos/init.d/custom.properties
        environment:
          PREFER_HOST_MODE: ip
          MODE: cluster
          NACOS_SERVER_IP: 182.168.20.33
          NACOS_APPLICATION_PORT: 8848
          NACOS_SERVERS: "192.168.20.31:8848 192.168.20.32:8848 192.168.20.33:8848"
          SPRING_DATASOURCE_PLATFORM: mysql
          MYSQL_SERVICE_HOST: 192.168.20.22
          MYSQL_SERVICE_PORT: 3306
          MYSQL_SERVICE_DB_NAME: nacos
          MYSQL_SERVICE_USER: root
          MYSQL_SERVICE_PASSWORD: mysql123
          JVM_XMS: 256m
          JVM_XMX: 512m
          JVM_XMN: 256m
          NACOS_AUTH_IDENTITY_KEY: nacos
          NACOS_AUTH_IDENTITY_VALUE: nacos
          # 2.0以上版本开启鉴权时要添加这个,可以改,位数这么多就行
          # NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
        ports:
          - "8850:8848"
          - "9850:9848"
        restart: always  
        networks:
          zrb_network:
            ipv4_address: 192.168.20.33
    
    ## 已经自定义好的网络          
    networks:
      zrb_network: 
        external: true 
    

    检查,启动:

    sudo docker compose -f nacos-cluster.yml config -q
    sudo docker compose -f nacos-cluster.yml up -d
    

    相关文章

      网友评论

          本文标题:Docker实用-安装Nacos

          本文链接:https://www.haomeiwen.com/subject/khotedtx.html