TypechoJoeTheme

Jim Tse

【Nacos】nacos配置中心和服务发现

本文最后更新于2025年02月26日,已超过2天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

修改配置文件./config/application.properties

#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
# spring.datasource.platform=mysql
spring.sql.init.platform=mysql

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

### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_cfg?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=root

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

### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=nacosKey
nacos.core.auth.server.identity.value=nacosValue

### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=PqxnJL1XLuX4LgN3wUivR23hUpt6zuVCTMM7cpINAEM=

创建mysql数据库 nacos_cfg 并导入./config/mysql-schema.sql

-- 添加nacos用户、角色和权限
INSERT INTO `nacos_cfg`.`users` (`username`, `password`, `enabled`) VALUES ('nacos', '$2a$10$8aPT4SMvJkzR87eylTQene97fwb3GD/xEnY3fnYxbf5x8ShCv4xVK', 1);
INSERT INTO `nacos_cfg`.`roles` (`username`, `role`) VALUES ('nacos', 'ROLE_ADMIN');
INSERT INTO `nacos_cfg`.`permissions` (`role`, `resource`, `action`) VALUES ('ROLE_ADMIN', ':*:*', 'rw');

bin目录下运行nacos服务端

单机模式

sh startup.sh -m standalone

集群模式

修改 ./conf/cluster.conf

# ip:port
200.8.9.16:8848
200.8.9.17:8848
200.8.9.18:8848

集群模式逐台运行nacos服务端

# Linux/Unix/Mac
sh startup.sh -p embedded

# Ubuntu

bash startup.sh -p embedded

# Windows
startup.cmd -p embedded

bin目录下停止nacos服务器

sh shutdown.sh
赞(0)
版权属于:

Jim Tse

本文链接:

https://jimtse.eu.org:88/program/nacos.html(转载时请注明本文出处及文章链接)

评论 (0)