【问题标题】:ipvsadm - How to display hostname and port?ipvsadm - 如何显示主机名和端口?
【发布时间】:2018-07-11 06:13:44
【问题描述】:

上例一中ipvs规则的输出如下:

[root@penguin sbin]# ipvsadm -ln
IP Virtual Server version 1.0.8 (size=65536)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  207.175.44.110:80 rr
  -> 192.168.10.5:80              Masq    1      0          0
  -> 192.168.10.4:80              Masq    1      0          0
  -> 192.168.10.3:80              Masq    1      0          0
  -> 192.168.10.2:80              Masq    1      0          0
  -> 192.168.10.1:80              Masq    1      0          0

我只想显示主机名和端口(不是 IP 和端口)。示例:

[root@penguin sbin]# ipvsadm -ln
IP Virtual Server version 1.0.8 (size=65536)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  207.175.44.110:80 rr
  -> webserver-01:80              Masq    1      0          0
  -> webserver-02:80              Masq    1      0          0
  -> webserver-03:80              Masq    1      0          0
  -> webserver-04:80              Masq    1      0          0
  -> webserver-05:80              Masq    1      0          0

请帮助我。

【问题讨论】:

    标签: linux bash shell load-balancing balance


    【解决方案1】:

    你试过了吗

    ipvsadm -l
    

    ?

    根据手册页:

    -n, --数字

      Numeric output.  IP addresses and port numbers will  be  printed
      in  numeric  format  rather  than  as as host names and services
      respectively, which is the  default.   --exact  Expand  numbers.
      Display  the  exact  value  of  the  packet  and  byte counters,
      instead  of only the rounded number in K’s (multiples  of  1000)
      M’s  (multiples  of  1000K)  or G’s (multiples  of 1000M).  This
      option is only relevant for the -L command.
    

    【讨论】:

    • 但是,当我排除 -n 选项时,端口号将替换为服务名称。示例:-> webserver-05:http Masq 1 0 0
    • 哦!您想保留端口号...我在 ipvsadm 中看不到此组合的任何选项,您必须将 IP 转换为主机名或将端口名转换为端口号。在/etc/services 中有端口名称和端口号之间的映射,您必须查询 DNS 以获得 IP 名称转换。
    • 是的。我想保留端口号。可以详细一步一步做吗?
    • 您运行命令,将输出通过管道传输到脚本。在脚本中,加载端口映射,逐行遍历输入并使用正则表达式匹配端口。使用 dict 翻译端口名称/编号。写结果。
    • 是的。我会尝试。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2016-04-12
    • 2019-04-10
    • 2023-04-06
    • 2021-02-20
    • 2020-02-09
    • 1970-01-01
    • 2021-11-14
    • 2019-03-18
    相关资源
    最近更新 更多