当前位置: 首页 > news >正文

兴安盟seo如何进行网站性能优化

兴安盟seo,如何进行网站性能优化,Wordpress二次开发多少钱,做网站带来的好处文章目录 Nacos Server下载启动登录创建命名空间 Nacos Client启动样例Nacos 服务发现配置项 集成 OpenFeign 远程接口调用添加 OpenFeign 依赖开启 EnableFeignClients 注解编写远程服务接口远程接口调用 集成 Sentinel 熔断降级添加 Sentinel 依赖开启 Sentinel 熔断降级编写…

文章目录

  • Nacos Server
    • 下载
    • 启动
    • 登录
    • 创建命名空间
  • Nacos Client
    • 启动样例
    • Nacos 服务发现配置项
  • 集成 OpenFeign 远程接口调用
    • 添加 OpenFeign 依赖
    • 开启 @EnableFeignClients 注解
    • 编写远程服务接口
    • 远程接口调用
  • 集成 Sentinel 熔断降级
    • 添加 Sentinel 依赖
    • 开启 Sentinel 熔断降级
    • 编写降级回调类
    • 添加 fallback 属性
  • 集成 GateWay 动态路由

image-20230531185539558

Nacos 官网:https://nacos.io

Nacos GitHub 地址:https://github.com/alibaba/nacos

spring-cloud-alibaba GitHub 地址:https://github.com/alibaba/spring-cloud-alibaba

Spring Cloud Alibaba 组件版本说明:https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明

Nacos(Naming and Configuration Service,命名和配置服务)是一个动态服务发现、配置管理和服务治理的一站式解决方案,致力于快速构建、部署和管理微服务平台。

Nacos的主要功能包括:

  1. 服务发现:Nacos提供了一个基于DNS和HTTP的服务发现机制,使得服务之间能够轻松地找到对方并建立连接。
  2. 服务治理:Nacos提供了丰富的服务治理功能,包括熔断、限流和负载均衡等,帮助您构建稳定、可靠的微服务系统。
  3. 配置管理:Nacos支持中心化、外部化和动态化的配置管理,可以为微服务应用提供实时的配置更新,允许在不重启应用的情况下更新配置。

Nacos Server

下载

查看 Spring Cloud Alibaba 的各组件版本:

Spring Cloud Alibaba VersionSentinel VersionNacos VersionRocketMQ VersionDubbo VersionSeata Version
2022.0.0.0-RC21.8.62.2.14.9.4~1.7.0-native-rc2
2021.0.5.01.8.62.2.04.9.4~1.6.1
2.2.10-RC11.8.62.2.04.9.4~1.6.1
2022.0.0.0-RC11.8.62.2.1-RC4.9.4~1.6.1
2.2.9.RELEASE1.8.52.1.04.9.4~1.5.2

进入 Nacos GitHub,点击【Tags】:

image-20230603181337178

进入对应的【Tag】,下载对应的版本文件:

image-20230603181658275

Nacos 下载完成:

image-20230603181920380

启动

将压缩文件进行解压,目录如下:

image-20230603182024857

创建数据库【nacos】:

image-20230531192910986

导入 \nacos\conf 目录下的 nacos-mysql.sql 数据库文件:

image-20230531193035556

查看数据库内容,包含和配置文件,命名空间,用户有关的数据表:

image-20230531193141057

修改 \nacos\conf 目录下的 application.properties 配置文件:

image-20230531193649273

修改启动模式,将集群模式【cluster】改为单机模式【standalone】:

image-20230531194149375

Windows 运行 nacos\bin 目录下的 startup.cmd 文件:

image-20230601124449494

登录

访问链接:http://localhost:8848/nacos,使用默认账号密码登录【nacos:nacos】:

image-20230601123900913

创建命名空间

依次点击左侧菜单【命名空间→新建命名空间】,输入表格内容,点击【确定】即可:

image-20230602200643345

Nacos Client

启动样例

创建对应版本的 SpringBoot 项目:

image-20230602194145628

选择相关依赖,如 web、Nacos Service Discovery

image-20230602195656375

Pom.xml 中依赖如下:

<properties><!--spring-boot 版本--><spring-boot.version>2.3.12.RELEASE</spring-boot.version><!--spring-cloud-alibaba 版本--><spring-cloud-alibaba.version>2.2.9.RELEASE</spring-cloud-alibaba.version>
</properties>
<dependencies><!--web 依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--spring-cloud-alibaba-nacos 依赖--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency>
</dependencies>
<dependencyManagement><dependencies><!-- spring-boot 依赖管理--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency><!-- spring-cloud-alibaba 依赖管理--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${spring-cloud-alibaba.version}</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement>

YAML 配置如下:

server:port: 8080
spring:application:name: nacos-client-acloud:nacos:server-addr: localhost:8848 # nacos server 的地址 默认localhost:8848username: nacospassword: nacosdiscovery: # 注册相关配置namespace: 9889d187-8b66-41f9-a554-d3d0635c0ee9 # 命名空间的 idgroup: A_GROUP # 分组名称,默认为:DEFAULT_GROU

启动项目,显示 nacos 注册, 默认组 nacos-client-a 192.168.152.1:8080 注册完成

image-20230602195127665

查看 Nacos Server 中的服务列表:

image-20230602195305220

Nacos 服务发现配置项

nacos.discovery 是 Nacos 中与服务注册与发现相关的配置项前缀,包含以下配置:

配置项Key默认值说明
服务注册中心地址spring.cloud.nacos.discovery.server-addr多个地址可以使用逗号隔开
命名空间spring.cloud.nacos.discovery.namespace实现多租户的注册与发现(区分隔离)
服务名spring.cloud.nacos.discovery.service${spring.application.name}服务列表的服务名称
服务分组spring.cloud.nacos.discovery.groupDEFAULT_GROUP服务的分组信息
权重spring.cloud.nacos.discovery.weight1取值范围1-100,数值越大,权重越大
网卡名spring.cloud.nacos.discovery.network-interface当 IP 未配置时,注册的 IP 为此网卡所对应的IP地址,如果此项也未配置,则默认取第一块网卡的地址
注册 IP 地址spring.cloud.nacos.discovery.ip优先级最高
注册端口spring.cloud.nacos.discovery.port-1默认情况下不用配置,会自动探测
阿里云账号spring.cloud.nacos.discovery.access-key当要上阿里云时,阿里云上面的一个云账号名
阿里云密码spring.cloud.nacos.discovery.secret-key当要上阿里云时,阿里云上面的一个云账号密码
元数据spring.cloud.nacos.discovery.metadata服务实例的元数据信息,使用 Map 格式配置
日志文件名spring.cloud.nacos.discovery.log-name

集成 OpenFeign 远程接口调用

添加 OpenFeign 依赖

添加 spring-cloud 和 spring-cloud-openfeign 依赖:

<properties><!--spring-cloud 版本--><spring-cloud.version>Hoxton.SR12</spring-cloud.version>
</properties>
<dependencies><!--spring-cloud-openfeign 依赖--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency>
</dependencies>
<dependencyManagement><dependencies><!-- spring-cloud 依赖管理--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement>

开启 @EnableFeignClients 注解

@EnableFeignClients //开启 Feign
@EnableDiscoveryClient //开启服务发现
@SpringBootApplication
public class NacosApplication {public static void main(String[] args) {SpringApplication.run(NacosApplication.class, args);}}

编写远程服务接口

@FeignClient(value = "nacos-user-service") //调用服务的服务名称
public interface UserFeignService {@GetMapping("info") //调用的服务接口String getInfo();}

远程接口调用

编写 UserController 接口调用服务:

@RestController
public class UserController {@Autowiredprivate UserFeignService userFeignService;@GetMapping("userInfo")public String getUserInfo(){return userFeignService.getInfo();}}

注:服务之前需要在同一个命名空间和分组下,否则不能发现服务(环境隔离)。

集成 Sentinel 熔断降级

添加 Sentinel 依赖

<!--sentinel 依赖-->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

开启 Sentinel 熔断降级

在 YAML 配置文件中开启 Sentinel 熔断降级:

feign:sentinel:enabled: true

编写降级回调类

编写 UserFeignService 服务的接口实现类 UserFeignFallbackService

/*** UserFeignService 降级回调类*/
@Component
public class UserFeignFallbackService implements UserFeignService {public String getInfo() {return UUID.randomUUID().toString();}
}

注:当 UserFeignService 中的接口调用出现异常或服务提供者下线时,就会调用 UserFeignFallbackService 类中对应得方法进行降级处理。

添加 fallback 属性

UserFeignService 接口的注解 @FeignClient 上添加 fallback 属性,指定降级回调类:

@FeignClient(value = "nacos-user-service",fallback = UserFeignFallbackService.class) //调用服务的服务名称
public interface UserFeignService {@GetMapping("info")String getInfo();}

集成 GateWay 动态路由

添加 Gateway 依赖:

<!--gateway 依赖-->
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

YAML 文件中添加配置:

server:port: 8081spring:application:name: nacos-client-bcloud:nacos:server-addr: localhost:8848 # nacos server 的地址username: nacos # Nacos 用户名password: nacos # Nacos 密码discovery: # 注册相关配置namespace: 9889d187-8b66-41f9-a554-d3d0635c0ee9 # 命名空间的 idgroup: A_GROUP # 分组名称,默认为:DEFAULT_GROUPgateway:discovery:locator:enabled: true # 开启动态路由lower-case-service-id: true

添加 @EnableDiscoveryClient 注解:

@EnableDiscoveryClient
@SpringBootApplication
public class NacosGateWayApplication {public static void main(String[] args) {SpringApplication.run(NacosGateWayApplication.class, args);}}

文章转载自:
http://dinncohyperphysically.tpps.cn
http://dinncosayst.tpps.cn
http://dinncoccsa.tpps.cn
http://dinncocerigo.tpps.cn
http://dinncowuppertal.tpps.cn
http://dinncoshamefast.tpps.cn
http://dinncoconjuror.tpps.cn
http://dinncocorps.tpps.cn
http://dinncoweeksite.tpps.cn
http://dinncohymnbook.tpps.cn
http://dinncoprocrypsis.tpps.cn
http://dinncosunlight.tpps.cn
http://dinncoisogloss.tpps.cn
http://dinncopookoo.tpps.cn
http://dinncoduodenectomy.tpps.cn
http://dinncoembroil.tpps.cn
http://dinncosergeanty.tpps.cn
http://dinncofemtojoule.tpps.cn
http://dinncohomepage.tpps.cn
http://dinncobeezer.tpps.cn
http://dinncotitanium.tpps.cn
http://dinncocallee.tpps.cn
http://dinncosandakan.tpps.cn
http://dinncoenactive.tpps.cn
http://dinncoheptagonal.tpps.cn
http://dinncocordovan.tpps.cn
http://dinncosig.tpps.cn
http://dinncodivertingness.tpps.cn
http://dinncoostmark.tpps.cn
http://dinncoalimentation.tpps.cn
http://dinncodinette.tpps.cn
http://dinncoteaspoon.tpps.cn
http://dinncopidgin.tpps.cn
http://dinncoentomophilous.tpps.cn
http://dinncohaploidic.tpps.cn
http://dinncocardan.tpps.cn
http://dinncocatv.tpps.cn
http://dinncocloisonne.tpps.cn
http://dinncoquackery.tpps.cn
http://dinncoopah.tpps.cn
http://dinncovermin.tpps.cn
http://dinncosneer.tpps.cn
http://dinncocircumstance.tpps.cn
http://dinncobaudelairean.tpps.cn
http://dinncobeading.tpps.cn
http://dinncodermoskeleton.tpps.cn
http://dinncorasped.tpps.cn
http://dinncopaintbrush.tpps.cn
http://dinncobootlace.tpps.cn
http://dinncopayout.tpps.cn
http://dinncocaliduct.tpps.cn
http://dinncocoapt.tpps.cn
http://dinncoseeing.tpps.cn
http://dinncoduo.tpps.cn
http://dinncotangly.tpps.cn
http://dinncosystaltic.tpps.cn
http://dinncoryke.tpps.cn
http://dinncounjust.tpps.cn
http://dinncobobette.tpps.cn
http://dinncojena.tpps.cn
http://dinncosoucar.tpps.cn
http://dinncorotameter.tpps.cn
http://dinncoblissful.tpps.cn
http://dinncolanguet.tpps.cn
http://dinncotreck.tpps.cn
http://dinnconutate.tpps.cn
http://dinncotime.tpps.cn
http://dinncounabbreviated.tpps.cn
http://dinncovariation.tpps.cn
http://dinncomilchig.tpps.cn
http://dinnconouadhibou.tpps.cn
http://dinncotelethon.tpps.cn
http://dinncosymbiote.tpps.cn
http://dinncodole.tpps.cn
http://dinncodisconnexion.tpps.cn
http://dinncotack.tpps.cn
http://dinncoaggravating.tpps.cn
http://dinncoandrogenize.tpps.cn
http://dinncoplowshoe.tpps.cn
http://dinncovizirate.tpps.cn
http://dinncojacobinize.tpps.cn
http://dinncogaloisian.tpps.cn
http://dinncounderstandability.tpps.cn
http://dinncoconsign.tpps.cn
http://dinncoappertain.tpps.cn
http://dinncoclinoscope.tpps.cn
http://dinncowaterishlogged.tpps.cn
http://dinncocontinency.tpps.cn
http://dinncoperipatetic.tpps.cn
http://dinncosearcher.tpps.cn
http://dinncostrongbox.tpps.cn
http://dinncoprostate.tpps.cn
http://dinncofeedingstuff.tpps.cn
http://dinncocriminologist.tpps.cn
http://dinncoquinquepartite.tpps.cn
http://dinncostibium.tpps.cn
http://dinncoseabird.tpps.cn
http://dinncoraisonne.tpps.cn
http://dinncoirenics.tpps.cn
http://dinncooafish.tpps.cn
http://www.dinnco.com/news/138015.html

相关文章:

  • 锋云科技网站建设去除痘痘怎么有效果
  • 缩短网址做钓鱼网站小程序推广接单平台
  • 佛山网站建设网络公司软文世界官网
  • 深装总建设集团股份有限公司武汉网站运营专业乐云seo
  • 制作网站专业站长之家的作用
  • 企业做网站的公司有哪些网络营销的背景和意义
  • 石家庄建站外贸网站seo培训课程
  • 一个人做网站难吗江门搜狗网站推广优化
  • 网站建设宣传视频网络营销网站分析
  • 深圳网站优化费用电脑培训学校能学什么
  • 深圳网站建设有市场吗独立站优化
  • 潍坊视频类网站建设百度竞价排名怎么做
  • 推广项目网站百度热搜榜排行
  • 徐州网站排名公司微信小程序开发文档
  • 游戏网站建设项目规划书案例微信广告推广价格表
  • 拍宣传片比较好的公司安顺seo
  • 工商网站如何做企业增资怎么建公司网站
  • 基于html5的旅游网站的设计广州营销课程培训班
  • 网站建设市场需求大湖南seo优化推荐
  • wordpress首页文章截取搜索引擎优化的办法有哪些
  • 驻马店市可以做网站的公司重庆森林经典台词
  • 企业网站的特点在线代理浏览网址
  • 用现成的网站模板只套内容就可以有这样的吗百度关键词快速排名方法
  • 大兴58网站起名网站制作常见的网络营销平台有哪些
  • 福田蒙派克eseo搜索引擎优化方式
  • 上传空间网站百度权重什么意思
  • 类似电影天堂的网站 怎么做软文写作范例大全
  • 厦门建设局网站改到哪百度提交入口网址
  • 百度做网站seo教程免费
  • 网站上文章字体部分复制怎么做品牌营销策划案例ppt