微服务是一种软件开发架构风格,它将一个应用程序拆分成一组小型、独立的服务,每个服务都可以独立部署、管理和扩展。每个服务都可以通过轻量级的通信机制(通常是 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工具查看已经注册成功
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
消费者启动不了
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®istry=zookeeper×tamp=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×tamp=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网卡后重启正常
chatgpt 方法
根据错误信息,导致这个异常的原因是服务中心中没有可用的提供者(provider)来提供名为 "com.alibaba.dubbo.demo.DemoService" 的服务。下面是一些可能的原因:
1. 服务提供者没有正确启动或注册到服务中心。
2. 服务中心(zookeeper)的地址或配置不正确,导致注册失败。
3. 消费者端的网络连接问题,无法和服务中心进行通信。
4. 消费者端的版本不匹配,可能与服务端版本不兼容。
要解决这个问题,你可以尝试以下步骤:
1. 检查服务提供者是否已经正确启动,并确保它已经成功注册到服务中心。
2. 检查服务中心的地址和配置是否正确,确保消费者能够正确连接到服务中心。
3. 检查网络连接是否正常,确保消费者和服务中心之间能够相互通信。
4. 确保消费者端使用的 Dubbo 版本与提供者端一致,或者尝试更新消费者端的版本以解决兼容性问题。
如果问题仍然存在,请根据具体情况进行进一步的调试和排查。
再启动一个生产者
消费者会轮询调用生产者,
生产者挂了,会取消调用挂了的生产者
dubboadmin
机器 192.168.74.68
下载上传tomcat
root@ubuntu20:/apps# tar -xf apache-tomcat-9.0.59.tar.gz
root@ubuntu20:/apps# ls
进入webapps目录
root@ubuntu20:/apps/apache-tomcat-9.0.59/webapps#
上传dubboadmin.war解压
mv /apps/dubboadmin.war .
root@ubuntu20:/apps/apache-tomcat-9.0.59/webapps# unzip dubboadmin.war
修改配置添加zk集群地址
cat /apps/apache-tomcat-9.0.59/webapps/dubboadmin/WEB-INF/dubbo.properties
dubbo.registry.address=zookeeper://192.168.74.70:2181| zookeeper://192.168.74.71:2181 | zookeeper://192.168.74.72:2181
dubbo.admin.root.password=root #登录用户和密码均为root
dubbo.admin.guest.password=guest
启动
root@node4:/apps/apache-tomcat-9.0.59# ./bin/catalina.sh start
java
专栏收录该内容
18 篇文章0 订阅
订阅专栏
dubbo-admin访问报404的错误主要有三方面:
1、zookeeper,没有提前启动;
2、防火墙没有关闭;
3、jdk版本过高,dubbo-admin不匹配;
这里主要针对第三个(版本不匹配进行讲解)进行讲解:
前提条件:1、zookeeper安装完毕;2、jdk8安装完毕;3、Tomcat安装完毕;4、maven安装完毕;参考: https://blog.csdn.net/weixin_38313970/article/details/89814286/
我这里dubbo版本2.1.5,排查后是jdk版本过高,
apt autoremove openjdk-11-jdk
apt install openjdk-8-jdk
路径问题,加dubboadmin
微服务编译
机器 192.168.74.69
#Github 地址:
https://github.com/apache/dubbo-admin/blob/develop/README_ZH.md
如果遇到了网络问题,可以设置npm代理镜像来加速npm install的过程:
在~/.npmrc中增加 registry=https://registry.npmmirror.com
root@node6:~# cat .npmrc
registry=https://registry.npmmirror.com
下载代码
root@node6:~# apt install git
git clone https://github.com/apache/dubbo-admin.git
- 在 dubbo-admin-server/src/main/resources/application.properties中指定注册中心地址,我这里写一个地址
root@node6:~/dubbo-admin# vim dubbo-admin-server/src/main/resources/application.properties
admin.registry.address=zookeeper://192.168.71.70:2181
admin.config-center=zookeeper://192.168.74.71:2181
admin.metadata-report.address=zookeeper://192.168.74.71:2181
3.安装maven 编译
apt install maven -y
root@server02:~# mvn -v
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.20, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-73-generic", arch: "amd64", family: "unix"
mvn clean package -Dmaven.test.skip=true
怎么区分环境
sed
配置文件地址写好
目前的java服务,大部分是通过maven编译
1.16C32G 配置jdk环境
2.安装maven
3.结合jenkins编译
4. 将编译好的jar包进行代码部署(target目录下),k8s环境要重新打镜像
nexus
wget https://download.sonatype.com/nexus/3/nexus-3.59.0-01-unix.tar.gz
root@server02:/apps# ln -sf /apps/nexus-3.59.0-01 /apps/nexus