Dubbo协议端口的介绍--记一次踩坑

Dubbo协议端口的介绍

dubbo框架一共支持9种协议。其中,默认的,也是最常用的,那就是dubbo协议。

既然是网络协议,那么,必然要有端口号。

所以,在使用dubbo协议暴露服务时,需要配置dubbo端口。

dubbo协议的默认端口是20880。

springboot配置:

dubbo:
  application:
    name: omsbase-provider
  registry:
    address: zookeeper://192.168.40.84:${embedded.zookeeper.port}
#    address: zookeeper://127.0.0.1:2181
  protocol:
    name: dubbo
    port: 20888

一个应用程序启动后,dubbo即开启端口侦听请求。

linux服务器上查看dubbo端口:

[root@chuxing-service ~]# netstat -tunpl|grep 20880
tcp6       0      0 :::20880                :::*                    LISTEN      16074/java          
[root@chuxing-service ~]# netstat -tunpl|grep 2088*
tcp6       0      0 :::20880                :::*                    LISTEN      16074/java          
tcp6       0      0 :::20881                :::*                    LISTEN      15588/java          
tcp6       0      0 :::20888                :::*                    LISTEN      6983/java

通过各个dubbo端口对应的pid,我们来看看相应的主进程应用:

[root@chuxing-service ~]# ps -ef|grep 16074
root     12630 11879  0 09:50 pts/1    00:00:00 grep --color=auto 16074
root     16074     1  0 Apr26 ?        00:04:31 java -Xms2g -Xmx4g -Djava.awt.headless=true -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -server -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=85 -Xnoclassgc -Xverify:none -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -jar /www/service/car-pub-server-provider/bin/../car-pub-server-provider.jar
[root@chuxing-service ~]# ps -ef|grep 15588
root     12666 11879  0 09:50 pts/1    00:00:00 grep --color=auto 15588
root     15588     1  0 Apr26 ?        00:03:44 java -Xms2g -Xmx4g -Djava.awt.headless=true -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -server -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=85 -Xnoclassgc -Xverify:none -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -jar /www/service/bosskg-server-provider/bin/../bosskg-server-provider.jar

netstat -apn/netstat -n

[root@chuxing-service ~]# netstat -apn |grep 20880
tcp6       0      0 :::20880                :::*                    LISTEN      16074/java          
tcp6       0      0 192.168.40.84:50120     192.168.40.84:20880     ESTABLISHED 10974/java          
tcp6       0      0 192.168.40.84:20880     192.168.40.84:36100     ESTABLISHED 16074/java          
tcp6       0      0 192.168.40.84:36104     192.168.40.84:20880     ESTABLISHED 6983/java           
tcp6       0      0 192.168.40.84:20880     192.168.40.84:50120     ESTABLISHED 16074/java          
tcp6       0      0 192.168.40.84:36100     192.168.40.84:20880     ESTABLISHED 7726/java           
tcp6       0      0 192.168.40.84:20880     192.168.40.84:36104     ESTABLISHED 16074/java          
[root@chuxing-service ~]# netstat -n |grep 20880
tcp6       0      0 192.168.40.84:50120     192.168.40.84:20880     ESTABLISHED
tcp6       0      0 192.168.40.84:20880     192.168.40.84:36100     ESTABLISHED
tcp6       0      0 192.168.40.84:36104     192.168.40.84:20880     ESTABLISHED
tcp6       0      0 192.168.40.84:20880     192.168.40.84:50120     ESTABLISHED
tcp6       0      0 192.168.40.84:36100     192.168.40.84:20880     ESTABLISHED
tcp6       0      0 192.168.40.84:20880     192.168.40.84:36104     ESTABLISHED

注意:因为端口不能重复,所以,当一台服务器上同时存在多个应用要暴露dubbo服务时,需要指定不同的协议端口。否则的话,程序起不来。但进程能起来,这次记录这边日志的原因就是虽然端口占用了,但是dubbo程序进程还能起来。

如果启动日志量大的时候可能没观察到对应的报错,此时一定要注意看下对应的java进程是否有相同的服务名,如果有kill掉在重新发布自己的程序即可

我们可以这样模拟:一个使用了dubbo提供服务的应用程序,本地将其启动。此时,指定的端口将被占用。如果我们再运行一个testcase方法时,就会发现启动失败,提示指定的dubbo端口已经被占用。异常信息:

2020-04-24 16:26:33.231 [main] ERROR org.springframework.boot.SpringApplication:858 - Application run failed
org.apache.dubbo.rpc.RpcException: Fail to start server(url: dubbo://10.8.0.58:20888/com.emax.omsbase.rpcapi.modules.enterprise.service.EnterpriseService?anyhost=true&application=omsbase-provider&bean.name=ServiceBean:com.emax.omsbase.rpcapi.modules.enterprise.service.EnterpriseService&bind.ip=10.8.0.58&bind.port=20888&channel.readonly.sent=true&codec=dubbo&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&heartbeat=60000&interface=com.emax.omsbase.rpcapi.modules.enterprise.service.EnterpriseService&methods=checkEnterprise,saveEnterprise,saveEnterpriseProductConfig,queryIndustryType1,getPage,selectLoginAcc,queryIndustryType2,updateEnterpriseById,updateEntStatusByEntId,resetEntAccountPasswordByEntId,openEnterpriseByEntId,updateEnterpriseProductConfigById,updateEnterpriseBillConfigById&pid=21060&qos.enable=false&register=true&release=2.7.3&side=provider&timeout=15000&timestamp=1587716790773) Failed to bind NettyServer on /10.8.0.58:20888, cause: Address already in use: bind
...
Caused by: org.apache.dubbo.remoting.RemotingException: Failed to bind NettyServer on /10.8.0.58:20888, cause: Address already in use: bind
...
Caused by: java.net.BindException: Address already in use: bind

  

 

  

 

posted @ 2022-12-12 17:58  胡小华  阅读(1258)  评论(0编辑  收藏  举报