微服务dubbo

微服务是一种软件开发架构风格,它将一个应用程序拆分成一组小型、独立的服务,每个服务都可以独立部署、管理和扩展。每个服务都可以通过轻量级的通信机制(通常是 HTTP/REST 或消息队列)相互通信。微服务架构追求高内聚、低耦合,使开发团队能够更加灵活地开发、测试和部署独立的功能模块。

服务治理是指在微服务架构中,对服务的管理、监控、调度和协调的一系列实践和工具。它包括服务注册与发现、负载均衡、故障转移、容错处理等,以确保微服务架构能够弹性扩展、容错恢复、高可用性。服务治理可以通过使用服务注册中心、负载均衡器、断路器等技术来实现。它提供了一种集中管理和控制微服务的方式,使整个系统具备更好的弹性和高可用性。

环境
zk是之前的环境
192.168.74.70 zk
192.168.74.71 zk
192.168.74.72 zk
192.168.74.67 provider
192.168.74.66 consumer
安装java环境
apt install openjdk-11-jdk -y

先启动生产者

上传dubbo-demo-provider-2.1.5-assembly.tar.gz
解压移动
mv dubbo-demo-provider-2.1.5 /usr/local/dubbo-demo-provider

修改配置,添加zookeeper配置,注释multicast

/usr/local/dubbo-demo-provider-2.1.5/conf# vi dubbo.properties 
dubbo.container=log4j,spring
dubbo.application.name=demo-provider
dubbo.application.owner=
dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://192.168.74.70:2181 | zookeeper://192.168.74.71:2181 zookeeper://192.168.74.72:2181 
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
dubbo.monitor.protocol=registry
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
dubbo.log4j.file=logs/dubbo-demo-provider.log 
dubbo.log4j.level=WARN                                          

启动
root@node4:/usr/local/dubbo-demo-provider-2.1.5# ./bin/start.sh
查看日志

 cat logs/stdout.log 

[1.480s][warning][exceptions] Class com.alibaba.dubbo.common.URL in throws clause of method com.alibaba.dubbo.remoting.Server com.alibaba.dubbo.remoting.Transporter_Adpative.bind(com.alibaba.dubbo.common.URL, com.alibaba.dubbo.remoting.ChannelHandler) is not a subtype of class java.lang.Throwable
[2023-08-27 23:15:15] Dubbo service server started!

zk工具查看已经注册成功
微服务dubbo_第1张图片
zk就有了生产者地址

配置消费者

安装jdk
apt install openjdk-11-jdk
上传包并解压
tar -xf dubbo-demo-consumer-2.1.5-assembly.tar.gz -C /usr/local/

配置zookeeper地址

root@node3:~# vim /usr/local/dubbo-demo-provider/conf/dubbo.properties

dubbo.container=log4j,spring
dubbo.application.name=demo-consumer
dubbo.application.owner=
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://192.168.74.70:2181 | zookeeper://192.168.74.71:2181 | zookeeper://192.168.74.72:2181
#dubbo.registry.address=zookeeper://127.0.0.1:2181
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
dubbo.monitor.protocol=registry
dubbo.log4j.file=logs/dubbo-demo-consumer.log
dubbo.log4j.level=WARN

启动
root@node3:~/dubbo-demo-consumer-2.1.5# ./bin/start.sh

微服务dubbo_第2张图片

消费者启动不了

Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.alibaba.dubbo.demo.DemoService. No provider available for the service com.alibaba.dubbo.demo.DemoService from the url registry://192.168.74.72:2181/com.alibaba.dubbo.registry.RegistryService?application=demo-consumer&cluster=available&dubbo=2.1.5&pid=3467&refer=application%3Ddemo-consumer%26dubbo%3D2.1.5%26interface%3Dcom.alibaba.dubbo.demo.DemoService%26methods%3DsayHello%26monitor%3Ddubbo%253A%252F%252F192.168.74.72%253A2181%252Fcom.alibaba.dubbo.registry.RegistryService%253Fapplication%253Ddemo-consumer%2526dubbo%253D2.1.5%2526pid%253D3467%2526protocol%253Dregistry%2526refer%253Ddubbo%25253D2.1.5%252526interface%25253Dcom.alibaba.dubbo.monitor.MonitorService%252526pid%25253D3467%252526timestamp%25253D1693150000307%2526registry%253Dzookeeper%2526timestamp%253D1693150000302%26pid%3D3467%26revision%3D2.1.5%26timestamp%3D1693149990218&registry=zookeeper&timestamp=1693150000302 to the consumer 192.168.1.220 use dubbo version 2.1.
.2023-08-27 23:42:02,889 [main] ERROR com.alibaba.dubbo.remoting.transport.AbstractClient (AbstractClient.java:111) -  [DUBBO] Failed to start NettyClient node3/192.168.74.66 connect to the server /192.168.1.220:20880 (check == false, ignore and retry later!), cause: client(url: dubbo://192.168.1.220:20880/com.alibaba.dubbo.demo.DemoService?anyhost=true&application=demo-consumer&check=false&codec=dubbo&dubbo=2.1.5&heartbeat=60000&interface=com.alibaba.dubbo.demo.DemoService&loadbalance=roundrobin&methods=sayHello&monitor=dubbo%3A%2F%2F192.168.74.70%3A2181%2Fcom.alibaba.dubbo.registry.RegistryService%3Fapplication%3Ddemo-consumer%26dubbo%3D2.1.5%26pid%3D4732%26protocol%3Dregistry%26refer%3Ddubbo%253D2.1.5%2526interface%253Dcom.alibaba.dubbo.monitor.MonitorService%2526pid%253D4732%2526timestamp%253D1693150921489%26registry%3Dzookeeper%26timestamp%3D1693150921477&pid=4732&revision=2.1.5&timestamp=1693150921416) failed to connect to server /192.168.1.220:20880, error message is:connection timed out, dubbo version: 2.1.5, current host: 192.168.74.66

查看日志连不不上zk
首先telnet zk 地址发现能通
再次查看日志说在连接192.168.1.220 erro
因为配置了二个网卡 eth0 为192.168.1.0/24
eth1为192.168.74.0/24,zk和生产者都是74网段,但却走了eth0网卡,在消费者和生产者禁用eth0网卡后重启正常
微服务dubbo_第3张图片

chatgpt 方法
根据错误信息,导致这个异常的原因是服务中心中没有可用的提供者(provider)来提供名为 "com.alibaba.dubbo.demo.DemoService" 的服务。下面是一些可能的原因:

1. 服务提供者没有正确启动或注册到服务中心。
2. 服务中心(zookeeper)的地址或配置不正确,导致注册失败。
3. 消费者端的网络连接问题,无法和服务中心进行通信。
4. 消费者端的版本不匹配,可能与服务端版本不兼容。

要解决这个问题,你可以尝试以下步骤:

1. 检查服务提供者是否已经正确启动,并确保它已经成功注册到服务中心。
2. 检查服务中心的地址和配置是否正确,确保消费者能够正确连接到服务中心。
3. 检查网络连接是否正常,确保消费者和服务中心之间能够相互通信。
4. 确保消费者端使用的 Dubbo 版本与提供者端一致,或者尝试更新消费者端的版本以解决兼容性问题。

如果问题仍然存在,请根据具体情况进行进一步的调试和排查。

再启动一个生产者

消费者会轮询调用生产者,
生产者挂了,会取消调用挂了的生产者

你可能感兴趣的:(微服务,dubbo,架构)