docker發布nacos server通過docker-compose(將nacos配置保存到數據中)


  • 直接通過docker啟動nacos-server
  1. 簡單發布nacos-serve,直接拉取nacos-server鏡像,然后啟動docker即可
    ps如果啟動報錯,提示內存不夠,則修改docker啟動參數
    eg: docker run --name nacos -d -p 8848:8848 -e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone  nacos/nacos-server:latest
    不過多解釋參數含義。
  2. 啟動后查看服務是否正常使用即可,docker ps -a | grep nacos 查詢是否有該服務。
  3. 如果有問題docker logs nacos查詢報錯信息。
  • 通過docker-compose啟動,包含mysql配置設置
  1. 在此不去解讀docker-compose的使用,提供配置信息
  2. 文件結構

     

     

  3. docker-compose.yml配置信息
    version: '2'
    services:
      nacos:
        image: nacos/nacos-server
        ports:
          - 8848:8848
        container_name: nacos
        environment:
          - JVM_XMS=256m
          - JVM_XMX=256m
          - MODE=standalone
        #掛載配置
        volumes:
          - ./nacos:/home/nacos/conf
        depends_on:
          - db
        # network_mode: bridge
        # networks:
        #   - default
        #   - outside
        # command: -e JVM_XMS=256m -e JVM_XMX=256m --env MODE=standalone 
      db:
        environment:
          MYSQL_ROOT_PASSWORD: "root1111"
          MYSQL_USER: "user"
          MYSQL_PASSWORD: "user1111"
          MYSQL_DATABASE: "nacos"
        image: "docker.io/mysql:latest"
        restart: always
        container_name: "mysql8.0"
        volumes:
          - "./mysql/db:/var/lib/mysql"
          - "./mysql/conf/:/etc/my.cnf"
        ports:
          - "23306:3306"
    # networks:
    #   outside:
    #     external: true

     application.properties配置信息
    使用nacos自帶的配置信息即可,需要注意的是需要打開mysql的配置,
    以及jdbc的url配置host要配置成docker-compose.yml中的services.db屬性中的container_name,這一點比較重要。

    #*************** Spring Boot Related Configurations ***************#
    ### Default web context path:
    server.servlet.contextPath=/nacos
    ### Default web server port:
    server.port=8848
    
    #*************** Network Related Configurations ***************#
    ### If prefer hostname over ip for Nacos server addresses in cluster.conf:
    # nacos.inetutils.prefer-hostname-over-ip=false
    
    ### Specify local server's IP:
    # nacos.inetutils.ip-address=
    
    
    
    #*************** Config Module Related Configurations ***************#
    ### If user MySQL as datasource:
    spring.datasource.platform=mysql
    
    ### Count of DB:
    db.num=1
    
    ### Connect URL of DB:
    db.url.0=jdbc:mysql://mysql8.0:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
    db.user=root
    db.password=root1111
    
    
    #*************** Naming Module Related Configurations ***************#
    ### Data dispatch task execution period in milliseconds:
    # nacos.naming.distro.taskDispatchPeriod=200
    
    ### Data count of batch sync task:
    # nacos.naming.distro.batchSyncKeyCount=1000
    
    ### Retry delay in milliseconds if sync task failed:
    # nacos.naming.distro.syncRetryDelay=5000
    
    ### If enable data warmup. If set to false, the server would accept request without local data preparation:
    # nacos.naming.data.warmup=true
    
    ### If enable the instance auto expiration, kind like of health check of instance:
    # nacos.naming.expireInstance=true
    
    
    ### If enable the empty service auto clean, services with an empty instance are automatically cleared
    nacos.naming.empty-service.auto-clean=false
    ### The empty service cleanup task delays startup time in milliseconds
    nacos.naming.empty-service.clean.initial-delay-ms=60000
    ### The empty service cleanup task cycle execution time in milliseconds
    nacos.naming.empty-service.clean.period-time-ms=20000
    
    
    #*************** CMDB Module Related Configurations ***************#
    ### The interval to dump external CMDB in seconds:
    # nacos.cmdb.dumpTaskInterval=3600
    
    ### The interval of polling data change event in seconds:
    # nacos.cmdb.eventTaskInterval=10
    
    ### The interval of loading labels in seconds:
    # nacos.cmdb.labelTaskInterval=300
    
    ### If turn on data loading task:
    # nacos.cmdb.loadDataAtStart=false
    
    
    #*************** Metrics Related Configurations ***************#
    ### Metrics for prometheus
    #management.endpoints.web.exposure.include=*
    
    ### Metrics for elastic search
    management.metrics.export.elastic.enabled=false
    #management.metrics.export.elastic.host=http://localhost:9200
    
    ### Metrics for influx
    management.metrics.export.influx.enabled=false
    #management.metrics.export.influx.db=springboot
    #management.metrics.export.influx.uri=http://localhost:8086
    #management.metrics.export.influx.auto-create-db=true
    #management.metrics.export.influx.consistency=one
    #management.metrics.export.influx.compressed=true
    
    
    #*************** Access Log Related Configurations ***************#
    ### If turn on the access log:
    server.tomcat.accesslog.enabled=true
    
    ### The access log pattern:
    server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
    
    ### The directory of access log:
    server.tomcat.basedir=
    
    
    #*************** Access Control Related Configurations ***************#
    ### If enable spring security, this option is deprecated in 1.2.0:
    #spring.security.enabled=false
    
    ### The ignore urls of auth, is deprecated in 1.2.0:
    nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
    
    ### The auth system to use, currently only 'nacos' is supported:
    nacos.core.auth.system.type=nacos
    
    ### If turn on auth system:
    nacos.core.auth.enabled=false
    
    ### The token expiration in seconds:
    nacos.core.auth.default.token.expire.seconds=18000
    
    ### The default token:
    nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
    
    ### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
    nacos.core.auth.caching.enabled=false
    
    
    #*************** Istio Related Configurations ***************#
    ### If turn on the MCP server:
    nacos.istio.mcp.server.enabled=false
    View Code

     

  4. 拉取鏡像,docker-componse pull 
  5. 啟動項目,docker-componse up -d 
    重啟,docker-compose.exe up -d --force-recreate
  6. 啟動后訪問http://127.0.0.1:8848/nacos  用戶名密碼默認是nacos 查看nacos是否正常,連接mysql是否正常,
  7. mysql啟動后需要自建表結構,將nacos提供的建表sql執行即可,當然這個地方可以優化成啟動mysql的鏡像的時候將建表語句通過腳本的方式執行,這樣是最好的。
  8. 測試添加一個配置data_id后,mysql中config_info是否有數據


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM