Table of contents
Previous article: Nacos Service Registration and Configuration Center
Nacos Server data persistence
-
Download nacos
nacos-server-1.2.0.tar
-
Execute mysql data script
-
Modify nacos configuration
-
Restart nacos and create a new namespace
Nacos Server cluster construction
- Modify configuration file
application.properties
### Specify local server's IP:
nacos.inetutils.ip-address=127.0.0.1
#*************** 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_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root
- Modify the cluster configuration file and make a copy
#it is ip
#example
127.0.0.1:8848
127.0.0.1:8849
127.0.0.1:8850
- Copy 3 copies of nacos 8848 8849 8850 and modify the ports respectively.
Start D:\dev\nacos-1\bin separately in cluster mode
# 单列模式
# .\startup.cmd -m standalone
# 集群模式
.\startup.cmd -m cluster
- Visit http://localhost:8848/nacos/ ports 8849 and 8850 respectively.
Register the microservice to the Nacos cluster
- Service provider registers with cluster
- Modify the configuration of service provider m-service-resume-8083-nacos
server:
port: 8083
spring:
application:
name: m-service-resume
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8 &serverTimezone=UTC
username: root
password: root
jpa:
database: MySQL
show-sql: true
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl #避免将驼峰命名转换为下划线命名
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848,127.0.0.1:8849,127.0.0.1:8850
# 非免密登录需要用户,密码等信息
# username: nacos
# password: nacos
# enabled: true
#集群名称
cluster-name: BJ
#所属命名空间 命名空间ID
namespace: 59486577-18d5-459c-94ad-cbdf6f3d9d5a
- Check the nacos cluster, m-service-resume has been registered in the dev cluster with the namespace
- Service consumers register to the cluster
- Modify m-service-autodeliver-8093-nacos configuration
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848,127.0.0.1:8849,127.0.0.1:8850
#集群名称
cluster-name: BJ
#所属命名空间
namespace: 59486577-18d5-459c-94ad-cbdf6f3d9d5a
- Observation cluster
- Access the consumer interface http://localhost:8093/autodeliver/checkState/1545132