在線運(yùn)維命令參考手冊

2022-04-24 13:58 更新

新版本 telnet 命令使用說明

dubbo 2.5.8 新版本增加了 QOS 模塊,提供了新的 telnet 命令支持。

端口

新版本的 telnet 端口 與 dubbo 協(xié)議的端口是不同的端口,默認(rèn)為 22222,可通過配置文件dubbo.properties 修改:

dubbo.application.qos-port=33333

或者通過設(shè)置 JVM 參數(shù):

-Ddubbo.application.qos-port=33333

安全

默認(rèn)情況下,dubbo 接收任何主機(jī)發(fā)起的命令,可通過配置文件dubbo.properties 修改:

dubbo.application.qos-accept-foreign-ip=false

或者通過設(shè)置 JVM 參數(shù):

-Ddubbo.application.qos-accept-foreign-ip=false

拒絕遠(yuǎn)端主機(jī)發(fā)出的命令,只允許服務(wù)本機(jī)執(zhí)行

telnet 與 http 協(xié)議

telnet 模塊現(xiàn)在同時(shí)支持 http 協(xié)議和 telnet 協(xié)議,方便各種情況的使用

示例如下:

?  ~ telnet localhost 22222
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
  ████████▄  ███    █▄  ?█████████▄  ?█████████▄   ▄██████▄
  ███   ?███ ███    ███   ███    ███   ███    ███ ███    ███
  ███    ███ ███    ███   ███    ███   ███    ███ ███    ███
  ███    ███ ███    ███  ▄███▄▄▄██?   ▄███▄▄▄██?  ███    ███
  ███    ███ ███    ███ ??███???██▄  ??███???██▄  ███    ███
  ███    ███ ███    ███   ███    ██▄   ███    ██▄ ███    ███
  ███   ▄███ ███    ███   ███    ███   ███    ███ ███    ███
  ████████?  ████████?  ▄█████████?  ▄█████████?   ?██████?


dubbo>ls
As Provider side:
+----------------------------------+---+
|       Provider Service Name      |PUB|
+----------------------------------+---+
|org.apache.dubbo.demo.DemoService| N |
+----------------------------------+---+
As Consumer side:
+---------------------+---+
|Consumer Service Name|NUM|
+---------------------+---+

dubbo>
?  ~ curl "localhost:22222/ls?arg1=xxx&arg2=xxxx"
As Provider side:
+----------------------------------+---+
|       Provider Service Name      |PUB|
+----------------------------------+---+
|org.apache.dubbo.demo.DemoService| N |
+----------------------------------+---+
As Consumer side:
+---------------------+---+
|Consumer Service Name|NUM|
+---------------------+---+

支持的命令

ls 列出消費(fèi)者和提供者

dubbo>ls
As Provider side:
+----------------------------------+---+
|       Provider Service Name      |PUB|
+----------------------------------+---+
|org.apache.dubbo.demo.DemoService| Y |
+----------------------------------+---+
As Consumer side:
+---------------------+---+
|Consumer Service Name|NUM|
+---------------------+---+

列出 dubbo 的所提供的服務(wù)和消費(fèi)的服務(wù),以及消費(fèi)的服務(wù)地址數(shù)

Online 上線服務(wù)命令

當(dāng)使用延遲發(fā)布功能的時(shí)候(通過設(shè)置 org.apache.dubbo.config.AbstractServiceConfig#register 為 false),后續(xù)需要上線的時(shí)候,可通過 Online 命令

//上線所有服務(wù)
dubbo>online
OK

//根據(jù)正則,上線部分服務(wù)
dubbo>online com.*
OK

常見使用場景:

  • 當(dāng)線上的 QPS 比較高的時(shí)候,當(dāng)剛重啟機(jī)器的時(shí)候,由于沒有進(jìn)行JIT 預(yù)熱或相關(guān)資源沒有預(yù)熱,可能會(huì)導(dǎo)致大量超時(shí),這個(gè)時(shí)候,可通過分批發(fā)布服務(wù),逐漸加大流量
  • 當(dāng)由于某臺(tái)機(jī)器由于某種原因,需要下線服務(wù),然后又需要重新上線服務(wù)

Offline 下線服務(wù)命令

由于故障等原因,需要臨時(shí)下線服務(wù)保持現(xiàn)場,可以使用 Offline 下線命令。

//下線所有服務(wù)
dubbo>offline
OK

//根據(jù)正則,下線部分服務(wù)
dubbo>offline com.*
OK

help 命令

//列出所有命令
dubbo>help

//列出單個(gè)命令的具體使用情況
dubbo>help online
+--------------+----------------------------------------------------------------------------------+
| COMMAND NAME | online                                                                           |
+--------------+----------------------------------------------------------------------------------+
|      EXAMPLE | online dubbo                                                                     |
|              | online xx.xx.xxx.service                                                         |
+--------------+----------------------------------------------------------------------------------+

dubbo>

相關(guān)參數(shù)說明

QoS提供了一些啟動(dòng)參數(shù),來對啟動(dòng)進(jìn)行配置,他們主要包括:

參數(shù) 說明 默認(rèn)值
qos-enable 是否啟動(dòng)QoS true
qos-port 啟動(dòng)QoS綁定的端口 22222
qos-accept-foreign-ip 是否允許遠(yuǎn)程訪問 false
注意,從2.6.4/2.7.0開始,qos-accept-foreign-ip默認(rèn)配置改為false,如果qos-accept-foreign-ip設(shè)置為true,有可能帶來安全風(fēng)險(xiǎn),請仔細(xì)評估后再打開。

QoS參數(shù)可以通過如下方式進(jìn)行配置

  • 系統(tǒng)屬性
  • dubbo.properties
  • XML方式
  • Spring-boot自動(dòng)裝配方式

其中,上述方式的優(yōu)先順序?yàn)橄到y(tǒng)屬性 > dubbo.properties > XML/Spring-boot自動(dòng)裝配方式。

使用系統(tǒng)屬性方式進(jìn)行配置

-Ddubbo.application.qos-enable=true
-Ddubbo.application.qos-port=33333
-Ddubbo.application.qos-accept-foreign-ip=false

使用dubbo.properties文件進(jìn)行配置

在項(xiàng)目的src/main/resources目錄下添加dubbo.properties文件,內(nèi)容如下:

dubbo.application.qos-enable=true
dubbo.application.qos-port=33333
dubbo.application.qos-accept-foreign-ip=false

使用XML方法進(jìn)行配置

如果要通過XML配置響應(yīng)的QoS相關(guān)的參數(shù),可以進(jìn)行如下配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
  <dubbo:application name="demo-provider">
    <dubbo:parameter key="qos-enable" value="true"/>
    <dubbo:parameter key="qos-accept-foreign-ip" value="false"/>
    <dubbo:parameter key="qos-port" value="33333"/>
  </dubbo:application>
  <dubbo:registry address="multicast://224.5.6.7:1234"/>
  <dubbo:protocol name="dubbo" port="20880"/>
  <dubbo:service interface="org.apache.dubbo.demo.provider.DemoService" ref="demoService"/>
  <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>
</beans>

使用spring-boot自動(dòng)裝配方式配置

如果是spring-boot的應(yīng)用,可以在application.properties或者application.yml上配置:

dubbo.application.qos-enable=true
dubbo.application.qos-port=33333
dubbo.application.qos-accept-foreign-ip=false


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)