@@ -94,8 +94,115 @@ Master节点采用Raft算法保证多个Master节点数据一致性,Master节
9494
9595集群的读写请求可以直接发给Server,也可以发给Client使用RPC转发给Master节点,这些请求最终会通过Mstaer节点同步给所有Leader节点上。集群内的数据读写和复制采用TCP的8300端口完成。
9696
97-
98-
99-
100-
97+ ### Consul 安装部署
98+
99+ #### 下载与安装
100+ ``` perl
101+ / /下载二进制包与解压
102+ wget https://releases.hashicorp.com/consul/1.5.1/consul_1.5.1_linux_amd64.zip
103+ unzip consul_1.5.1_linux_amd64.zip -d /usr/local/bin
104+
105+ //修改变量环境信息
106+ vi /etc/profile
107+ export CONSUL_HOME=/usr/local/bin/consul
108+ export PATH=$PATH :CONSUL_HOME
109+
110+ // 使用环境变量配置生效
111+ source /etc/profile
112+
113+ / /测试
114+ consul --version
115+ ```
116+
117+ #### 启动配置参数说明
118+ | 参数名称 | 用途 |
119+ | ------------ | ------------ |
120+ | -server | 指定运行模式为服务器,每个Consul集群至少有1个Server,正常不超过5个 |
121+ | -client | 表示Consul指定客户端的IP地址,默认127.0.0.1 |
122+ | -bootstrap-expect | 预期服务器集群的数量 |
123+ | -data-dir | 存储数据目录,该目录的数据在重启Consul后依然生效,目录需要赋予Consul启动用户权限 |
124+ | -node | 当前服务器在集群中的名称,默认是服务器的名称 |
125+ | -ui | 启动当前服务器内部的WebUI服务器和控制台界面 |
126+ | -join | 指定当前服务器启动时,加入另一个代理服务器的地址 |
127+
128+ **演示服务器:10.211.55.6,10.211.55.7,10.211.55.8**
129+ ```perl
130+ //10.211.55.6
131+ consul agent -server -ui -bootstrap-expect=3 -data-dir=/data/consul -node=agent-1 -client=0.0.0.0 -bind =10.211.55.6 -datacenter=dc1
132+
133+ / /10.211.55.7
134+ consul agent -server -ui -bootstrap-expect=3 -data-dir=/data/consul -node=agent-2 -client=0.0.0.0 -bind =10.211.55.7 -datacenter=dc1 -join 10.211.55.6
135+
136+ / /10.211.55.8
137+ consul agent -server -ui -bootstrap-expect=3 -data-dir=/data/consul -node=agent-3 -client=0.0.0.0 -bind =10.211.55.8 -datacenter=dc1 -join 10.211.55.6
138+ ```
139+
140+ #### 查看控制台UI
141+ <img src =" https://ipman-blog-1304583208.cos.ap-nanjing.myqcloud.com/dubbo/1121609122338_.pic.jpg " width = " 800 " height = " 280 " alt =" 图片名称 " align =center />
142+
143+ ### Dubbo 集成Consul注册中心
144+ Dubbo在高版本中已扩展了对Consul的支持。
145+
146+ ** 1、添加Consul的API和Client依赖**
147+ ``` perl
148+ <dependency>
149+ <groupId>com.ecwid.consul</groupId>
150+ <artifactId>consul-api</artifactId>
151+ <version>1.4.5</version>
152+ </dependency>
153+
154+ <dependency>
155+ <groupId>com.orbitz.consul</groupId>
156+ <artifactId>consul-client</artifactId>
157+ <version>1.5.0</version>
158+ </dependency>
159+ ```
160+
161+ ** 2、通过HTTP API方式(端口8500)注册Dubbo Provider程序**
162+ ``` java
163+ < ? xml version= " 1.0" encoding= " UTF-8" ? >
164+
165+ < beans xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance"
166+ xmlns: dubbo= " http://dubbo.apache.org/schema/dubbo"
167+ xmlns= " http://www.springframework.org/schema/beans" xmlns: context= " http://www.springframework.org/schema/context"
168+ xsi: schemaLocation= " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
169+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" >
170+ < context: property- placeholder/ >
171+
172+ < dubbo: application name= " consul-provider-demo" / >
173+
174+ < dubbo: protocol name= " dubbo" host= " 10.211.55.2" / >
175+
176+ < dubbo: registry address= " consul://${consul.address:10.211.55.8}:8500" / >
177+ < ! -- < dubbo: registry address= " consul://${consul.address:10.211.55.6}:8500?backup=10.211.55.7:8500,10.211.55.8:8500" / > -- >
178+
179+ < bean id= " demoService" class= " com.ipman.dubbo.consul.sample.impl.DemoServiceImpl" / >
180+
181+ < dubbo: service interface= " com.ipman.dubbo.consul.sample.api.DemoService" ref= " demoService" / >
182+ < / beans>
183+ ```
184+
185+ ** 3、通过HTTP API方式(端口8500)注册Dubbo Consumer程序**
186+ ``` java
187+ < ? xml version= " 1.0" encoding= " UTF-8" ? >
188+ < beans xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance"
189+ xmlns: dubbo= " http://dubbo.apache.org/schema/dubbo"
190+ xmlns= " http://www.springframework.org/schema/beans" xmlns: context= " http://www.springframework.org/schema/context"
191+ xsi: schemaLocation= " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
192+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" >
193+ < context: property- placeholder/ >
194+
195+ < dubbo: application name= " consul-consumer-demo" / >
196+
197+ < dubbo: registry address= " consul://${consul.address:10.211.55.8}:8500" / >
198+ < ! -- < dubbo: registry address= " consul://${consul.address:10.211.55.6}:8500?backup=10.211.55.7:8500,10.211.55.8:8500" / > -- >
199+
200+ < dubbo: reference scope= " remote" id= " demoService" check= " true"
201+ interface= " com.ipman.dubbo.consul.sample.api.DemoService" / >
202+ < / beans>
203+ ```
204+
205+ ** 4、启动Dubbo程序进行测试,并在Consul控制台里查看效果**
206+
207+ <img src =" https://ipman-blog-1304583208.cos.ap-nanjing.myqcloud.com/dubbo/1131609123179_.pic.jpg " width = " 800 " height = " 360 " alt =" 图片名称 " align =center />
101208
0 commit comments