7-7 关于 docker run -it web:v1 调7-6的dubbo服务失败
来源:7-7 传统web服务迁移kubernetes
yl_testimooc3804939
2022-11-12
在7-6中,生成到node-3的dubbo服务正常,在node-1的ZK也能注册,dubbo服务也能测试。
[root@node-1 configs]# cat dubbo.yaml
hostNetwork: true
nodeName: node-3
ports:
- containerPort: 20881
env:
- name: DUBBO_PORT
value: "20881"
[root@node-1 configs]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
dubbo-demo-5fb89b885d-lwv2l 1/1 Running 0 3s 172.16.1.23
[root@node-3 harbor]# crictl ps
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID
7ba8f3af36475 a5878a1e012c5 7 seconds ago Running dubbo-demo 0 85d4ecd045c17
#查看部署节点端口
[root@node-3 harbor]# netstat -lntup|grep 20881
tcp 0 0 0.0.0.0:20881 0.0.0.0:* LISTEN 92021/java
#测试dubbo
[root@node-2 ~]# telnet 172.16.1.23 20881
Trying 172.16.1.23...
Connected to 172.16.1.23.
Escape character is '^]'.
dubbo>ls
com.mooc.demo.api.DemoService
dubbo>ls com.mooc.demo.api.DemoService
sayHello
dubbo>invoke com.mooc.demo.api.DemoService.sayHello("xxx")
"Hello xxx"
elapsed: 4 ms.
dubbo>exit
Connection closed by foreign host.
[root@node-1 zookeeper]# docker run --name zookeeper -p 2181:2181 --restart always -d hub.mooc.com/zookeeper/zookeeper:3.4.10
此时,我要通过7-7的web项目调取7-6的服务失败。
执行操作如下:
[root@node-1 web-demo]# cat start.sh
#!/bin/bash
sh /usr/local/tomcat/bin/startup.sh
tail -f /usr/local/tomcat/logs/catalina.out
[root@node-1 web-demo]# chmod +x start.sh
[root@node-1 web-demo]# ll start.sh
-rwxr-xr-x 1 root root 92 Nov 12 05:33 start.sh
[root@node-1 web-demo]# cat Dockerfile
FROM hub.mooc.com/kubernetes/tomcat:8.0.51-alpine
COPY ROOT /usr/local/tomcat/webapps/ROOT
COPY start.sh /usr/local/tomcat/bin/start.sh
ENTRYPOINT ["sh" , "/usr/local/tomcat/bin/start.sh"]
[root@node-1 web-demo]# docker build -t web:v1 .
[root@node-1 web-demo]# docker run -it web:v1
执行上述docker run抛出的异常结果:
[2022-11-11 22:50:49.814] {ERROR} com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry 146 -
[DUBBO] Failed to register consumer://172.17.0.3/com.mooc.demo.api.DemoService?application=demo&category=consumers&check=false&default.retries=3&default.timeout=60000&dubbo=2.6.2&interface=com.mooc.demo.api.DemoService&methods=sayHello&pid=14&revision=1.0-SNAPSHOT&side=consumer×tamp=1668207005427, waiting for retry, cause:
Failed to register consumer://172.17.0.3/com.mooc.demo.api.DemoService?application=demo&category=consumers&check=false&default.retries=3&default.timeout=60000&dubbo=2.6.2&interface=com.mooc.demo.api.DemoService&methods=sayHello&pid=14&revision=1.0-SNAPSHOT&side=consumer×tamp=1668207005427 to zookeeper
zookeeper://172.16.1.23:2181/com.alibaba.dubbo.registry.RegistryService?application=demo&dubbo=2.6.2&interface=com.alibaba.dubbo.registry.RegistryService&pid=14×tamp=1668207005494, cause: KeeperErrorCode = ConnectionLoss, dubbo version: 2.6.2,
current host: 172.17.0.3
com.alibaba.dubbo.rpc.RpcException: Failed to register
consumer://172.17.0.3/com.mooc.demo.api.DemoService?application=demo&category=consumers&check=false&default.retries=3&default.timeout=60000&dubbo=2.6.2&interface=com.mooc.demo.api.DemoService&methods=sayHello&pid=14&revision=1.0-SNAPSHOT&side=consumer×tamp=1668207005427 to zookeeper
zookeeper://172.16.1.23:2181/com.alibaba.dubbo.registry.RegistryService?application=demo&dubbo=2.6.2&interface=com.alibaba.dubbo.registry.RegistryService&pid=14×tamp=1668207005494, cause: KeeperErrorCode = ConnectionLoss
node-1的IP为172.16.1.21
node-3的IP为172.16.1.23
是互通的。
但是在tomcat内部运行的话,我如何连接到docker运行的ZK服务,并让7-7的web服务能调通7-6的dubbo服务?
我发现日志中的172.17.0.3是进入tomcat的bash环境读取来的。
[root@node-1 zookeeper]# docker run -it --entrypoint bash hub.mooc.com/kubernetes/tomcat:8.0.51-alpine
bash-4.4# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
57: eth0@if58: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
写回答
1回答
-
刘果国
2022-11-12
这个不是环境问题,是dubbo服务向zk注册服务时的ip不正确导致的。让dubbo把hostip注册进去就好。可以以host网络模式运行dubbo服务
032022-11-13
相似问题