在Docker中安装Nacos

目录

1、依赖环境

1.1、依赖软件

2、安装步骤

2.1、编写

2.2、构建镜像并运行

2.3、配置

2.3.1、application.properties

2.3.2、nacos-logback.xml

2.4、重启

3、验证

3.1、访问

4、API

4.1、使用


1、依赖环境

1.1、依赖软件

示例系统:RedHat,版本:7.6

依赖软件:Docker,版本:20.10.14

备注:

安装Docker参考:RedHat系统安装Docker-CSDN博客

2、安装步骤

2.1、编写

将文件上传或编辑到指定目录:如/usr/local/soft/

vi docker-compose.yml

# 版本号
version: "3"

# 服务列表
services:

  # 配置nacos
  nacos:
    # 指定镜像:命令 nacos/nacos-server:latest
    image: nacos/nacos-server:latest
    # 指定服务名称,命令:--name nacos-test
    container_name: nacos-test
    # 指定端口:命令 -p 主机端口:容器端口
    ports:
      - 8848:8848
      - 9848:9848
      - 9849:9849
    # 自动重启
    restart: "always"
    # 权限
    privileged: true
     # 指定时区
    environment:
      - TZ:Asia/Shanghai
      - MODE:standalone
      - SPRING_DATASOURCE_PLATFORM:mysql
      - MYSQL_SERVICE_HOST:0.0.0.0
      - MYSQL_SERVICE_PORT:3306
      - MYSQL_SERVICE_DB_NAME:nacos_config
      - MYSQL_SERVICE_USER:nacos
      - MYSQL_SERVICE_PASSWORD:123456
      
    # 数据容器卷
    volumes:
      # 需要手动创建工作目录
      - /usr/local/nacos/conf:/home/nacos/conf
      - /usr/local/nacos/data:/home/nacos/data
      - /usr/local/nacos/logs:/home/nacos/logs
  
    # 加入指定网络,容器间必须要处于同一个网络才能通过容器名称进行调用
    networks:
      - test_network
  
# 创建网络      
networks:
  # 默认将会创建为 docker-compose.yml所在文件夹名test_network网络名称
  test_network: 
    driver: bridge

备注:

镜像版本、容器名称、端口、配置目录、网络、标红等可以根据自己需要设置

安装docker-compose参考:在线安装docker-compose_在线装docker-compose-CSDN博客

2.2、构建镜像并运行

前台运行:docker-compose up

后台运行:docker-compose up -d

2.3、配置

前台停止:Ctrl+c

后台停止:docker stop 容器ID

2.3.1、application.properties

vi /usr/local/nacos/conf/application.properties

#
# Copyright 1999-2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#*************** Spring Boot Related Configurations ***************#
### Default web context path:
server.servlet.contextPath=/nacos
### Include message field
server.error.include-message=ALWAYS
### 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 use MySQL as datasource:
spring.datasource.platform=mysql

### Count of DB:
db.num=1

### Connect URL of DB:
db.url.0=jdbc:mysql://0.0.0.0:3306/nacos_config?characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=nacos
db.password.0=123456

### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

#*************** Naming Module Related Configurations ***************#

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

### Add in 2.0.0
### The interval to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.interval=60000

### The expired time to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.expired-time=60000

### The interval to clean expired metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.interval=5000

### The expired time to clean metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.expired-time=60000

### The delay time before push task to execute from service changed, unit: milliseconds.
# nacos.naming.push.pushTaskDelay=500

### The timeout for push task execute, unit: milliseconds.
# nacos.naming.push.pushTaskTimeout=5000

### The delay time for retrying failed push task, unit: milliseconds.
# nacos.naming.push.pushTaskRetryDelay=1000

### Since 2.0.3
### The expired time for inactive client, unit: milliseconds.
# nacos.naming.client.expired.time=180000

#*************** 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 %{Request-Source}i

### The directory of access log:
server.tomcat.basedir=file:.

#*************** 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
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**

### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos

### If turn on auth system:
nacos.core.auth.enabled=false

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

### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false

### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security

### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789

### worked when nacos.core.auth.system.type=ldap,{0} is Placeholder,replace login username
#nacos.core.auth.ldap.url=ldap://localhost:389
#nacos.core.auth.ldap.basedc=dc=example,dc=org
#nacos.core.auth.ldap.userDn=cn=admin,${nacos.core.auth.ldap.basedc}
#nacos.core.auth.ldap.password=admin
#nacos.core.auth.ldap.userdn=cn={0},dc=example,dc=org
#nacos.core.auth.ldap.filter.prefix=uid
#nacos.core.auth.ldap.case.sensitive=true


#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

#*************** Core Related Configurations ***************#

### set the WorkerID manually
# nacos.core.snowflake.worker-id=

### Member-MetaData
# nacos.core.member.meta.site=
# nacos.core.member.meta.adweight=
# nacos.core.member.meta.weight=

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
## Server domain name address of [address-server] mode
# address.server.domain=jmenv.tbsite.net
## Server port of [address-server] mode
# address.server.port=8080
## Request address of [address-server] mode
# address.server.url=/nacos/serverlist

#*************** JRaft Related Configurations ***************#

### Sets the Raft cluster election timeout, default value is 5 second
# nacos.core.protocol.raft.data.election_timeout_ms=5000
### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
# nacos.core.proto

  • 46
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Docker安装Nacos,您可以按照以下步骤进行操作: 1. 首先,您需要在Docker安装MySQL 8。您可以执行以下命令来安装MySQL 8镜像: ``` docker pull mysql:8 ``` 2. 接下来,您需要下载NacosDocker镜像。您可以执行以下命令来下载Nacos的最新版本镜像: ``` docker pull nacos/nacos-server ``` 3. 然后,您可以使用以下命令运行Nacos容器: ``` docker run -d --name nacos -p 8848:8848 nacos/nacos-server ``` 4. 等待一段时间,Nacos容器将会启动。您可以使用以下命令来检查Nacos容器的状态: ``` docker ps ``` 5. 通过浏览器访问`http://localhost:8848`,您将能够看到Nacos的管理界面。 请注意,这些步骤是基于您已经在Docker安装了MySQL 8,并且已经正确配置了Docker环境的前提下进行的。如果您需要进一步配置Nacos或连接到MySQL,请参考Nacos官方文档或相关的资料。 <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [docker安装单机nacos <m1 mac >](https://blog.csdn.net/weixin_45197447/article/details/129165810)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Mac(M1芯片)通过Docker安装Nacos](https://blog.csdn.net/xichengfengyulou/article/details/126448685)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值