简介看官网,不多说,下载最新稳定版:wget https://github.com/alibaba/nacos/releases/download/2.0.4/nacos-server-2.0.4.tar.gz
tar -xf nacos.tar.gz cd nacos/bin/ #因为只有一台机器,所以必须加-m standalone bash startup.sh -m standalone #成功
因为用的是腾讯云的轻应用服务器(便宜,几十块钱3年2核4G等于白嫖咯),授权防火墙8848/TCP协议
打开控制面板:http://ip:8848/nacos/#/login, 默认账号密码nacos/nacos,可视化操作没什么好说的,权限控制,先改密码,添加新用户
配置管理,稀里哗啦把相关的配置搬到配置管理中,搞定
package nacos import ( "fmt" "github.com/nacos-group/nacos-sdk-go/clients" "github.com/nacos-group/nacos-sdk-go/common/constant" "github.com/nacos-group/nacos-sdk-go/vo" "os" ) func init() { //因为这里添加配置时候选的是public所以namespaceId放空,不然会报错找不到配置 //namespaceId := "53f7f635-9af9-4f30-b665-c9d7342134dc" cwd, _ := os.Getwd() cc := constant.ClientConfig{ //Endpoint: "81.68.69.29:8848", NamespaceId: "", Username: "your username", Password: "your password", LogLevel: "debug", CacheDir: cwd + "/log/cache", } serverConfigs := []constant.ServerConfig{ { ContextPath: "/nacos", IpAddr: "ip", Port: 8848, Scheme: "http", }, } clients.CreateNamingClient(map[string]interface{}{ "serverConfigs": serverConfigs, "clientConfig": cc, }) client, _ := clients.CreateConfigClient(map[string]interface{}{ "serverConfigs": serverConfigs, "clientConfig": cc, }) fmt.Println("Init Nacos Ok.") body, _ := client.GetConfig(vo.ConfigParam{ DataId: "your dataId", Group: "your groupId", OnChange: func(namespace, group, dataId, data string) { fmt.Println("config changed group:" + group + ", dataId:" + dataId + ", content:" + data) }, }) fmt.Println("GetConfig:" + body) client.ListenConfig(vo.ConfigParam{ DataId: "your dataId", Group: "your groupId", OnChange: func(namespace, group, dataId, data string) { //我用的是beego所以。 //可以注入到beegoConfig中 fmt.Println("config changed group:" + group + ", dataId:" + dataId + ", content:" + data) }, }) }
然后在main.go中引入一下即可
import _ "your_project/nacos"