diff --git a/images/distributeimg_1.png b/images/distributeimg_1.png new file mode 100644 index 000000000..212cfcd9c Binary files /dev/null and b/images/distributeimg_1.png differ diff --git a/images/distributeimg_2.png b/images/distributeimg_2.png new file mode 100644 index 000000000..ce81095dc Binary files /dev/null and b/images/distributeimg_2.png differ diff --git a/images/distributeimg_3.png b/images/distributeimg_3.png new file mode 100644 index 000000000..10d65293c Binary files /dev/null and b/images/distributeimg_3.png differ diff --git a/images/distributeimg_4.png b/images/distributeimg_4.png new file mode 100644 index 000000000..f1a88c94f Binary files /dev/null and b/images/distributeimg_4.png differ diff --git a/redkale.html b/redkale.html index c01473491..af9efeb0b 100644 --- a/redkale.html +++ b/redkale.html @@ -62,6 +62,111 @@             6、启动进程本身的监听服务。

+

RedKale 集中式与分布式

+

      通常一个系统会分为三层:接入层、业务层、数据层。对应到RedKale的组件是: Servlet、Service、Source。大部分系统提供的是HTTP服务,为了方便演示RedKale从集中式到分布式的变化,以一个简单的HTTP服务作为范例。
+       假设一个极简单的公司内部论坛系统包含三个模块:
+             用户模块    UserSerivice:     提供用户注册、登录、更新资料等功能, UserServlet作为接入层。
+             帖子模块 ForumSerivice:     提供看帖、发帖、删帖等功能, ForumServlet作为接入层。
+             通知模块  NotifySerivice:     提供用户操作、回帖等消息通知功能, NotifyWebSocket是WebSocket的Servlet,作为接入层。
+

+
+

      1、单点部署

+

      在早期用户量很少或者开发、调试环境中只需部署一个进程就可满足需求。

+

+

      如上图,所有模块的HttpServlet、Service与Source数据库操作全部署在一起。 application.xml作简单的配置即可:

+
<application port="5050">   
+    
+    <server protocol="HTTP" port="6060" root="root"> 
+        <services autoload="true" />  
+        <servlets autoload="true"/>
+    </server> 
+    	
+</application>
+                
+
+ +

      2、多点部署

+

      在生产环境需要避免单点问题,一个服务一般会部署多套。在此做个简单的容灾部署,最前端部署一个nginx作反向代理和负载均衡服务器,后面部署两套系统。

+

+

      如上图,两个进程间的Serivce都是本地模式,两者会通过SNCP服务保持数据同步,若DataSource开启了数据缓存也会自动同步。两套的配置文件相同,配置如下:

+
+<application port="5050">   
+
+    <resources>	
+        <group name="ALL">
+            <node addr="192.168.50.110" port="7070"/>
+            <node addr="192.168.50.120" port="7070"/>
+        </group>
+    </resources>
+
+    <!-- HTTP 监听 Server -->
+    <server protocol="HTTP" port="6060" root="root"> 
+        <!-- 前端配置了nginx,需要配置才能获取客户端真实的IP地址 -->
+        <request>
+            <remoteaddr value="request.headers.X-RemoteAddress"/>
+        </request>
+        <services autoload="true" groups="ALL"/>	
+        <servlets autoload="true" />
+    </server> 
+
+    <!-- SNCP 监听 Server -->
+    <server protocol="SNCP" port="7070"> 
+        <services autoload="true"  groups="ALL"/>
+    </server>
+	
+</application>
+
+ +

      3、分层部署

+

      随着业务的复杂度增加,接入层与业务层混在一起会越来越难部署和维护,因此需要进行分层部署。

+

+

      如上图,对HttpServlet与Service进行了分离。每个接入层的Service都是远程模式,业务层只需提供SNCP供远程调用。

+

      接入层中每个进程的配置相同,配置如下:

+
<application port="5050">   
+
+    <resources>	
+        <group name="ALL">
+            <node addr="192.168.50.110" port="7070"/>
+            <node addr="192.168.50.120" port="7070"/>
+        </group>
+    </resources>
+
+    <!-- HTTP 监听 Server -->
+    <server protocol="HTTP" port="6060" root="root"> 
+        <!-- 前端配置了nginx,需要配置才能获取客户端真实的IP地址 -->
+        <request>
+            <remoteaddr value="request.headers.X-RemoteAddress"/>
+        </request>
+        <services autoload="true" groups="ALL"/>	
+        <servlets autoload="true" />
+    </server> 
+	
+</application>
+                
+

      业务层中每个进程的配置相同,置如下:

+
<application port="5050">   
+
+    <resources>	
+        <group name="ALL">
+            <node addr="192.168.50.110" port="7070"/>
+            <node addr="192.168.50.120" port="7070"/>
+        </group>
+    </resources>
+
+    <!-- SNCP 监听 Server -->
+    <server protocol="SNCP" port="7070"> 
+        <services autoload="true"  groups="ALL"/>
+    </server>
+	
+</application>
+                
+
+ +

      4、微服务部署

+

      在生产环境需要避免单点问题,一个服务一般会部署多套。在此做个简单的容灾部署,最前端部署一个nginx作反向代理和负载均衡服务器,后面部署两套系统。

+

+ +

appplication.xml 配置说明

<?xml version="1.0" encoding="UTF-8"?>
 <!--