<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>微服务 &#8211; chang的个人博客</title>
	<atom:link href="https://www.qiqin-chang.cn/category/springcloud/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.qiqin-chang.cn</link>
	<description></description>
	<lastBuildDate>Sun, 28 Dec 2025 19:29:03 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.qiqin-chang.cn/wp-content/uploads/2025/04/cropped-无背景-圆形-32x32.png</url>
	<title>微服务 &#8211; chang的个人博客</title>
	<link>https://www.qiqin-chang.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Sentinel-服务保护</title>
		<link>https://www.qiqin-chang.cn/sentinel-%e6%9c%8d%e5%8a%a1%e4%bf%9d%e6%8a%a4/</link>
					<comments>https://www.qiqin-chang.cn/sentinel-%e6%9c%8d%e5%8a%a1%e4%bf%9d%e6%8a%a4/#respond</comments>
		
		<dc:creator><![CDATA[乐章]]></dc:creator>
		<pubDate>Wed, 30 Apr 2025 19:15:40 +0000</pubDate>
				<category><![CDATA[微服务]]></category>
		<guid isPermaLink="false">http://www.qiqin-chang.cn/?p=454</guid>

					<description><![CDATA[基础配置： 依赖： 配置： 异常处理： 流控异常： 异常类： @SentinelResource: 异常类：  [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">基础配置：</h1>



<p>依赖：</p>



<pre class="wp-block-code"><code>&lt;!--sentinel 服务保护-->
&lt;dependency>
    &lt;groupId>com.alibaba.cloud&lt;/groupId> 
    &lt;artifactId>spring-cloud-starter-alibaba-sentinel&lt;/artifactId>
&lt;/dependency></code></pre>



<p>配置：</p>



<pre class="wp-block-code"><code>spring:
  cloud:
    sentinel:
      transport:
        dashboard: localhost:8080 #控制台地址
      eager: true
      http-method-specify: true # 区分请求方式前缀(可选)
      # web-context-unify: false #开启链路分割</code></pre>



<h1 class="wp-block-heading">异常处理：</h1>



<h2 class="wp-block-heading">流控异常：</h2>



<p>异常类：</p>



<pre class="wp-block-code"><code>@Component
public class MyBlockExceptionHandler implements BlockExceptionHandler {
​
    private ObjectMapper objectMapper = new ObjectMapper();
​
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, String resourceName, BlockException e) throws Exception {
​
        response.setContentType("application/json;charset=utf-8");
        PrintWriter writer = response.getWriter();
​
        //R为返回结果类，请使用自己的结果类包装
        R error = R.error(500,resourceName + "被Sentinel限制了,原因" + e.getClass()); 
        String json = objectMapper.writeValueAsString(error);
        writer.write(json);
​
        writer.flush();
        writer.close();
    }
}</code></pre>



<h2 class="wp-block-heading">@SentinelResource:</h2>



<p>异常类：</p>



<p>全局异常处理器：</p>



<pre class="wp-block-code"><code>@RestControllerAdvice //全局异常处理器
public class GlobalExceptionHandler {
    
}</code></pre>



<p>方法注解：</p>



<pre class="wp-block-code"><code>@SentinelResource(value = "createUser-资源名称",blockHandler = "createUserFallback-兜底函数") //fallback异常</code></pre>



<p>服务类中兜底函数:</p>



<pre class="wp-block-code"><code>//兜底回调
public Order createUserFallback(Long userId, BlockException e) { //Throwable exception
    User user = new user();
    user.setId(0L);
    user.setTotalAmount(new BigDecimal("0"));
    user.setUserId(userId);
    user.setNickName("未知用户");
    user.setAddress("异常信息："+ e.getClass());
​
    return user;
}</code></pre>



<h2 class="wp-block-heading">OpenFeign:</h2>



<p>请看OpenFeign章节</p>



<h2 class="wp-block-heading">硬编码SphU：</h2>



<pre class="wp-block-code"><code>try {
    SphU.entry("resourceName");   
}catch (BlockException e) {
    //编码处理            
}</code></pre>



<h1 class="wp-block-heading">流控规则：</h1>



<h2 class="wp-block-heading">阈值类型：</h2>





<ul class="wp-block-list">
<li>阈值 请求阈值</li>



<li>QPS 每秒访问次数</li>



<li>并发线程数 分配线程池连接数量</li>
</ul>



<p>集群模式：</p>



<ul class="wp-block-list">
<li>单机均摊 每台服务器都分配阈值的数量</li>



<li>总体阈值 所有服务器一共分配阈值的数量</li>
</ul>



<h2 class="wp-block-heading">流控模式：</h2>





<ul class="wp-block-list">
<li>直接 达到阈值触发流控</li>



<li>链路 需要开启链路分割对不同链路都可进行流控</li>



<li>关联 需要开启链路分割关联的链路达到阈值触发流控</li>
</ul>



<h2 class="wp-block-heading">流控效果：</h2>



<ul class="wp-block-list">
<li>快速失败 达到阈值直接失败</li>



<li>Warm UP(预热/冷启动) +冷启动时间 逐渐增加并发数直至阈值</li>



<li>匀速排队 +最大等待时间 每秒接受阈值个请求其余请求进行排队超出最大请求时间将被舍弃</li>
</ul>



<h2 class="wp-block-heading">熔断降级：</h2>



<ul class="wp-block-list">
<li>慢调用比例 规定时间内超时线程比例超过阈值进行熔断</li>



<li>异常比例 规定时间内异常线程比例超过阈值进行熔断</li>



<li>异常数 规定时间内异常数超过阈值进行熔断</li>
</ul>



<h2 class="wp-block-heading">热点规则：</h2>



<ul class="wp-block-list">
<li>对参数实现流控规则</li>
</ul>



<h2 class="wp-block-heading">权限规则：</h2>



<ul class="wp-block-list">
<li>设置流控应用的黑白名单</li>
</ul>



<h2 class="wp-block-heading">系统规则：</h2>



<ul class="wp-block-list">
<li>对系统的整体阈值进行规则限流</li>
</ul>



<h1 class="wp-block-heading">请求限流：</h1>



<h2 class="wp-block-heading">线程隔离：</h2>



<p>OpenFeign整合Sentinel:</p>



<p>修改chang-service模块的application.yml文件，开启Feign的sentinel功能：</p>



<pre class="wp-block-code"><code>feign:
  sentinel:
    enabled: true # 开启feign对sentinel的支持</code></pre>



<p>测试配置：</p>



<pre class="wp-block-code"><code>server:
  port: 8082
  tomcat:
    threads:
      max: 50 # 允许的最大线程数
    accept-count: 50 # 最大排队等待数量
    max-connections: 100 # 允许的最大连接</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.qiqin-chang.cn/sentinel-%e6%9c%8d%e5%8a%a1%e4%bf%9d%e6%8a%a4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>密码保护：Seata-分布式事务</title>
		<link>https://www.qiqin-chang.cn/seata-%e5%88%86%e5%b8%83%e5%bc%8f%e4%ba%8b%e5%8a%a1/</link>
					<comments>https://www.qiqin-chang.cn/seata-%e5%88%86%e5%b8%83%e5%bc%8f%e4%ba%8b%e5%8a%a1/#respond</comments>
		
		<dc:creator><![CDATA[乐章]]></dc:creator>
		<pubDate>Wed, 30 Apr 2025 19:08:02 +0000</pubDate>
				<category><![CDATA[微服务]]></category>
		<guid isPermaLink="false">http://www.qiqin-chang.cn/?p=452</guid>

					<description><![CDATA[无法提供摘要。这是一篇受保护的文章。]]></description>
										<content:encoded><![CDATA[<form action="https://www.qiqin-chang.cn/znyz" class="post-password-form" method="post"><input type="hidden" name="redirect_to" value="https://www.qiqin-chang.cn/seata-%e5%88%86%e5%b8%83%e5%bc%8f%e4%ba%8b%e5%8a%a1/" /></p>
<p>此内容受密码保护。如需查阅，请在下方输入密码。</p>
<p><label for="pwbox-452">密码： <input name="post_password" id="pwbox-452" type="password" spellcheck="false" required size="20" /></label> <input type="submit" name="Submit" value="提交" /></p>
</form>
]]></content:encoded>
					
					<wfw:commentRss>https://www.qiqin-chang.cn/seata-%e5%88%86%e5%b8%83%e5%bc%8f%e4%ba%8b%e5%8a%a1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Nacos-注册中心</title>
		<link>https://www.qiqin-chang.cn/nacos-%e6%b3%a8%e5%86%8c%e4%b8%ad%e5%bf%83/</link>
					<comments>https://www.qiqin-chang.cn/nacos-%e6%b3%a8%e5%86%8c%e4%b8%ad%e5%bf%83/#respond</comments>
		
		<dc:creator><![CDATA[乐章]]></dc:creator>
		<pubDate>Thu, 10 Apr 2025 23:47:09 +0000</pubDate>
				<category><![CDATA[微服务]]></category>
		<guid isPermaLink="false">http://8.153.197.211/?p=218</guid>

					<description><![CDATA[注册中心： 基础配置： 依赖： 配置： 服务注册： 服务发现： 在启动类上添加： 实现负载均衡的远程调用： 依 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">注册中心：</h1>



<h2 class="wp-block-heading">基础配置：</h2>



<p>依赖：</p>



<pre class="wp-block-code"><code>&lt;!--nacos 服务注册发现--&gt;
&lt;dependency&gt;
 &nbsp; &nbsp;&lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
 &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-discovery&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;!--微服务web项目启动--&gt;
&lt;dependency&gt;
 &nbsp; &nbsp;&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
 &nbsp; &nbsp;&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>



<p>配置：</p>



<p>服务注册：</p>



<pre class="wp-block-code"><code>spring:
  application:
 &nbsp;  name: user-service # 服务名称
  cloud:
 &nbsp;  nacos:
 &nbsp; &nbsp;  server-addr: localhost:8848 # nacos地址</code></pre>



<p>服务发现：</p>



<p>在启动类上添加：</p>



<pre class="wp-block-code"><code>@EnableDiscoveryClient //开启服务发现功能</code></pre>



<h2 class="wp-block-heading">实现负载均衡的远程调用：</h2>



<p>依赖：</p>



<pre class="wp-block-code"><code>&lt;!--loadbalancer 负载均衡--&gt;
&lt;dependency&gt;
 &nbsp; &nbsp;&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
 &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-loadbalancer&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>



<p>注解式负载均衡：</p>



<pre class="wp-block-code"><code>@LoadBalanced //注解式负载均衡</code></pre>



<p>配置类：</p>



<pre class="wp-block-code"><code>@Configuration
public class UserConfig {
​
 &nbsp; &nbsp;
 &nbsp; &nbsp;@Bean
 &nbsp; &nbsp;RestTemplate restTemplate() {
 &nbsp; &nbsp; &nbsp; &nbsp;return new RestTemplate();
 &nbsp;  }
}</code></pre>



<p>远程调用：</p>



<pre class="wp-block-code"><code>//基于注解的负载均衡
private Product getUserFromRemoteWithLoadBalanceAnnotation(Long id) {
 &nbsp; &nbsp;//1.获取到商品服务所在的所有机器IP+port
 &nbsp; &nbsp;String url = "http://user-service/user/" + Id; //根据服务名称自动负载均衡的匹配服务地址
 &nbsp; &nbsp;//2.给远程发送请求
 &nbsp; &nbsp;User user = restTemplate.getForObject(url, Product.class);
 &nbsp; &nbsp;return user;
}</code></pre>



<h1 class="wp-block-heading">配置中心：</h1>



<h2 class="wp-block-heading">配置隔离：</h2>



<p>常见SpringBoot环境：</p>



<ul class="wp-block-list">
<li>dev 开发环境</li>



<li>test 测试环境</li>



<li>prod 生产环境</li>
</ul>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="172" src="https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-02-1024x172.png" alt="" class="wp-image-427" srcset="https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-02-1024x172.png 1024w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-02-300x50.png 300w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-02-768x129.png 768w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-02-1536x258.png 1536w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-02-2048x345.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">添加共享配置：</h2>



<p>在配置管理-&gt;配置列表中点击+新建一个配置：</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="453" src="https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-14-1024x453.png" alt="" class="wp-image-235" srcset="https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-14-1024x453.png 1024w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-14-300x133.png 300w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-14-768x340.png 768w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-14-1536x679.png 1536w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-14.png 1723w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>在弹出的表单中填写信息：</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="620" src="https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-15-1024x620.png" alt="" class="wp-image-236" srcset="https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-15-1024x620.png 1024w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-15-300x182.png 300w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-15-768x465.png 768w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/nacos-15.png 1150w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">拉取共享配置：</h2>



<p>依赖：</p>



<pre class="wp-block-code"><code>&lt;!--nacos 配置中心--&gt;
&lt;dependency&gt;
 &nbsp; &nbsp;&lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
 &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-config&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;!--读取bootstrap文件--&gt;
&lt;dependency&gt;
 &nbsp; &nbsp;&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
 &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-bootstrap&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>



<p>配置：</p>



<p>配置导入规则：先导入优先，外部导入优先</p>



<pre class="wp-block-code"><code>server:
  port: 8000
​
spring:
  profiles:
 &nbsp;  active: dev #激活某一环境
  application:
 &nbsp;  name: user-service # 服务名称
  cloud:
 &nbsp;  nacos:
 &nbsp; &nbsp;  server-addr: localhost:8848 # nacos地址
 &nbsp; &nbsp;  config:
 &nbsp; &nbsp; &nbsp;  import-check:
 &nbsp; &nbsp; &nbsp; &nbsp;  enabled: false #禁用导入检查
 &nbsp; &nbsp; &nbsp;  namespace: ${spring.profiles.active:public} #使用选定环境的命名空间中的配置 -选定默认值为public
​
#以下为不同开发环境配置
#开发环境
---
spring:
  config:
 &nbsp;  activate:
 &nbsp; &nbsp;  on-profile: dev
 &nbsp;  import:
 &nbsp; &nbsp;  - nacos:common.yaml?group=order #按需加载对应组群的配置文件
 &nbsp; &nbsp;  - nacos:database.yaml?group=order
​
#测试环境
---
spring:
  config:
 &nbsp;  activate:
 &nbsp; &nbsp;  on-profile: test
 &nbsp;  import:
 &nbsp; &nbsp;  - nacos:database.yaml?group=order
​
#生产环境
---
spring:
  config:
 &nbsp;  activate:
 &nbsp; &nbsp;  on-profile: prod
 &nbsp;  import:
 &nbsp; &nbsp;  - nacos:common.yaml?group=order</code></pre>



<h2 class="wp-block-heading">配置自动刷新：</h2>



<h3 class="wp-block-heading">自动刷新：</h3>



<p>类注解：</p>



<pre class="wp-block-code"><code>@RefreshScope</code></pre>



<p>配置类成员变量注解：</p>



<pre class="wp-block-code"><code>@value</code></pre>



<h3 class="wp-block-heading">批量绑定自动刷新：</h3>



<p>配置类注解：</p>



<pre class="wp-block-code"><code>@ConfigurationProperties</code></pre>



<p>配置类方法：</p>



<pre class="wp-block-code"><code>@Component
@ConfigurationProperties(prefix = "user")//配置批量绑定在nacos下，可无需@RefreshScope实现自动刷新，以驼峰命名代替'-'格式
@Data
public class UserProperties {
​
 &nbsp; &nbsp;String timeout;
​
 &nbsp; &nbsp;String autoConfirm;
​
 &nbsp; &nbsp;String dbUrl;
}</code></pre>



<h3 class="wp-block-heading">监听配置变化：</h3>



<p>启动类方法：</p>



<pre class="wp-block-code"><code>//1.项目启动就监听配置文件的变化
//2.发生变化后拿到变化的值
//3.发送邮件
@Bean
ApplicationRunner applicationRunner(NacosConfigManager nacosConfigManager) {
 &nbsp; &nbsp;return args -&gt; {
 &nbsp; &nbsp; &nbsp; &nbsp;ConfigService configService = nacosConfigManager.getConfigService();
 &nbsp; &nbsp; &nbsp; &nbsp;configService.addListener("user-service.yaml",
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"DEFAULT_GROUP",new Listener() {
​
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Override
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public Executor getExecutor() {
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return Executors.newFixedThreadPool(4);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
​
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Override
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public void receiveConfigInfo(String configInfo) {
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println("变化的配置信息" + configInfo);
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println("邮件通知...");
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
 &nbsp; };
}</code></pre>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.qiqin-chang.cn/nacos-%e6%b3%a8%e5%86%8c%e4%b8%ad%e5%bf%83/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>OpenFeign-远程调用</title>
		<link>https://www.qiqin-chang.cn/openfeign-%e8%bf%9c%e7%a8%8b%e8%b0%83%e7%94%a8/</link>
					<comments>https://www.qiqin-chang.cn/openfeign-%e8%bf%9c%e7%a8%8b%e8%b0%83%e7%94%a8/#respond</comments>
		
		<dc:creator><![CDATA[乐章]]></dc:creator>
		<pubDate>Thu, 10 Apr 2025 01:09:30 +0000</pubDate>
				<category><![CDATA[微服务]]></category>
		<guid isPermaLink="false">http://8.153.197.211/?p=145</guid>

					<description><![CDATA[返回 基础配置： 依赖： 启动类添加注解: 方式1：声明扫描包： 方式2：声明要用的FeignClient：  [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="typora://app/%E7%9B%AE%E5%BD%95%E9%A1%B5" id="top"><br>返回</a></p>



<h1 class="wp-block-heading">基础配置：</h1>



<p>依赖：</p>



<pre class="wp-block-code"><code> &nbsp;&lt;!--openFeign-远程调用--&gt;
 &nbsp;&lt;dependency&gt;
 &nbsp; &nbsp; &nbsp;&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
 &nbsp; &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-openfeign&lt;/artifactId&gt;
 &nbsp;&lt;/dependency&gt;
​
 &nbsp;&lt;!--loadbalancer 负载均衡--&gt;
 &nbsp;&lt;dependency&gt;
 &nbsp; &nbsp; &nbsp;&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
 &nbsp; &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-loadbalancer&lt;/artifactId&gt;
 &nbsp;&lt;/dependency&gt;</code></pre>



<p>启动类添加注解:</p>



<pre class="wp-block-code"><code>@EnableFeignClients //开启Fegin远程调用功能，需在服务的启动类上添加</code></pre>



<p>方式1：声明扫描包：</p>



<pre class="wp-block-code"><code>@EnableFeignClients(basePackages = “com.chang.api.client”)</code></pre>



<p>方式2：声明要用的FeignClient：</p>



<pre class="wp-block-code"><code>@EnableFeignClients(userClient.class)</code></pre>



<h1 class="wp-block-heading">使用方法：</h1>



<ul class="wp-block-list">
<li>在要使用的微服务中创建client包，在包中书写远程请求代码</li>
</ul>



<p>远程调用接口：</p>



<pre class="wp-block-code"><code>@FeignClient("user-service") //服务名称 调用外部API：@FeignClient(value = "服务名称-client",url = "服务地址")
public interface UserClient {
​
 &nbsp; &nbsp;@GetMapping("/users") //请求方式+请求路径
 &nbsp; &nbsp;List&lt;UserTO&gt; queryUserByIds(@RequestParam("ids") Collection&lt;Long&gt; ids); //返回值类型+请求参数
}</code></pre>



<p>参数说明：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>参数</th><th>说明</th></tr></thead><tbody><tr><td>@FeignClient(&#8220;user-service&#8221;)</td><td>声明服务名称</td></tr><tr><td>@GetMapping</td><td>声明请求方式</td></tr><tr><td>@GetMapping(&#8220;/users&#8221;)</td><td>声明请求路径</td></tr><tr><td>@RequestParam(&#8220;ids&#8221;) Collection&lt;Long&gt; ids</td><td>声明请求参数</td></tr><tr><td>List&lt;UserDTO&gt;</td><td>返回值类型</td></tr></tbody></table></figure>



<p>有了上述信息，OpenFeign就可以利用动态代理帮我们实现这个方法，并且向<code>http://chang-service/user</code>发送一个<code>GET</code>请求，携带ids为请求参数，并自动将返回值处理为<code>List&lt;UserDTO&gt;</code></p>



<p>我们只需要在serviceImpl层中直接调用这个方法，即可实现远程调用了</p>



<h1 class="wp-block-heading">抽取client模块：</h1>



<p>可以创建新的api模块用来统一存储client远程请求代码，在有需要的模块中通过依赖注入</p>



<p>依赖:</p>



<pre class="wp-block-code"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0"
 &nbsp; &nbsp; &nbsp; &nbsp; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 &nbsp; &nbsp; &nbsp; &nbsp; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
 &nbsp; &nbsp;&lt;parent&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;artifactId&gt;CHANG&lt;/artifactId&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;groupId&gt;com.chang&lt;/groupId&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;version&gt;1.0.0&lt;/version&gt;
 &nbsp; &nbsp;&lt;/parent&gt;
 &nbsp; &nbsp;&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
​
 &nbsp; &nbsp;&lt;artifactId&gt;hm-api&lt;/artifactId&gt;
​
 &nbsp; &nbsp;&lt;properties&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;
 &nbsp; &nbsp;&lt;/properties&gt;
​
 &nbsp; &nbsp;&lt;dependencies&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;!--open feign--&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;dependency&gt;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-openfeign&lt;/artifactId&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;/dependency&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;!-- load balancer--&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;dependency&gt;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-loadbalancer&lt;/artifactId&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;/dependency&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;!-- swagger 注解依赖 --&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;dependency&gt;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;groupId&gt;io.swagger&lt;/groupId&gt;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;artifactId&gt;swagger-annotations&lt;/artifactId&gt;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;version&gt;1.6.6&lt;/version&gt;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;scope&gt;compile&lt;/scope&gt;
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;/dependency&gt;
 &nbsp; &nbsp;&lt;/dependencies&gt;
&lt;/project&gt;</code></pre>



<h1 class="wp-block-heading">连接池配置:</h1>



<p>依赖:</p>



<pre class="wp-block-code"><code>&lt;!--OK http 的依赖 --&gt;
&lt;dependency&gt;
 &nbsp;&lt;groupId&gt;io.github.openfeign&lt;/groupId&gt;
 &nbsp;&lt;artifactId&gt;feign-okhttp&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>



<p>配置：</p>



<pre class="wp-block-code"><code>feign:
  okhttp:
 &nbsp;  enabled: true # 开启OKHttp功能</code></pre>



<h1 class="wp-block-heading">日志配置：</h1>



<p>配置：</p>



<pre class="wp-block-code"><code>logging:
  level:
 &nbsp;  com.chang.user.feign: debug #选择需要生成日志的项目路径</code></pre>



<p>配置类：</p>



<pre class="wp-block-code"><code>public class UserConfig {
 &nbsp; &nbsp;@Bean
 &nbsp; &nbsp;public Logger.Level feignLogLevel(){
 &nbsp; &nbsp; &nbsp; &nbsp;return Logger.Level.FULL;
 &nbsp;  }
}</code></pre>



<p>OpenFeign只会在FeignClient所在包的日志级别为<strong>DEBUG</strong>时，才会输出日志。其日志级别有4级,默认的日志级别是NONE。</p>



<p>日志级别：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>级别</th><th>说明</th></tr></thead><tbody><tr><td>NONE</td><td>不记录任何日志信息，这是默认值</td></tr><tr><td>BASIC</td><td>仅记录请求的方法，URL以及响应状态码和执行时间</td></tr><tr><td>HEADERS</td><td>在BASIC的基础上，额外记录了请求和响应的头信息</td></tr><tr><td>FULL</td><td>记录所有请求和响应的明细，包括头信息、请求体、元数据</td></tr></tbody></table></figure>



<h1 class="wp-block-heading">超时配置：</h1>



<p>配置：</p>



<pre class="wp-block-code"><code>spring:
  profiles:
 &nbsp;  include: feign #启用feign配置</code></pre>



<p>application-feign.yaml配置：</p>



<pre class="wp-block-code"><code>spring:
  cloud:
 &nbsp;  openfeign:
 &nbsp; &nbsp;  client:
 &nbsp; &nbsp; &nbsp;  config:
 &nbsp; &nbsp; &nbsp; &nbsp;  default:
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  logger-level: full
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  connect-timeout: 1000
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  read-timeout: 2000
 &nbsp; &nbsp; &nbsp; &nbsp;  product-service:
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  logger-level: full
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  connect-timeout: 3000
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  read-timeout: 5000
# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  request-interceptors:
# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  - com.chang.order.interceptor.XTokenRequestInterceptor #对对应路径下的服务开启拦截器</code></pre>



<h1 class="wp-block-heading">重试机制：</h1>



<p>配置类：</p>



<pre class="wp-block-code"><code>@Bean //重试器
Retryer retryer(){
 &nbsp; &nbsp;return new Retryer.Default();
}</code></pre>



<h1 class="wp-block-heading">拦截器：</h1>



<p>拦截器：</p>



<pre class="wp-block-code"><code>@Component //注入容器为开启全局拦截 单一配置请看feign配置文件
public class XTokenRequestInterceptor implements RequestInterceptor {
​
​
    /**
     * 请求拦截器
     * @param template 请求模版
     */
    @Override
    public void apply(RequestTemplate template) {
        System.out.println("XTokenRequestInterceptor......");
        template.header("X-token", UUID.randomUUID().toString());
   }
}</code></pre>



<h1 class="wp-block-heading">Fallback调用兜底：</h1>



<p>依赖：</p>



<pre class="wp-block-code"><code>&lt;!--sentinel 服务保护--&gt;
&lt;dependency&gt;
 &nbsp; &nbsp;&lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt; 
 &nbsp; &nbsp;&lt;artifactId&gt;spring-cloud-starter-alibaba-sentinel&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>



<p>application-feign.yaml配置：</p>



<pre class="wp-block-code"><code>feign:
  sentinel:
 &nbsp;  enabled: true #开启服务保护</code></pre>



<p>远程调用类：</p>



<pre class="wp-block-code"><code>@FeignClient(value = "product-service",fallback = ProductFeignClientFallback.class) //fallbacke指定回调类
public interface ProductFeignClient {
​
 &nbsp; &nbsp;//mvc注解的两套使用逻辑
 &nbsp; &nbsp;//1.标注在Controller上，是接受这样的请求
 &nbsp; &nbsp;//2.标注在FeignClient上，是发送这样的请求
 &nbsp; &nbsp;@GetMapping("/product/{id}")
 &nbsp; &nbsp;Product getProduct(@PathVariable("id") Long id);
​
}</code></pre>



<p>回调类：</p>



<pre class="wp-block-code"><code>@Component
public class ProductFeignClientFallback implements ProductFeignClient {
 &nbsp; &nbsp;@Override
 &nbsp; &nbsp;public Product getProduct(Long id) {
 &nbsp; &nbsp; &nbsp; &nbsp;System.out.println("兜底回调...");
 &nbsp; &nbsp; &nbsp; &nbsp;Product product = new Product();
 &nbsp; &nbsp; &nbsp; &nbsp;product.setId(id);
 &nbsp; &nbsp; &nbsp; &nbsp;product.setPrice(new BigDecimal("0"));
 &nbsp; &nbsp; &nbsp; &nbsp;product.setProductName("位置商品");
 &nbsp; &nbsp; &nbsp; &nbsp;product.setNum(0);
​
 &nbsp; &nbsp; &nbsp; &nbsp;return product;
 &nbsp;  }
}</code></pre>



<h1 class="wp-block-heading">在微服务之间传递用户信息：</h1>



<ul class="wp-block-list">
<li>存在api服务中</li>
</ul>



<p>配置类：</p>



<pre class="wp-block-code"><code>public class DefaultFeignConfig {
​
 &nbsp; &nbsp;@Bean
 &nbsp; &nbsp;public RequestInterceptor userInfoRequestInterceptor(){
 &nbsp; &nbsp; &nbsp; &nbsp;return new RequestInterceptor() {
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Override
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public void apply(RequestTemplate template) {
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 获取登录用户
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Long userId = UserContext.getUser();
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(userId == null) {
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果为空则直接跳过
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 如果不为空则放入请求头中，传递给下游微服务
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;template.header("user-info", userId.toString());
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }
 &nbsp; &nbsp; &nbsp;  };
 &nbsp;  }
​
 &nbsp; &nbsp;@Bean
 &nbsp; &nbsp;public UserClientFallbackFactory ClientFallbackFactory(){
 &nbsp; &nbsp; &nbsp; &nbsp;return new UserClientFallbackFactory();
 &nbsp;  }
}</code></pre>



<p><a href="#top">返回顶部</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.qiqin-chang.cn/openfeign-%e8%bf%9c%e7%a8%8b%e8%b0%83%e7%94%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>密码保护：gateway-网关</title>
		<link>https://www.qiqin-chang.cn/gateway-%e7%bd%91%e5%85%b3/</link>
					<comments>https://www.qiqin-chang.cn/gateway-%e7%bd%91%e5%85%b3/#respond</comments>
		
		<dc:creator><![CDATA[乐章]]></dc:creator>
		<pubDate>Thu, 10 Apr 2025 01:05:09 +0000</pubDate>
				<category><![CDATA[微服务]]></category>
		<guid isPermaLink="false">http://8.153.197.211/?p=141</guid>

					<description><![CDATA[无法提供摘要。这是一篇受保护的文章。]]></description>
										<content:encoded><![CDATA[<form action="https://www.qiqin-chang.cn/znyz" class="post-password-form" method="post"><input type="hidden" name="redirect_to" value="https://www.qiqin-chang.cn/gateway-%e7%bd%91%e5%85%b3/" /></p>
<p>此内容受密码保护。如需查阅，请在下方输入密码。</p>
<p><label for="pwbox-141">密码： <input name="post_password" id="pwbox-141" type="password" spellcheck="false" required size="20" /></label> <input type="submit" name="Submit" value="提交" /></p>
</form>
]]></content:encoded>
					
					<wfw:commentRss>https://www.qiqin-chang.cn/gateway-%e7%bd%91%e5%85%b3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>docker-容器引擎</title>
		<link>https://www.qiqin-chang.cn/docker-%e5%ae%b9%e5%99%a8%e5%bc%95%e6%93%8e/</link>
					<comments>https://www.qiqin-chang.cn/docker-%e5%ae%b9%e5%99%a8%e5%bc%95%e6%93%8e/#respond</comments>
		
		<dc:creator><![CDATA[乐章]]></dc:creator>
		<pubDate>Thu, 10 Apr 2025 01:02:56 +0000</pubDate>
				<category><![CDATA[微服务]]></category>
		<guid isPermaLink="false">http://8.153.197.211/?p=139</guid>

					<description><![CDATA[安装及配置： 镜像库地址：https://hub.docker.com/ 官方文档：https://docs. [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">安装及配置：</h1>



<p>镜像库地址：<a href="https://hub.docker.com/">https://hub.docker.com/</a></p>



<p>官方文档：<a href="https://docs.docker.com/">https://docs.docker.com/</a></p>



<p>1.卸载旧版本</p>



<pre class="wp-block-code"><code>yum remove docker \
  docker-client \
  docker-client-latest \
  docker-common \
  docker-latest \
  docker-latest-logrotate \
  docker-logrotate \
  docker-engine</code></pre>



<p>2.配置阿里云yum源</p>



<pre class="wp-block-code"><code>yum repolist #检查yum源</code></pre>



<p>3.7版本CentOS已经停止维护了</p>



<pre class="wp-block-code"><code>bash &lt;(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)</code></pre>



<p>4.安装必要的一些系统工具</p>



<pre class="wp-block-code"><code>sudo yum install -y yum-utils device-mapper-persistent-data lvm2</code></pre>



<p>5.添加软件源信息（会在 /etc/yum.repos.d/ 目录下看到 docker-ce.repo 文件）</p>



<pre class="wp-block-code"><code>sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</code></pre>



<p>6.安装docker</p>



<pre class="wp-block-code"><code>yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin<br><br></code></pre>



<p>7.启动和校验</p>



<pre class="wp-block-code"><code>\# 获取Docker版本
docker -v
​
\# 启动Docker
systemctl start docker
​
\# 停止Docker
systemctl stop docker
​
\# 重启
systemctl restart docker
​
\# 设置开机自启
systemctl enable docker
​
\# 执行docker ps命令，如果不报错，说明安装启动成功
docker ps</code></pre>



<p>8.CentOS配置镜像加速</p>



<p>获取镜像加速地址：在阿里云服务中搜索容器镜像服务-点击镜像工具-点击镜像加速器( 旁边有centOS7的docker安装教程)</p>



<p><strong>阿里云镜像更新慢建议别用</strong></p>



<pre class="wp-block-code"><code>sudo mkdir -p /etc/docker
​
sudo tee /etc/docker/daemon.json &lt;&lt;-'EOF'
{
"registry-mirrors": &#91;
"https://docker.nju.edu.cn",
"https://hub.littlediary.cn",
"https://hub.xdark.top",
"https://dockerpull.org",
"https://hub.crdz.gq",
"https://docker.1panel.live",
"https://docker.unsee.tech"
]
}
EOF
​
sudo systemctl daemon-reload
​
sudo systemctl restart docker
</code></pre>



<h1 class="wp-block-heading">基本操作：</h1>



<h2 class="wp-block-heading">常见命令：</h2>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th><strong>命令</strong></th><th><strong>说明</strong></th></tr></thead><tbody><tr><td>docker pull</td><td>拉取镜像</td></tr><tr><td>docker push</td><td>推送镜像到DockerRegistry</td></tr><tr><td>docker images</td><td>查看本地镜像</td></tr><tr><td>docker rmi</td><td>删除本地镜像</td></tr><tr><td>docker run</td><td>创建并运行容器（不能重复创建）</td></tr><tr><td>docker stop</td><td>停止指定容器</td></tr><tr><td>docker start</td><td>启动指定容器</td></tr><tr><td>docker restart</td><td>重新启动容器</td></tr><tr><td>docker rm</td><td>删除指定容器</td></tr><tr><td>docker ps</td><td>查看容器</td></tr><tr><td>docker logs</td><td>查看容器运行日志</td></tr><tr><td>docker exec</td><td>进入容器 -it (添加可输入终端)</td></tr><tr><td>docker save</td><td>保存镜像到本地压缩文件</td></tr><tr><td>docker load</td><td>加载本地压缩文件到镜像 -i (加载镜像)</td></tr><tr><td>docker inspect</td><td>查看容器详细信息</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">docker流程图：</h2>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="478" src="https://www.qiqin-chang.cn/wp-content/uploads/2025/04/docker-流程图-1024x478.png" alt="" class="wp-image-419" srcset="https://www.qiqin-chang.cn/wp-content/uploads/2025/04/docker-流程图-1024x478.png 1024w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/docker-流程图-300x140.png 300w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/docker-流程图-768x359.png 768w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/docker-流程图-1536x718.png 1536w, https://www.qiqin-chang.cn/wp-content/uploads/2025/04/docker-流程图-2048x957.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">docker run 命令的常见参数：</h2>



<pre class="wp-block-preformatted">-d:让容器后台运行<br><br>--name；容器名<br><br>-e:环境变量<br><br>-p:宿主机端口映射到容器内端口<br><br>--env MODE=standalone 参数设置  单机版（开发时使用）<br><br>--restart=always 设置开机启动</pre>



<h2 class="wp-block-heading">镜像名称结构：</h2>



<pre class="wp-block-preformatted">Repository:TAG<br><br>镜像名：版本号</pre>



<h2 class="wp-block-heading">设置容器别名：</h2>



<pre class="wp-block-code"><code>vi ~/.bashrc # 编辑文件别名

# 按i进入编辑模式
# 按ESC进入命令模式
# 按:wq保存并退出

source ~/.bashrc # 保存文件别名</code></pre>



<h2 class="wp-block-heading">修改内容：</h2>



<pre class="wp-block-code"><code># 修改/root/.bashrc文件
vi /root/.bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias dps='docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Ports}}\t{{.Status}}\t{{.Names}}"'
alias dis='docker images'

# Source global definitions
if &#91; -f /etc/bashrc ]; then
        . /etc/bashrc
fi</code></pre>



<h1 class="wp-block-heading">数据卷：</h1>



<p>如何挂载数据卷：</p>



<p>在创建容器时，利用 -v 数据卷名：容器内目录 完成挂载</p>



<p>容器创建时，如果挂载的数据卷不存在则会自动创建</p>



<pre class="wp-block-preformatted"># 挂载本地目录<br>-v 本地目录:容器内目录<br># 挂载本地文件<br>-v 本地文件:容器内文件</pre>



<p>注意：本地目录或文件必须以 / 或 ./开头，如果直接以名字开头，会被识别为数据卷名而非本地目录名。</p>



<p>数据卷命令：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th><strong>命令</strong></th><th><strong>说明</strong></th></tr></thead><tbody><tr><td>docker volume ls</td><td>查看所有数据卷</td></tr><tr><td>docker volume rm</td><td>删除指定数据卷</td></tr><tr><td>docker volume inspect</td><td>查看数据卷的详情</td></tr><tr><td>docker volume prune</td><td>删除所有未使用的数据卷</td></tr></tbody></table></figure>



<h1 class="wp-block-heading">网络：</h1>



<p>网络命令：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th><strong>命令</strong></th><th><strong>说明</strong></th></tr></thead><tbody><tr><td>docker network create</td><td>创建一个网络</td></tr><tr><td>docker network ls</td><td>查看所有网络</td></tr><tr><td>docker network rm</td><td>删除指定网络</td></tr><tr><td>docker network prune</td><td>清除未使用的网络</td></tr><tr><td>docker network connect</td><td>使指定容器连接加入某网络</td></tr><tr><td>docker network disconnect</td><td>使指定容器连接离开某网络</td></tr><tr><td>docker network inspect</td><td>查看网络详细信息</td></tr></tbody></table></figure>



<p><a href="#top">返回顶部</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.qiqin-chang.cn/docker-%e5%ae%b9%e5%99%a8%e5%bc%95%e6%93%8e/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
