Build Nacos--docker way


1. Front

1. Configure the database corresponding to nacos
2. Mount the application.properties corresponding to nacos
3. Run nacos
4. Remarks

2. Configure MySQL corresponding to Nacos

Find the corresponding MySQL file address :
https://github.com/alibaba/nacos/blob/master/distribution/conf/nacos-mysql.sql

You can find the initial SQL file address in the cluster deployment instructions :
https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html
Insert picture description here
You can go to this place to copy the SQL statement yourself

3. Configure the application.properties corresponding to Nacos

Find the corresponding MySQL file address :
https://github.com/nacos-group/nacos-docker/blob/master/build/conf/application.properties

Modified content:

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://172.19.0.2(数据库IP):3306(数据库端口)/nacos_config(数据库库名)?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root (数据库用户名)
db.password=123456 (数据库密码)
删除db.url.1
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
spring.datasource.platform=mysql
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db.num=1
db.url.0=jdbc:mysql://172.19.0.2:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456
### The auth system to use, currently only 'nacos' is supported:
nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}


### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}

### The default token:
nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN: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=${NACOS_AUTH_CACHE_ENABLE:false}

server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false

nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true

4. Start Nacos

docker-nacos.yaml

# Compose 版本 Version 2支持更多的指令。Version 1将来会被弃用。
version: "3"

# 定义服务
services:

  # 为project定义服务
  nacos:
    # 服务的镜像名称或镜像ID。如果镜像在本地不存在,Compose将会尝试拉取镜像
    image: nacos/nacos-server:1.2.1
    # 配置端口 - "宿主机端口:容器暴露端口"
    ports:
      - 8848:8848
    # 配置容器连接的网络,引用顶级 networks 下的条目(就是最下面配置的networks(一级目录))
    networks:
      - mysql_mysql
    # 挂载
    volumes:
      - "E://Docker/nacos/conf/application.properties:/home/nacos/conf/application.properties"
    # 容器总是重新启动
    restart: always
    # 添加环境变量
    environment:
      MODE: standalone
    # 指定一个自定义容器名称,而不是生成的默认名称。
    container_name: nacos
    # 使用该参数,container内的root拥有真正的root权限。
    privileged: true


# 声明外部网络
networks:
  mysql_mysql:
    external: true

Run the container:

docker-compose -f docker-nacos.yaml up -d

Log:
Insert picture description here

4. Remarks

  • Nacos 1.1.4 removes the database master-slave mirror configuration : Reason : https://github.com/nacos-group/nacos-docker/wiki/ Removes the database master-slave mirror configuration (so I deleted db.url.1)

  • I am here to start by docker-compose, you can modify it to the corresponding docker run mode

  • docker-compose will be introduced tomorrow

  • Of course, you can also run nacos through source code or installation package mode

  • About the parameter description in application.properties and the configuration of custom.properties : https://github.com/nacos-group/nacos-docker/blob/master/README_ZH.md

Guess you like

Origin blog.csdn.net/qq_38637558/article/details/114465538