需要下载Nacos服务端程序,并运行bin目录下的startup.cmd,运行参数
运行前,必须设置JAVA_HOME环境变量,如: C:\Program Files\Java\jdk1.8.0_271
startup.cmd -m standalone
出现 如下信息表示启动成功
可以访问http://localhost:8848进入控制台
账号密码皆为:nacos
"nacos is starting with standalone"
,--.
,--.'|
,--,: : | Nacos 1.4.4
,`--.'`| ' : ,---. Running in stand alone mode, All function modules
| : : | | ' ,'\ .--.--. Port: 8848
: | \ | : ,--.--. ,---. / / | / / ' Pid: 20664
| : ' '; | / \ / \. ; ,. :| : /`./ Console: http://192.168.1.250:8848/nacos/index.html
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
| | | \ | \__\/: . .. ' / ' | .; : \ \ `. https://nacos.io
' : | ; .' ," .--.; |' ; :__| : | `----. \
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
' : | ; : .' \ : : `----' '--'. /
; |.' | , .-./\ \ / `--'---'
'---' `--`---' `----'
2022-08-23 09:45:02,749 INFO Tomcat initialized with port(s): 8848 (http)
2022-08-23 09:45:03,036 INFO Root WebApplicationContext: initialization completed in 1879 ms
2022-08-23 09:45:04,911 INFO Adding welcome page: class path resource [static/index.html]
2022-08-23 09:45:05,167 WARN You are asking Spring Security to ignore Ant [pattern='/**']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2022-08-23 09:45:05,168 INFO Will secure Ant [pattern='/**'] with []
2022-08-23 09:45:05,189 INFO Will not secure any request
2022-08-23 09:45:05,205 INFO Exposing 1 endpoint(s) beneath base path '/actuator'
2022-08-23 09:45:05,247 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'
2022-08-23 09:45:05,264 INFO Nacos started successfully in stand alone mode. use embedded storage
然后在项目内添加如下配置:
spring:
application:
#为项目起名字,这个名字会被nacos记录并使用
name: nacos-stock
cloud:
nacos:
discovery:
# 设置nacos服务器的地址
server-addr: localhost:8848
# 默认为true是临时实例, 改为 false 就是永久实例
ephemeral: true
<!-- Nacos注册依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
添加以上配置后,项目启动后会被注册到Nacos(此时并不能远程调用,远程调用需用到Dubbo)
达内:lzy