SpringCloud(微服务)学习篇(一)

news2024/9/29 9:22:13

SpringCloud(微服务)学习篇(一)

1 nacos的下载和配置

1.1 进入官网

nacos官网

1.2 点击nacos➡点击最新稳定版本

在这里插入图片描述

1.3 往下翻并点击nacos-server-2.2.0.zip,此时就已经开始下载了

在这里插入图片描述

1.4 把下载好的压缩包解压到没有中文路径的目录里面

在这里插入图片描述

1.5 修改application.properties文件

1.5.1 找到application.properties的位置

在这里插入图片描述

1.5.2 右键文件以记事本编辑并定位到mysql的位置

在这里插入图片描述

1.5.3 修改MySQL配置

在这里插入图片描述

1.5.4 完整的application.properties文件内容如下所示

#
# Copyright 1999-2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#*************** Spring Boot Related Configurations ***************#
### Default web context path:
server.servlet.contextPath=/nacos
### Include message field
server.error.include-message=ALWAYS
### Default web server port:
server.port=8848

#*************** Network Related Configurations ***************#
### If prefer hostname over ip for Nacos server addresses in cluster.conf:
# nacos.inetutils.prefer-hostname-over-ip=false

### Specify local server's IP:
# nacos.inetutils.ip-address=


#*************** 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=jdbc:mysql://127.0.0.1:3305/nacos?serverTimezone=UTC
db.user=root
db.password=root

### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

#*************** Naming Module Related Configurations ***************#

### If enable data warmup. If set to false, the server would accept request without local data preparation:
# nacos.naming.data.warmup=true

### If enable the instance auto expiration, kind like of health check of instance:
# nacos.naming.expireInstance=true

### Add in 2.0.0
### The interval to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.interval=60000

### The expired time to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.expired-time=60000

### The interval to clean expired metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.interval=5000

### The expired time to clean metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.expired-time=60000

### The delay time before push task to execute from service changed, unit: milliseconds.
# nacos.naming.push.pushTaskDelay=500

### The timeout for push task execute, unit: milliseconds.
# nacos.naming.push.pushTaskTimeout=5000

### The delay time for retrying failed push task, unit: milliseconds.
# nacos.naming.push.pushTaskRetryDelay=1000

### Since 2.0.3
### The expired time for inactive client, unit: milliseconds.
# nacos.naming.client.expired.time=180000

#*************** CMDB Module Related Configurations ***************#
### The interval to dump external CMDB in seconds:
# nacos.cmdb.dumpTaskInterval=3600

### The interval of polling data change event in seconds:
# nacos.cmdb.eventTaskInterval=10

### The interval of loading labels in seconds:
# nacos.cmdb.labelTaskInterval=300

### If turn on data loading task:
# nacos.cmdb.loadDataAtStart=false


#*************** Metrics Related Configurations ***************#
### Metrics for prometheus
#management.endpoints.web.exposure.include=*

### Metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200

### Metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
#management.metrics.export.influx.uri=http://localhost:8086
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true

#*************** Access Log Related Configurations ***************#
### If turn on the access log:
server.tomcat.accesslog.enabled=true

### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

### The directory of access log:
server.tomcat.basedir=file:.

#*************** Access Control Related Configurations ***************#
### If enable spring security, this option is deprecated in 1.2.0:
#spring.security.enabled=false

### The ignore urls of auth
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**

### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos

### If turn on auth system:
nacos.core.auth.enabled=false

### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true

### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false

### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security

### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789

### worked when nacos.core.auth.system.type=ldap,{0} is Placeholder,replace login username
#nacos.core.auth.ldap.url=ldap://localhost:389
#nacos.core.auth.ldap.basedc=dc=example,dc=org
#nacos.core.auth.ldap.userDn=cn=admin,${nacos.core.auth.ldap.basedc}
#nacos.core.auth.ldap.password=admin
#nacos.core.auth.ldap.userdn=cn={0},dc=example,dc=org
#nacos.core.auth.ldap.filter.prefix=uid
#nacos.core.auth.ldap.case.sensitive=true


#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

#*************** Core Related Configurations ***************#

### set the WorkerID manually
# nacos.core.snowflake.worker-id=

### Member-MetaData
# nacos.core.member.meta.site=
# nacos.core.member.meta.adweight=
# nacos.core.member.meta.weight=

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
## Server domain name address of [address-server] mode
# address.server.domain=jmenv.tbsite.net
## Server port of [address-server] mode
# address.server.port=8080
## Request address of [address-server] mode
# address.server.url=/nacos/serverlist

#*************** JRaft Related Configurations ***************#

### Sets the Raft cluster election timeout, default value is 5 second
# nacos.core.protocol.raft.data.election_timeout_ms=5000
### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
# nacos.core.protocol.raft.data.snapshot_interval_secs=30
### raft internal worker threads
# nacos.core.protocol.raft.data.core_thread_num=8
### Number of threads required for raft business request processing
# nacos.core.protocol.raft.data.cli_service_thread_num=4
### raft linear read strategy. Safe linear reads are used by default, that is, the Leader tenure is confirmed by heartbeat
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
### rpc request timeout, default 5 seconds
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000

#*************** Distro Related Configurations ***************#

### Distro data sync delay time, when sync task delayed, task will be merged for same data key. Default 1 second.
# nacos.core.protocol.distro.data.sync.delayMs=1000

### Distro data sync timeout for one sync data, default 3 seconds.
# nacos.core.protocol.distro.data.sync.timeoutMs=3000

### Distro data sync retry delay time when sync data failed or timeout, same behavior with delayMs, default 3 seconds.
# nacos.core.protocol.distro.data.sync.retryDelayMs=3000

### Distro data verify interval time, verify synced data whether expired for a interval. Default 5 seconds.
# nacos.core.protocol.distro.data.verify.intervalMs=5000

### Distro data verify timeout for one verify, default 3 seconds.
# nacos.core.protocol.distro.data.verify.timeoutMs=3000

### Distro data load retry delay when load snapshot data failed, default 30 seconds.
# nacos.core.protocol.distro.data.load.retryDelayMs=30000

### enable to support prometheus service discovery
#nacos.prometheus.metrics.enabled=true

1.6 修改startup.cmd文件

1.6.1 定位到startup.cmd的文件的位置

在这里插入图片描述

1.6.2 右键编辑startup.cmd文件

在这里插入图片描述

1.6.3 变更后的startup.cmd文件内容如下所示

@echo off
rem Copyright 1999-2018 Alibaba Group Holding Ltd.
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem      http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
if not exist "%JAVA_HOME%\bin\java.exe" echo Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! & EXIT /B 1
set "JAVA=%JAVA_HOME%\bin\java.exe"

setlocal enabledelayedexpansion

set BASE_DIR=%~dp0
rem added double quotation marks to avoid the issue caused by the folder names containing spaces.
rem removed the last 5 chars(which means \bin\) to get the base DIR.
set BASE_DIR="%BASE_DIR:~0,-5%"

set CUSTOM_SEARCH_LOCATIONS=file:%BASE_DIR%/conf/

set MODE="standalone"
set FUNCTION_MODE="all"
set SERVER=nacos-server
set MODE_INDEX=-1
set FUNCTION_MODE_INDEX=-1
set SERVER_INDEX=-1
set EMBEDDED_STORAGE_INDEX=-1
set EMBEDDED_STORAGE=""


set i=0
for %%a in (%*) do (
    if "%%a" == "-m" ( set /a MODE_INDEX=!i!+1 )
    if "%%a" == "-f" ( set /a FUNCTION_MODE_INDEX=!i!+1 )
    if "%%a" == "-s" ( set /a SERVER_INDEX=!i!+1 )
    if "%%a" == "-p" ( set /a EMBEDDED_STORAGE_INDEX=!i!+1 )
    set /a i+=1
)

set i=0
for %%a in (%*) do (
    if %MODE_INDEX% == !i! ( set MODE="%%a" )
    if %FUNCTION_MODE_INDEX% == !i! ( set FUNCTION_MODE="%%a" )
    if %SERVER_INDEX% == !i! (set SERVER="%%a")
    if %EMBEDDED_STORAGE_INDEX% == !i! (set EMBEDDED_STORAGE="%%a")
    set /a i+=1
)

rem if nacos startup mode is standalone
if %MODE% == "standalone" (
    echo "nacos is starting with standalone"
	  set "NACOS_OPTS=-Dnacos.standalone=true"
    set "NACOS_JVM_OPTS=-Xms512m -Xmx512m -Xmn256m"
)

rem if nacos startup mode is cluster
if %MODE% == "cluster" (
    echo "nacos is starting with cluster"
	  if %EMBEDDED_STORAGE% == "embedded" (
	      set "NACOS_OPTS=-DembeddedStorage=true"
	  )

    set "NACOS_JVM_OPTS=-server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%BASE_DIR%\logs\java_heapdump.hprof -XX:-UseLargePages"
)

rem set nacos's functionMode
if %FUNCTION_MODE% == "config" (
    set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.functionMode=config"
)

if %FUNCTION_MODE% == "naming" (
    set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.functionMode=naming"
)

rem set nacos options
set "NACOS_OPTS=%NACOS_OPTS% -Dloader.path=%BASE_DIR%/plugins,%BASE_DIR%/plugins/health,%BASE_DIR%/plugins/cmdb,%BASE_DIR%/plugins/selector"
set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.home=%BASE_DIR%"
set "NACOS_OPTS=%NACOS_OPTS% -jar %BASE_DIR%\target\%SERVER%.jar"

rem set nacos spring config location
set "NACOS_CONFIG_OPTS=--spring.config.additional-location=%CUSTOM_SEARCH_LOCATIONS%"

rem set nacos log4j file location
set "NACOS_LOG4J_OPTS=--logging.config=%BASE_DIR%/conf/nacos-logback.xml"


set COMMAND="%JAVA%" %NACOS_JVM_OPTS% %NACOS_OPTS% %NACOS_CONFIG_OPTS% %NACOS_LOG4J_OPTS% nacos.nacos %*

rem start nacos command
%COMMAND%

1.7 新建nacos数据库并导入需要的表

1.7.1 新建nacos数据库

在这里插入图片描述

1.7.2 右键nacos数据库➡点击运行SQL文件

在这里插入图片描述

1.7.3 点击右侧三个小圆点按钮,找到mysql-schema.sql文件的位置

在这里插入图片描述

1.7.4 找到mysql-schema.sql位置并点击打开按钮

在这里插入图片描述

1.7.5 点击开始按钮

在这里插入图片描述

1.7.6 导入成功后,nacos会出现这些表

在这里插入图片描述

1.7.7 打开users表,查看登录需要的账户和密码

在这里插入图片描述

1.8 双击startup.cmd文件

在这里插入图片描述

1.9 出现如下图案,代表配置成功

在这里插入图片描述

1.10 立马在浏览器里面输入http://127.0.0.1:8848/nacos/index.html 后回车进入如下界面

在这里插入图片描述

1.11 输入账户nacos和密码nacos后 并点击提交按钮

在这里插入图片描述

1.12 进入如下界面,代表nacos可以正常使用了

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/381371.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Testlink相关功能使用部分总结

1.首页面(普通用户,测试用例创建用户的权限) 右上角切换具体的项目;页面上方包含主页、用例、测试执行、测试结果;左侧包含测试项目管理、关键字管理、编辑测试用例、搜索测试用例、每用户创建的测试用例;…

Element UI的基本使用

学习来源,传送门 目录创建vue项目Element UI主要的标签Vue router 来动态创建左侧导航栏为何会发生嵌套menu与router的绑定设置默认展开设置默认打开页面创建vue项目 以管理员身份,在选定目录下,使用vue ui 按照正常配置配好,可…

Linux(ubuntu)系统搭建docker下的LNMP环境

系统环境 系统:Ubuntu 18.04.4 LTS x86_64 管理面板:宝塔面板7.9.8 下载镜像 通过面板下载docker和docker-compose 下载完毕后通过docker->镜像->从仓库拉取拉取镜像ubuntu:20.04 或者通过docker pull ubuntu:20.04拉取镜像 通过docker->容…

代码随想录算法训练营第四十一天 | 01背包问题-二维数组滚动数组,416. 分割等和子集

一、参考资料01背包问题 二维 https://programmercarl.com/%E8%83%8C%E5%8C%85%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%8001%E8%83%8C%E5%8C%85-1.html 视频讲解:https://www.bilibili.com/video/BV1cg411g7Y6 01背包问题 一维 https://programmercarl.com/%E8%83%8C%E5…

大功率分流电阻器产品阵容进一步扩大,助力大功率应用小型化

全球知名半导体制造商ROHM(总部位于日本京都市)面向车载、工业设备及白色家电等大功率应用,开发出大功率低阻值分流电阻器“GMR 系列”中额定功率最大的、10W 电阻器“GMR320”。近年来,在车载领域和工业设备领域中,应…

什么是敏捷测试

敏捷 反应快速灵敏。 在敏捷软件开发领域,更注重的以人为核心,迭代,循序渐进的开发方法。相比传统的开发方法,这种方法能更快速的开发,上线,反馈,调整、迭代。以敏捷的姿态去发展产品。 敏捷与…

基于java+swing+mysql员工工资管理系统

基于javaswingmysql员工工资管理系统一、系统介绍二、功能展示1.用户登陆2.员工主要功能3.管理员主要功能三、系统实现1.StudentFrame .java四、其它1.其他系统实现2.获取源码一、系统介绍 该项目功能相对完善,有管理员和普通用户两个角色,分别实现了一…

磷脂酰丝氨酸的作用;CAS:383907-32-2;磷脂酰丝氨酸(phosphatidylserine,PS)

磷脂酰丝氨酸(phosphatidylserine,PS)又称丝氨酸磷脂,二酰甘油酰磷酸丝氨酸,简称PS,是一类普遍存在的磷脂,通常位于细胞膜的内层,磷酯化合物中的磷酸甘油酯类,是细胞膜组…

数字化时代,企业如何通过技术改造传统客户服务模式

B端产品要从流量思维到客户思维上转变,良好的客户服务能够让B端企业走的越远走的越多,当然,对于所有产品或者企业来说,也唯有客户服务才是走的更远更久的保证,优秀的客户服务团队是企业的潜在优质财富。 搭建客服团队…

ATTO 647N-NHS ester,ATTO 647N SE,ATTO 647N NHS酯,适用于单分子检测应用

基础产品数据(Basic Product Data):CAS号:N/A中文名:ATTO 647N-琥珀酰亚胺酯,ATTO 647N-活性酯,ATTO 647N NHS酯英文名:ATTO 647 N-NHS,ATTO647N-NHS,ATTO 64…

为什么转行IT行业都会选择学习Python?

现在学习Python的人越来越多了,很多人都疑惑为什么这么多人转行IT都会选择学Python?为什么学Python要参加Python培训班呢?接下来蛋糕为大家答疑解惑一下吧。 虽然Python已经非常普及,但是大部分的大学都还没有开设Python课程,如果想要学习…

XGBoost学习-应用案例

文章目录一、过拟合:剪枝参数与回归模型调参二、XGBoost模型的保存和调用使用Joblib保存和调用模型三、分类案例:XGB中的样本不均衡问题四、 XGBoost类中的其他参数和功能总结一、过拟合:剪枝参数与回归模型调参 class xgboost.XGBRegressor…

2023前端vue面试题(边面边更)

Vue中key的作用 vue 中 key 值的作用可以分为两种情况来考虑: 第一种情况是 v-if 中使用 key。由于 Vue 会尽可能高效地渲染元素,通常会复用已有元素而不是从头开始渲染。因此当使用 v-if 来实现元素切换的时候,如果切换前后含有相同类型的…

只用最适合的 | 主流 .NET 报表控件全面对比

随着 .NET 平台的出现,报表相关的开发控件随着而来,已经有若干成熟的产品可供开发人员使用,本文旨在通过从不同维度对比目前最流行的3款 .NET报表控件:FastReport、Stimulsoft、水晶报表,给所有报表开发人员在做产品选…

家用洗地机哪款最好用?全球洗地机十大品牌

近年来,智能家用电器洗地机已经融入到我们生活中了,成为最受欢迎的清洁工具了,家用洗地机吸拖洗一体,不用先扫后拖那么麻烦,只需轻轻一推,就能把扫地、拖地、擦地的活全干了,操作简单&#xff0…

【iOS】—— 初识RAC响应式编程

RAC(ReactiveCocoa) 文章目录RAC(ReactiveCocoa)响应式编程和函数式编程的区别函数式编程响应式编程响应式编程的优点RAC操作1.利用button点击实现点击事件和传值2.RACSignal用法RACSignal总结:3.对于label的TapGestur…

Java | IO 模式之 JavaNIO 应用

文章目录NIO1 Java NIO 基本介绍2 NIO 和 BIO 的比较3 NIO 三大核心原理示意图3.1 Buffer缓冲区3.2 Channel(通道)3.3 Selector选择器3.4 总结4 NIO核心一:缓冲区(Buffer)4.1 缓冲区(Buffer)4.2 Buffer 类及其子类4.3 …

泛型与Map接口

Java学习之道 泛型 泛型这种参数类型可以用在类、方法和接口中,分别被称为泛型类,泛型方法,泛型接口 参数化类型:将类型由原来的具体的类型参数化,在使用/调用时传入具体的类型JDK5引入特性提供了安全检测机制&#xf…

[oeasy]python0097_苹果诞生_史蒂夫_乔布斯_沃兹尼亚克_apple_I

苹果诞生 回忆上次内容 上次时代华纳公司 凭借手中的影视ip和资本吞并了雅达利公司 此时 雅达利公司 曾经开发过pong的 优秀员工 乔布斯 还在 印度禅修 寻找自我 看到游戏行业 蓬勃发展 乔布斯 也想有自己的 一番天地 可是 他的机会在哪里呢?🤔 Jobs 跟着 Wozn…

顺序表——重置版

本期我们来实现数据结构的顺序表(这个之前写过一次,不过本期和之前可能会略有不同,但大体相同),大家可以看一下我们之前完成的顺序表 (6条消息) 顺序表及其多种接口的实现_顺序表类中实现接口方法_KLZUQ的博客-CSDN博客…