nacos入门配置学习
推荐在linux中部署
nacos是什么
Nacos 致力于帮助您发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。
Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。Nacos 是构建以“服务”为中心的现代应用架构 (例如微服务范式、云原生范式) 的服务基础设施。
前提条件
要保持linux机器上已经先安装了jdk和maven
1.linux 安装maven
官网下载http://maven.apache.org/download.cgi
https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
如果是linux 服务器
直接centos下用wget直接下载
[root@bogon ~]# wget https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
解压到 /opt/目录
[root@bogon ~]# tar zxvf apache-maven-3.6.3-bin.tar.gz -C /opt/
编辑环境变量
[root@bogon ~]# vim /etc/profile
运行以上命令以后,在最后添加如下两行
export M2_HOME=/opt/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin
让配置生效
[root@bogon ~]# source /etc/profile
source命令解释
source命令:
source命令也称为“点命令”,也就是一个点符号(.)。source命令通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录。
用法:
source filename 或 . filename
参考:http://blog.sina.com.cn/s/blog_608740170100wyar.html
验证是否安装完成
看到提示apache maven 3.6.3 表示 安装完成
[root@bogon ~]# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /usr/local/jdk1.8.0_211/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"
[root@bogon ~]#
安装配置nacos
参考:https://nacos.io/zh-cn/docs/quick-start.html
1.通过源码配置
git clone https://github.com/alibaba/nacos.git
cd nacos/
mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
ls -al distribution/target/
// change the $version to your actual path
cd distribution/target/nacos-server-$version/nacos/bin
不知道为啥虚拟机这么慢,看别人的一分钟,我的23分钟,最后还报错了
[INFO] Building zip: /root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT.zip
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Alibaba NACOS 1.4.0-SNAPSHOT 1.4.0-SNAPSHOT:
[INFO]
[INFO] Alibaba NACOS 1.4.0-SNAPSHOT ....................... SUCCESS [07:05 min]
[INFO] nacos-api 1.4.0-SNAPSHOT ........................... SUCCESS [01:57 min]
[INFO] nacos-common 1.4.0-SNAPSHOT ........................ SUCCESS [ 45.530 s]
[INFO] nacos-consistency 1.4.0-SNAPSHOT ................... SUCCESS [ 37.486 s]
[INFO] nacos-auth 1.4.0-SNAPSHOT .......................... SUCCESS [ 50.616 s]
[INFO] nacos-core 1.4.0-SNAPSHOT .......................... SUCCESS [03:13 min]
[INFO] nacos-config 1.4.0-SNAPSHOT ........................ SUCCESS [01:48 min]
[INFO] nacos-cmdb 1.4.0-SNAPSHOT .......................... SUCCESS [ 4.583 s]
[INFO] nacos-naming 1.4.0-SNAPSHOT ........................ SUCCESS [01:03 min]
[INFO] nacos-address 1.4.0-SNAPSHOT ....................... SUCCESS [ 12.282 s]
[INFO] nacos-client 1.4.0-SNAPSHOT ........................ SUCCESS [ 31.869 s]
[INFO] nacos-istio 1.4.0-SNAPSHOT ......................... SUCCESS [ 19.682 s]
[INFO] nacos-console 1.4.0-SNAPSHOT ....................... SUCCESS [01:39 min]
[INFO] nacos-test 1.4.0-SNAPSHOT .......................... SUCCESS [ 10.133 s]
[INFO] nacos-example 1.4.0-SNAPSHOT ....................... SUCCESS [ 4.220 s]
[INFO] nacos-distribution 1.4.0-SNAPSHOT .................. FAILURE [ 30.182 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21:38 min
[INFO] Finished at: 2020-09-17T10:08:27+08:00
[INFO] ------------------------------------------------------------------------
error信息如下:
nacos-distribution: Failed to create assembly: Error creating assembly archive server-1.4.0-SNAPSHOT: Problem creating zip
先不管错误 继续往下走
[root@bogon nacos]# ls -al distribution/target/
total 73892
drwxr-xr-x. 4 root root 204 Sep 17 10:08 .
drwxr-xr-x. 5 root root 249 Sep 17 10:07 ..
drwxr-xr-x. 2 root root 6 Sep 17 10:08 archive-tmp
-rw-r--r--. 1 root root 86 Sep 17 10:07 checkstyle-cachefile
-rw-r--r--. 1 root root 9774 Sep 17 10:07 checkstyle-checker.xml
-rw-r--r--. 1 root root 81 Sep 17 10:07 checkstyle-result.xml
drwxr-xr-x. 3 root root 19 Sep 17 10:08 nacos-server-1.4.0-SNAPSHOT
-rw-r--r--. 1 root root 75637869 Sep 17 10:08 nacos-server-1.4.0-SNAPSHOT.tar.gz
-rw-r--r--. 1 root root 1636 Sep 17 10:07 rat.txt
[root@bogon nacos]# cd distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos/bin/
启动服务器
[root@bogon bin]# sh startup.sh -m standalone
/usr/local/jdk1.8.0_211/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Djava.ext.dirs=/usr/local/jdk1.8.0_211/jre/lib/ext:/usr/local/jdk1.8.0_211/lib/ext -Xloggc:/root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos/plugins/health,/root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos/plugins/cmdb -Dnacos.home=/root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos -jar /root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos/target/nacos-server.jar --spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:/root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos/conf/ --logging.config=/root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288nacos is starting with standalonenacos is starting锛.ou can check the /root/nacos/distribution/target/nacos-server-1.4.0-SNAPSHOT/nacos/logs/start.out
有错误 ,去查看start.out
无法加载内置的tomcat
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
查看配置 ,把mysql的默认连接打开
找到mysql的地方,把前面的#去掉
2.也可以直接下载编译好的release包
https://github.com/alibaba/nacos/releases
下载tar.gz格式的直接用.
解压后直接运行以下命令启动
sh startup.sh -m standalone
参考阅读
standalone代表着单机模式运行,非集群模式
服务注册
启动以后运行以下命令,进行服务注册,时间会有点长
[root@localhost bin]# curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'
ok[root@localhost bin]#
服务发现
在服务注册成功以后,运行以下注册 ,进行服务发现
[root@localhost bin]# curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instance/list?serviceName=nacos.naming.serviceName'
{"dom":"nacos.naming.serviceName","hosts":[],"name":"DEFAULT_GROUP@@nacos.naming.serviceName","cacheMillis":3000,"lastRefTime":1600322889354,"checksum":"7f882d81002bc22181203d423a20a16d","useSpecifiedURL":false,"clusters":"","env":"","metadata":{}}[root@localhost bin]#
发布配置
curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld"
启动调试
curl是做什么的
参考:https://man.linuxde.net/curl
curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称curl为下载工具。作为一款强力工具,curl支持包括HTTP、HTTPS、ftp等众多协议,还支持POST、cookies、认证、从指定偏移处下载部分文件、用户代理字符串、限速、文件大小、进度条等特征。做网页处理流程和数据检索自动化,curl可以祝一臂之力。
-X/--request <command>指定什么命令
推荐阅读
-bash: mvn: command not found
1. 解决Docker容器应用中mvn: command not found的问题
参考:https://www.jianshu.com/p/8792b0d07568 相关不符合
2.官方
https://nacos.io/zh-cn/docs/quick-start.html