<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>注册中心 on Leanku 的博客</title><link>https://www.leanku.com/tags/%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83/</link><description>Recent content in 注册中心 on Leanku 的博客</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Mon, 15 Sep 2025 20:46:01 +0800</lastBuildDate><atom:link href="https://www.leanku.com/tags/%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83/index.xml" rel="self" type="application/rss+xml"/><item><title>微服务治理-注册中心</title><link>https://www.leanku.com/post/microservice/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%B2%BB%E7%90%86-%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83/</link><pubDate>Mon, 15 Sep 2025 20:46:01 +0800</pubDate><guid>https://www.leanku.com/post/microservice/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%B2%BB%E7%90%86-%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83/</guid><description>&lt;h1 id="微服务治理-注册中心"&gt;微服务治理-注册中心&lt;/h1&gt;&#10;&lt;h2 id="一介绍"&gt;一、介绍&lt;/h2&gt;&#10;&lt;h3 id="11-什么是注册中心"&gt;1.1 什么是注册中心&lt;/h3&gt;&#10;&lt;p&gt;注册中心可以理解为：&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;整个微服务系统的“通讯录”或“服务目录”。&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p&gt;在单体应用中：&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;Web&#10; │&#10; ▼&#10;Controller&#10; │&#10; ▼&#10;Service&#10; │&#10; ▼&#10;Repository&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;所有模块都运行在同一个进程中，方法之间直接调用： $user = $this-&amp;gt;userService-&amp;gt;getUser($id);&lt;/p&gt;&#10;&lt;p&gt;开发者无需关心：&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;服务在哪里？&lt;/li&gt;&#10;&lt;li&gt;IP 是多少？&lt;/li&gt;&#10;&lt;li&gt;端口是多少？&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;因为它们都在同一个应用中。&lt;/p&gt;&#10;&lt;hr&gt;&#10;&lt;p&gt;而在微服务架构中：&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt; User Service&#10;&#10; 10.0.0.10&#10;&#10; │&#10;&#10;Order Service ---------------- Product Service&#10;&#10;10.0.0.11 10.0.0.12&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;现在 Order Service 想调用 User Service。&lt;/p&gt;&#10;&lt;p&gt;问题来了：Order Service 怎么知道 User Service 在哪里？&lt;/p&gt;&#10;&lt;p&gt;如果直接写 IP：虽然可以运行，但会产生很多问题。&lt;/p&gt;&#10;&lt;h3 id="12-为什么不能写死-ip"&gt;1.2 为什么不能写死 IP？&lt;/h3&gt;&#10;&lt;p&gt;假设：今天：User Service 10.0.0.10&lt;/p&gt;&#10;&lt;p&gt;后面因为扩容：User Service 10.0.0.20 或者增加服务器：10.0.0.xxx&lt;/p&gt;&#10;&lt;p&gt;那么：&lt;/p&gt;&#10;&lt;p&gt;所有调用 User Service 的项目：都要修改配置。&lt;/p&gt;&#10;&lt;p&gt;到底调用哪一个?&lt;/p&gt;&#10;&lt;p&gt;于是：&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;需要一个统一管理所有服务信息的地方。&lt;/strong&gt;&lt;/p&gt;</description></item></channel></rss>