Windows下Nacos的安装与使用
Nacos入门使用
一,Windows下安装nacos
到 https://github.com/alibaba/nacos/tags寻找合适的版本(我这里选择的是2.0.4),然后下载 nacos-server-2.0.4.zip,,Linux或Mac环境下载 nacos-server-2.0.4.tar.gz
然后在本地选择目录进行解压
由于nacos默认是使用集群环境,因此我们在**\nacos\bin目录下,打开startup,cmd文件,修改第26行
set MODE="cluster"
改成
set MODE="standalone"
然后双击startup.cmd,运行项目
"nacos is starting with standalone"
,--.
,--.'|
,--,: : | Nacos 2.0.4
,`--.'`| ' : ,---. Running in stand alone mode, All function modules
| : : | | ' ,'\ .--.--. Port: 8848
: | \ | : ,--.--. ,---. / / | / / ' Pid: 47524
| : ' '; | / \ / \. ; ,. :| : /`./ Console: http://***:8848/nacos/index.html
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
| | | \ | \__\/: . .. ' / ' | .; : \ \ `. https://nacos.io
' : | ; .' ," .--.; |' ; :__| : | `----. \
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
' : | ; : .' \ : : `----' '--'. /
; |.' | , .-./\ \ / `--'---'
'---' `--`---' `----'
2022-04-03 22:22:15,422 INFO Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@5a62b2a4' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-04-03 22:22:15,426 INFO Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-04-03 22:22:15,916 INFO Tomcat initialized with port(s): 8848 (http)
2022-04-03 22:22:16,254 INFO Root WebApplicationContext: initialization completed in 3320 ms
2022-04-03 22:22:20,821 INFO Initializing ExecutorService 'applicationTaskExecutor'
2022-04-03 22:22:20,986 INFO Adding welcome page: class path resource [static/index.html]
2022-04-03 22:22:21,453 INFO Creating filter chain: Ant [pattern='/**'], []
2022-04-03 22:22:21,488 INFO Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@3c782d8e, org.springframework.security.web.context.SecurityContextPersistenceFilter@4d0753c9, org.springframework.security.web.header.HeaderWriterFilter@7acfb656, org.springframework.security.web.csrf.CsrfFilter@2acbc859, org.springframework.security.web.authentication.logout.LogoutFilter@20411320, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@719bb3b4, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@4d27d9d, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@572e6fd9, org.springframework.security.web.session.SessionManagementFilter@55a609dd, org.springframework.security.web.access.ExceptionTranslationFilter@2c6aed22]
2022-04-03 22:22:21,571 INFO Initializing ExecutorService 'taskScheduler'
2022-04-03 22:22:21,592 INFO Exposing 16 endpoint(s) beneath base path '/actuator'
2022-04-03 22:22:21,732 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'
2022-04-03 22:22:21,737 INFO Nacos started successfully in stand alone mode. use embedded storage
2022-04-03 22:22:52,576 INFO Initializing Servlet 'dispatcherServlet'
2022-04-03 22:22:52,581 INFO Completed initialization in 5 ms
在浏览器访问 http://localhost:8848/nacos,输入账号/密码:nacos/nacos进行登录。
二,自定义配置
2.1 使用自定义端口
修改**\nacos\conf\application.properties文件
server.port=9000
在浏览器访问 http://localhost:9000/nacos,输入账号/密码:nacos/nacos进行登录。
2.2 配置MySQL
修改**\nacos\conf\application.properties文件
#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/xxx?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=root
找到**\nacos\conf\nacos-mysql.sql文件,在MySQL的xxx数据库中导入该文件执行
配置成功,重启
在浏览器访问 http://localhost:9000/nacos,输入账号/密码:nacos/nacos进行登录。
2.3 自定义密码登录
2.3.1 修改数据库
在MySQL的xxx数据库中,找到表users
用户名username是明文,password是BCrypt加密的密文
修改密码可以通过http://www.ab126.com/goju/10822.html等网站生成Bcrypt密码,或者自己编写代码获取
public static void main(String[] args) {
System.out.println(new BCryptPasswordEncoder().encode("123456"));
}
记得引进spring-security-crypto依赖
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>5.6.2</version>
</dependency>
在浏览器访问 http://localhost:9000/nacos,输入账号/密码:nacos/123456进行登录。
2.3.2 通过页面修改
在nacos页面的【权限控制】- 【用户列表】,直接对用户修改密码
更多推荐
所有评论(0)