1.拉取Nacos-Server最新版镜像

image20200402001458407.png

docker pull nacos/nacos-server:latest
docker images

image20200402001638203.png

2.创建挂载目录

mkdir -p /home/nacos/logs/  #创建日志logs目录
mkdir -p /home/nacos/init.d/
vim /home/nacos/init.d/nacos-custom.properties
#*************** 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://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456

#*************** 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=true

### 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

3.运行Nacos-Server

docker run -itd --name nacos-server \
-e MODE=standalone --restart=always \
-e PREFER_HOST_MODE=hostname \
-e NACOS_SERVER_PORT=8848 \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=10.98.10.12 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos \
-e MYSQL_SERVICE_USER=nacos \
-e MYSQL_SERVICE_PASSWORD=123456 \
-e MYSQL_DATABASE_NUM=1  \
-e NACOS_AUTH_ENABLE=true   \
-v /home/nacos/logs:/home/nacos/logs \
-v /home/nacos/init.d/nacos-custom.properties:/home/nacos/init.d/custom.properties \ -e JVM_XMS=512m -e JVM_XMX=512m -e JVM_XMN=251m \
-p 8848:8848 nacos/nacos-server

Nacos-Server属性配置:(有些配置在版本更新时可能会删除,需要去DockerHub上查看)

namedescription
MODEcluster/standalonecluster/standalone default cluster
NACOS_SERVERSnacos cluster addresseg. ip1:port1 ip2:port2 ip3:port3
PREFER_HOST_MODEWhether hostname are supportedhostname/ip default ip
NACOS_SERVER_PORTnacos server portdefault 8848
NACOS_SERVER_IPcustom nacos server ip when network was mutil-network
SPRING_DATASOURCE_PLATFORMstandalone support mysqlmysql / empty default empty
MYSQL_SERVICE_HOSTmysql host
MYSQL_SERVICE_PORTmysql database portdefault : 3306
MYSQL_SERVICE_DB_NAMEmysql database name
MYSQL_SERVICE_USERusername of database
MYSQL_SERVICE_PASSWORDpassword of database
MYSQL_DATABASE_NUMIt indicates the number of databasedefault :1
JVM_XMS-Xmsdefault :2g
JVM_XMX-Xmxdefault :2g
JVM_XMN-Xmndefault :1g
JVM_MS-XX:MetaspaceSizedefault :128m
JVM_MMS-XX:MaxMetaspaceSizedefault :320m
NACOS_DEBUGenable remote debugy/n default :n
TOMCAT_ACCESSLOG_ENABLEDserver.tomcat.accesslog.enableddefault :false
NACOS_AUTH_SYSTEM_TYPEThe auth system to use, currently only 'nacos' is supporteddefault :nacos
NACOS_AUTH_ENABLEIf turn on auth systemdefault :false
NACOS_AUTH_TOKEN_EXPIRE_SECONDSThe token expiration in secondsdefault :18000
NACOS_AUTH_TOKENThe default tokendefault :SecretKey012345678901234567890123456789012345678901234567890123456789
NACOS_AUTH_CACHE_ENABLETurn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.default : false

4.使用docker-compose运行

#安装docker-compose
pip install docker-compose
#编写构建文件
vim standalone-mysql5.7.yaml
version: "2"
services:
   nacos:
       image: 'nacos/nacos-server:1.2.1'
       container_name: nacos-server-standalone
       environment:
           - MODE=standalone
           - SPRING_DATASOURCE_PLATFORM=mysql
           - MYSQL_SERVICE_HOST=1.1.1.1
           - MYSQL_SERVICE_DB_NAME=nacos
           - MYSQL_SERVICE_PORT=3306
           - MYSQL_SERVICE_USER=nacos
           - MYSQL_SERVICE_PASSWORD=123456
           - MYSQL_DATABASE_NUM=1
           - JVM_XMS=512m
           - JVM_XMX=512m
           - JVM_XMN=256m
           - NACOS_AUTH_SYSTEM_TYPE=nacos
           - NACOS_AUTH_ENABLE=true
       volumes:
           - /home/nacos/logs:/home/nacos/logs
           - /home/nacos/init.d/nacos-custom.properties:/home/nacos/init.d/custom.properties
       ports:
           - "8848:8848"
           - "9555:9555"
       #depends_on:
       #- mysql
       restart: on-failure
#构建
docker-compose -f standalone-mysql5.7.yaml up -d

5.查看Nacos-Server运行状态

docker ps

image20200402002519318.pngimage20200402002557123.png