Java开发应用

springboot整合nacos,服务发现配置中心(一)

2022-01-20  本文已影响0人  指下光年

配置以及问题路径:https://www.jianshu.com/p/60ae960c40e1

  1. 搜索镜像
  [odin@localhost docker_sh]$ docker search nacos
  NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
  nacos/nacos-server                   This project contains a Docker image meant t…   226                  [OK]
  nacos/nacos-mysql                                                                    6                    
  nacos/nacos-mysql-master             nacos-mysql-master                              6                    
  1. 拉取镜像
docker pull nacos/nacos-server
  1. 创建挂载目录
mkdir /home/nacos_data/conf
mkdir /home/nacos_data/logs
  1. 启动临时容器
docker run --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server

开启端口命令:firewall-cmd --zone=public --add-port=8848/tcp --permanent
关闭端口命令:firewall-cmd --zone=public --remove-port=8848/tcp --permanent
查看端口是否开启 命令:firewall-cmd --query-port=8848/tcp
重启防火墙:firewall-cmd --reload
docker查看镜像:docker images
docker实时查看日志: docker logs -f 容器名

  1. 拷贝容器文件到主机
docker cp c3b9fb32b4d4:/home/nacos/conf  /home/nacos_data
docker cp c3b9fb32b4d4:/home/nacos/logs  /home/nacos_data
  1. 修改复制出来的配置文件
vi /home/nacos_data/conf/application.properties
# spring
server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.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://x.x.x.x:3306/nacos-dev?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}
nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity}
nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security}
server.tomcat.accesslog.enabled=true
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=${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

数据持久化到本地,本地创建数据库,执行数据库脚本。上面的配置文件改成自己的数据库
数据库脚本:https://www.jianshu.com/p/459e94cddcd7

第4步的时候我们开启了一个容器,别忘了把它停了并删除

  1. shell脚本启动
###nacos启动命令
docker  run --name nacos -d -p 8848:8848 --privileged=true --restart=always -e MODE=standalone -e PREFER_HOST_MODE=hostname -v /home/odin/nacos_datadir/logs:/home/nacos/logs -v /home/odin/nacos_datadir/conf/application.properties:/home/nacos/conf/application.properties nacos/nacos-server

上一篇下一篇

猜你喜欢

热点阅读