Nacos 源碼入門運行配置

什么是 Nacos?

Nacos 致力于幫助您發(fā)現(xiàn)、配置和管理微服務(wù)。Nacos 提供了一組簡單易用的特性集,幫助您快速實現(xiàn)動態(tài)服務(wù)發(fā)現(xiàn)、服務(wù)配置、服務(wù)元數(shù)據(jù)及流量管理。

具體請訪問Nacos網(wǎng)站查看文檔,現(xiàn)在開始使用Nacos。

下載Nacos源碼

Nacos可以通過源碼發(fā)行包兩種方式來獲取。
我們采用git源碼的方式,然后編譯運行和源碼運行兩種方式。

新建git項目使用 https://github.com/alibaba/nacos.git

1575045629456.png

運行 console項目的 SpringBoot Main Nacos 會報下面的異常:

2019-11-30 12:14:03.505 ERROR 9060 --- [           main] c.l.StartingSpringApplicationRunListener : read cluster conf fail

java.io.FileNotFoundException: C:\Users\wang\nacos\conf\cluster.conf (系統(tǒng)找不到指定的路徑。)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at com.alibaba.nacos.core.utils.SystemUtils.readClusterConf(SystemUtils.java:124)
    at com.alibaba.nacos.core.listener.StartingSpringApplicationRunListener.logClusterConf(StartingSpringApplicationRunListener.java:141)
    at com.alibaba.nacos.core.listener.StartingSpringApplicationRunListener.contextPrepared(StartingSpringApplicationRunListener.java:91)
    at org.springframework.boot.SpringApplicationRunListeners.contextPrepared(SpringApplicationRunListeners.java:60)
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:374)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at com.alibaba.nacos.Nacos.main(Nacos.java:35)

Nacos默認啟動是集群模式,單機模式需要設(shè)置啟動參數(shù) -Dnacos.standalone=true -Dnacos.home=E:\\tmp\nacos

創(chuàng)建Mysql數(shù)據(jù)庫

創(chuàng)建數(shù)據(jù)庫 nacos_config 導(dǎo)入nacos-mysql.sql 腳本

Snipaste_2019-11-30_12-28-53.png

修改配置文件

修改console項目的application.properties 添加數(shù)據(jù)庫連接

#設(shè)置數(shù)據(jù)源類型
spring.datasource.platform=mysql
#設(shè)置數(shù)據(jù)源連接數(shù)
db.num=1
#第一個數(shù)據(jù)源
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=123456

再次單機模式啟動,nacos數(shù)據(jù)都寫到了mysql

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容