为vSAN启用RDMA

交换机上启用LLDP、PFC和DCBx,PFC优先级为3(默认值),DCBx的标准为IEEE(默认值)。

dcb pfc
#
interface 25GE1/0/10
 description Host-01
 port link-type trunk
 undo port trunk allow-pass vlan 1
 port trunk allow-pass vlan 125
 stp edged-port enable
 lldp tlv-enable dcbx
 dcb pfc enable mode manual
#
interface 25GE1/0/12
 description Host-02
 port link-type trunk
 undo port trunk allow-pass vlan 1
 port trunk allow-pass vlan 125
 stp edged-port enable
 lldp tlv-enable dcbx
 dcb pfc enable mode manual
#
lldp enable
#

通过主机-配置-物理适配器确认用于vSAN网卡的设备位置和端口,以下示例中是0000:8a:00的端口2(vmnic3)和0000:8b:00的端口1(vmnic4),首先查看一下LLDP和DCBx的相关配置。需要先安装MFT才能使用相关命令。

[root@yaoge123:~] /opt/mellanox/bin/mlxconfig -d 0000:8a:00.1 query|grep -iE "dcb|lldp"
        LLDP_NB_DCBX_P1                             False(0)            
        LLDP_NB_RX_MODE_P1                          OFF(0)              
        LLDP_NB_TX_MODE_P1                          OFF(0)              
        LLDP_NB_DCBX_P2                             False(0)            
        LLDP_NB_RX_MODE_P2                          OFF(0)              
        LLDP_NB_TX_MODE_P2                          OFF(0)              
        DCBX_IEEE_P1                                True(1)             
        DCBX_CEE_P1                                 True(1)             
        DCBX_WILLING_P1                             True(1)             
        DCBX_IEEE_P2                                True(1)             
        DCBX_CEE_P2                                 True(1)             
        DCBX_WILLING_P2                             True(1)             

[root@yaoge123:~] /opt/mellanox/bin/mlxconfig -d 0000:8b:00.0 query|grep -iE "dcb|lldp"
        LLDP_NB_DCBX_P1                             False(0)            
        LLDP_NB_RX_MODE_P1                          OFF(0)              
        LLDP_NB_TX_MODE_P1                          OFF(0)              
        LLDP_NB_DCBX_P2                             False(0)            
        LLDP_NB_RX_MODE_P2                          OFF(0)              
        LLDP_NB_TX_MODE_P2                          OFF(0)              
        DCBX_IEEE_P1                                True(1)             
        DCBX_CEE_P1                                 True(1)             
        DCBX_WILLING_P1                             True(1)             
        DCBX_IEEE_P2                                True(1)             
        DCBX_CEE_P2                                 True(1)             
        DCBX_WILLING_P2                             True(1)       

发现LLDP没有启动,启用LLDP和DCBx,DCBx IEEE已启用。

[root@yaoge123:~] /opt/mellanox/bin/mlxconfig -d 0000:8a:00.1 set LLDP_NB_DCBX_P2=1 LLDP_NB_RX_MODE_P2=2 LLDP_NB_TX_MODE_P2=2 DCBX_WILLING_P2=1 DCBX_IEEE_P2=1 

Device #1:
----------

Device type:        ConnectX5           
Name:               MCX512A-ACU_Ax_Bx   
Description:        ConnectX-5 EN network interface card; 10/25GbE dual-port SFP28; PCIe3.0 x8; UEFI Enabled (x86/ARM)
Device:             0000:8a:00.1        

Configurations:                                          Next Boot       New
        LLDP_NB_DCBX_P2                             False(0)             True(1)             
        LLDP_NB_RX_MODE_P2                          OFF(0)               ALL(2)              
        LLDP_NB_TX_MODE_P2                          OFF(0)               ALL(2)              
        DCBX_WILLING_P2                             True(1)              True(1)             
        DCBX_IEEE_P2                                True(1)              True(1)             

 Apply new Configuration? (y/n) [n] : y
Applying... Done!
-I- Please reboot machine to load new configurations.

[root@yaoge123:~] /opt/mellanox/bin/mlxconfig -d 0000:8b:00.0 set LLDP_NB_DCBX_P1=1 LLDP_NB_RX_MODE_P1=2 LLDP_NB_TX_MODE_P1=2 DCBX_WILLING_P1=1 DCBX_IEEE_P1=1 

Device #1:
----------

Device type:        ConnectX5           
Name:               MCX512A-ACU_Ax_Bx   
Description:        ConnectX-5 EN network interface card; 10/25GbE dual-port SFP28; PCIe3.0 x8; UEFI Enabled (x86/ARM)
Device:             0000:8b:00.0        

Configurations:                                          Next Boot       New
        LLDP_NB_DCBX_P1                             False(0)             True(1)             
        LLDP_NB_RX_MODE_P1                          OFF(0)               ALL(2)              
        LLDP_NB_TX_MODE_P1                          OFF(0)               ALL(2)              
        DCBX_WILLING_P1                             True(1)              True(1)             
        DCBX_IEEE_P1                                True(1)              True(1)             

 Apply new Configuration? (y/n) [n] : y
Applying... Done!
-I- Please reboot machine to load new configurations.

重启后查看网卡当前配置,确认LLDP和DCBx均已启用

[root@yaoge123:~] /opt/mellanox/bin/mlxconfig -d 0000:8a:00.1 query|grep -iE "dcb|lldp"
        LLDP_NB_DCBX_P1                             False(0)            
        LLDP_NB_RX_MODE_P1                          OFF(0)              
        LLDP_NB_TX_MODE_P1                          OFF(0)              
        LLDP_NB_DCBX_P2                             True(1)             
        LLDP_NB_RX_MODE_P2                          ALL(2)              
        LLDP_NB_TX_MODE_P2                          ALL(2)              
        DCBX_IEEE_P1                                True(1)             
        DCBX_CEE_P1                                 True(1)             
        DCBX_WILLING_P1                             True(1)             
        DCBX_IEEE_P2                                True(1)             
        DCBX_CEE_P2                                 True(1)             
        DCBX_WILLING_P2                             True(1)             
[root@yaoge123:~] /opt/mellanox/bin/mlxconfig -d 0000:8b:00.0 query|grep -iE "dcb|lldp"
        LLDP_NB_DCBX_P1                             True(1)             
        LLDP_NB_RX_MODE_P1                          ALL(2)              
        LLDP_NB_TX_MODE_P1                          ALL(2)              
        LLDP_NB_DCBX_P2                             False(0)            
        LLDP_NB_RX_MODE_P2                          OFF(0)              
        LLDP_NB_TX_MODE_P2                          OFF(0)              
        DCBX_IEEE_P1                                True(1)             
        DCBX_CEE_P1                                 True(1)             
        DCBX_WILLING_P1                             True(1)             
        DCBX_IEEE_P2                                True(1)             
        DCBX_CEE_P2                                 True(1)             
        DCBX_WILLING_P2                             True(1)             

查看网卡的DCB状态,模式为IEEE,PFC已启用且优先级为3(0 0 0 1 0 0 0 0)

[root@2288Hv6-05:~] esxcli network nic dcb status get -n vmnic3
   Nic Name: vmnic3
   Mode: 3 - IEEE Mode
   Enabled: true
   Capabilities: 
         Priority Group: true
         Priority Flow Control: true
         PG Traffic Classes: 8
         PFC Traffic Classes: 8
   PFC Enabled: true
   PFC Configuration: 0 0 0 1 0 0 0 0
   IEEE ETS Configuration: 
         Willing Bit In ETS Config TLV: 1
         Supported Capacity: 8
         Credit Based Shaper ETS Algorithm Supported: 0x0
         TX Bandwidth Per TC: 13 13 13 13 12 12 12 12
         RX Bandwidth Per TC: 13 13 13 13 12 12 12 12
         TSA Assignment Table Per TC: 2 2 2 2 2 2 2 2
         Priority Assignment Per TC: 1 0 2 3 4 5 6 7
         Recommended TC Bandwidth Per TC: 13 13 13 13 12 12 12 12
         Recommended TSA Assignment Per TC: 2 2 2 2 2 2 2 2
         Recommended Priority Assignment Per TC: 1 0 2 3 4 5 6 7
   IEEE PFC Configuration: 
         Number Of Traffic Classes: 8
         PFC Configuration: 0 0 0 1 0 0 0 0
         Macsec Bypass Capability Is Enabled: 0
         Round Trip Propagation Delay Of Link: 0
         Sent PFC Frames: 0 0 0 0 0 0 0 0
         Received PFC Frames: 0 0 0 0 0 0 0 0
   DCB Apps: 
[root@2288Hv6-05:~] esxcli network nic dcb status get -n vmnic4
   Nic Name: vmnic4
   Mode: 3 - IEEE Mode
   Enabled: true
   Capabilities: 
         Priority Group: true
         Priority Flow Control: true
         PG Traffic Classes: 8
         PFC Traffic Classes: 8
   PFC Enabled: true
   PFC Configuration: 0 0 0 1 0 0 0 0
   IEEE ETS Configuration: 
         Willing Bit In ETS Config TLV: 1
         Supported Capacity: 8
         Credit Based Shaper ETS Algorithm Supported: 0x0
         TX Bandwidth Per TC: 13 13 13 13 12 12 12 12
         RX Bandwidth Per TC: 13 13 13 13 12 12 12 12
         TSA Assignment Table Per TC: 2 2 2 2 2 2 2 2
         Priority Assignment Per TC: 1 0 2 3 4 5 6 7
         Recommended TC Bandwidth Per TC: 13 13 13 13 12 12 12 12
         Recommended TSA Assignment Per TC: 2 2 2 2 2 2 2 2
         Recommended Priority Assignment Per TC: 1 0 2 3 4 5 6 7
   IEEE PFC Configuration: 
         Number Of Traffic Classes: 8
         PFC Configuration: 0 0 0 1 0 0 0 0
         Macsec Bypass Capability Is Enabled: 0
         Round Trip Propagation Delay Of Link: 0
         Sent PFC Frames: 0 0 0 0 0 0 0 0
         Received PFC Frames: 0 0 0 0 0 0 0 0
   DCB Apps: 

开源镜像站缓存加速

除了某些土豪站用全闪以外,大多数开源镜像站都是以机械盘为主,当带宽充裕的时候IO显然会成为瓶颈,那么采用少量的SSD来提升性能几乎是唯一的办法。加SSD的方法有很多种:

  1. lvmcache bcache bcachefs:因在用ZFS所以没有测试这类方案,看上去比较复杂;
  2. ZFS L2ARC:实际测试基本无效果,zpool iostat 看L2ARC读取很少;
  3. nginx proxy_cache:效果显著,但是必须用反代。

proxy_cache配置在前端nginx上,前端nginx访问SSD,前端nginx需要编译安装ngx_cache_purge以便主动清除缓存。前端nginx反代给后端nginx,后端nginx访问机械盘提供实际的数据。当然也可以一个nginx同时访问SSD和机械盘,这个nginx自己反代给自己,因为只有反代了才能缓存,前端nginx缓存配置如下:

http {
    ……
    proxy_cache_path /cache levels=1:2 use_temp_path=off keys_zone=mirror:64m inactive=6h max_size=1946g;
    ……
}
server {
    listen 80;
    listen [::]:80;
    listen 443 ssl;
    listen [::]:443 ssl;
    listen *:443 quic;
    listen [::]:443 quic;
    server_name mirror.nju.edu.cn mirrors.nju.edu.cn;
    ……
    proxy_cache mirror;
    proxy_cache_key $request_uri;
    proxy_cache_valid 200 24h;
    proxy_cache_valid 301 302 1h;
    proxy_cache_valid any 1m;
    proxy_cache_lock on;
    proxy_cache_lock_age 3s;
    proxy_cache_lock_timeout 3s;
    proxy_cache_use_stale error timeout updating;
    proxy_cache_background_update on;
    proxy_cache_revalidate on;
    cache_purge_response_type text;
    proxy_cache_purge PURGE from 127.0.0.1 192.168.10.10;
    add_header X-Cache-Status $upstream_cache_status;
    ……
    location / {
        proxy_pass http://192.168.10.10:8000;

        ……
    }
    ……
}
  • proxy_cache_path:
    use_temp_path=off 临时文件直接放到 cache 目录中,防止文件在 temp_path 和 cache_path 之间移动。缓存文件会先放在 temp_path 中,下载完了再移动到 cache_path 下,设定成 off 比较简单安全。
    keys_zone=mirror:64m 内存缓存区名称是 mirror 容量是64MB,每MB内存可以缓存八千个key,可以估算一下key的数量设定缓存区大小。
    inactive=6h 超过6小时没有访问的缓存会被删除,无论是否 valid,防止缓存被长期未用的数据占用。
    max_size=1946g 要比缓存目录 /cache 容量稍小,如果缓存用尽 nginx 会报错 [crit] …… failed (2: No such file or directory) 而且会直接断开客户端链接。
  • proxy_cache mirror:匹配前面 proxy_cache_path 的内存缓存区名称。
  • proxy_cache_key $request_uri:原始请求的URL,用这个URL用作缓存的key,只要这个key(请求URL)一样则nginx用缓存中一样的数据回复。
  • proxy_cache_valid 200 24h; proxy_cache_valid 301 302 1h; proxy_cache_valid any 1m;:HTTP状态码200的缓存24小时、301/302的缓存1小时、其它的缓存1分钟,缓存达到这个时间就会被抛弃,防止数据被长期缓存不能得到更新。
  • proxy_cache_lock on:当有多个请求同一个文件时(同一个key),只有第一个请求从反代中获取,通过加锁让后续的请求等待第一个请求完成后从缓存中获取,防止并发从后端中请求同一个文件,加重后端负载。
  • proxy_cache_lock_age 3s:第一个请求锁定3秒,到期后就释放锁,下一个请求发送到后端。
  • proxy_cache_lock_timeout 3s:后续的请求如果等待3秒还未从缓存中获取,就直接从后端获取,但是不缓存。
  • proxy_cache_use_stale error timeout updating:当请求后端时出现错误(error)或超时(timeout)时使用过期缓存,如果因缓存过期正在更新中(updating)时使用过期缓存,过期的缓存总比没有好。
  • proxy_cache_background_update on:允许后台请求过期的缓存。
  • proxy_cache_revalidate on:更新缓存时使用 If-Modified-Since 和 If-None-Match 请求后端,后端可以返回304而非200减少传输。
  • cache_purge_response_type text:清除缓存后返回文本格式的结果。
  • proxy_cache_purge PURGE from 127.0.0.1 192.168.10.10:使用PURGE这个HTTP方法清除缓存,允许本地和192.168.10.10来清除。
  • add_header X-Cache-Status $upstream_cache_status:添加HTTP头X-Cache-Status以便客户端知道缓存情况。

后端nginx可能需要设定某些文件的缓存有效期,比如提供给mirrorz的相关文件需要根据不同的请求站点设置不同的 Access-Control-Allow-Origin 头以实现跨域,但是URL相同则前端缓存key相同,前端无法根据不同的请求站点回复不同的HTTP头,在缓存有效期内均回复第一次访问缓存下来的HTTP头,所以比较简单的方法就是直接禁用有关文件的缓存:

server {
    listen 8000;
    root /mirror;
    ……
    location ~ ^/mirrorz/ {
        expires -1;
        ……
    }
    ……
}
  • expires -1:负值禁用缓存,通过添加HTTP头 Cache-Control: no-cache 和 Expires,Expires被设定为当前时间之前,这样前端nginx就不会缓存 mirrorz 的URL了。

编辑 tunasync worker 的配置文件添加一个脚本,使得每个同步作业结束后均清除前端上这个镜像的所有缓存:

#tunasync worker的配置文件
[global]
……
exec_on_success = [ "/home/mirror/postexec.sh" ]
exec_on_failure = [ "/home/mirror/postexec.sh" ]
……

#上述的postexec.sh脚本内容
#!/bin/bash
MIRROR_DIR="/mirror/"
DIR="${TUNASYNC_WORKING_DIR/"$MIRROR_DIR"/}"
/usr/bin/curl --silent --output /dev/null --request PURGE "https://mirror.nju.edu.cn/$DIR/*"

镜像站某些状态文件会频繁的周期更新,每次更新后都用 curl --silent --output /dev/null --request PURGE "https://mirror.nju.edu.cn/status/*" 清除一下缓存。

NVMe over RoCE 网络规划

NVMe over RoCE 存储系统的网络应认真规划,下面以一个简单的系统为例说明:

  • 一台双控制器(A控、B控)NVMe存储,每个控制器上有四个NVMe over RoCE的网口(A控A1-A4、B控B1-B4)
  • 两台无损以太网交换机(交换机A、交换机B)
  • 两台服务器(服务器1、服务器2)
  • 每台服务器有两个RoCE网卡(服务器X网卡1、服务器X网卡2),每个网卡有两个网口(服务器X网卡1A、服务器X网卡1B、服务器X网卡2A、服务器X网卡2B)
  • VLAN 123-124 用于 NVMe over RoCE、VLAN 99 用于业务网

交换机A的VLAN 123(192.168.123.0/24)用于传输NVMe over RoCE、交换机B用VLAN 124(192.168.124.0/24)用于传输NVMe over RoCE。无论是控制器、交换机、网卡坏任意一个,甚至每类都任意坏一个,均不影响业务连续性

接口交换机链接VLANNVMe over RoCE IP
存储A控A1交换机A123192.168.123.101
存储A控A2交换机A123192.168.123.102
存储A控A3交换机B124192.168.124.101
存储A控A4交换机B124192.168.124.102
存储B控B1交换机A123192.168.123.103
存储B控B2交换机A123192.168.123.104
存储B控B3交换机B124192.168.124.103
存储B控B4交换机B124192.168.124.104
服务器1网卡1A交换机A123192.168.123.11
服务器1网卡1B交换机B99业务网
服务器1网卡2A交换机A99业务网
服务器1网卡1B交换机B124192.168.124.11
服务器2网卡1A交换机A123192.168.123.12
服务器2网卡1B交换机B99业务网
服务器2网卡2A交换机A99业务网
服务器2网卡2B交换机B124192.168.124.12

VMware ESXi 配置 NVMe over RoCE

NVMe over RoCE 的相关配置需要在 vCenter Server Client 下面操作,ESXi Host Client 下是没有相关选项的,至少图形界面是这样,用 esxicli 估计可以直接在 ESXi 下面配置。所以需要先用本地的盘部署一套VCSA,精简配置大约150GB就够了,等NVMe配置好再迁移到存储上。

  • 在配置-网络-RDMA 适配器下确认RDMA适配器(vmrdmaX)对应的物理网络适配器(vmnicX),可通过交换机 shutdown 等方法确认规划用于 NVMe 的端口对应的物理网络适配器名称。
    如 vmrdma0 对应 vmnic2、vmrdma3 对应 vmnic5。
  • 在配置-网络-虚拟交换机下添加网络,选择 VMkernel 网络适配器、选择新建标准交换机、输入MTU(Dorado 推荐5500),选择一个用于NVMe的物理网络适配器,VLAN ID 填写对应交换机的 NVMe over RoCE 用 VLAN,可用服务中仅勾选 NVMe over RDMA,配置静态IPv4地址。
  • 重复上述过程,为每个 NVMe 端口对应的物理网络适配器创建独立的虚拟交换机并配置独立的 VLAN、独立的 VMkernel 端口,实现每个 VMKernel 和物理网络适配器之间一一映射。
    如 vSwitch1 绑定物理网络适配器 vmnic2、VMkernel 端口 vmk1 192.168.123.11、VLAN ID  123;vSwitch2 绑定物理网络适配器 vmnic5、VMkernel 端口 vmk2 192.168.124.11、VLAN ID  124。
  • 在配置-存储-存储适配器-添加软件适配器,添加 NVMe over RDMA 适配器,选择对应的RDMA设备。重复该过程为每个 NVMe 的 RDMA适配器 添加 软件适配器。
    如为 vmrdma0 添加 vmhba64,为 vmrdma3 添加 vmhba65
  • 在配置-存储-存储适配器中,选中刚刚添加的vmhbaXX(VMware NVME over RDMA Storage Adapter),在控制器中添加控制器,填写子系统NQN(存储的NQN)、该网络对应VLAN下的存储IP,保持活动时间 Dorado 推荐5秒,重复此过程添加存储在该VLAN下的所有IP。
    如 vmhba64 添加有 192.168.123.101-104 四个控制器
  • 重复上述过程给剩下的 vmhbaXX 添加控制器。
    vmhba65 添加有 192.168.124.101-104 四个控制器
  • 上述的每个控制器如果都可以访问同一个LUN,那么每一个都是一个多路径。7.0最多4条,8.0最多8条,8.0U1最多32条。
  • 最终结果如下表所示,8个路径 = 2个物理网络适配器 x 4个控制器
RDMA适配器VMkernel适配器VMkernel 适配器 IP物理适配器虚拟交换机VLAN存储适配器存储控制器 IP
vmrdma0vmk1192.168.123.11vmnic2vSwitch1123vmhba64192.168.123.101-104
vmrdma3vmk2192.168.124.11vmnic5vSwitch2124vmhba65192.168.124.101-104

NVMe over RoCE 网络配置

NVMe over RoCE 要求无损网络,因此交换机和主机网卡均需要一些配置来保证无损。

QoS标记采用PCP为例,PCP是在VLAN标签中标记优先级,所以流量必须在VLAN中,Dorado 不是所有的前端接口卡都支持DSCP。

  • 交换机启用PFC优先级3,1分钟发生死锁20次,关闭端口PFC
  • 交换机配置PFC死锁检测,检测时间1000ms,恢复时间1500ms
  • 交换机与存储和服务器链接用于NVMe over RoCE的所有端口配置PFC、VLAN和MTU
  • 两台交换机使用不同的VLAN,防止出现跨交换机的流量
  • 交换机在队列3启用AI-ECN并加载集中存储模型
  • 交换机启用LLDP(iNOF的基本要求)
  • 交换机启用简单的iNOF(默认域、无反射器)
dcb pfc nof
 priority 3 turn-off threshold 20
#
dcb pfc deadlock-detect timer 1000
dcb pfc deadlock-recovery timer 1500
#
interface 25GE1/0/1
 description Dorado-A
 port link-type trunk
 port trunk allow-pass vlan 123
 stp edged-port enable
 dcb pfc enable nof mode manual
 jumboframe enable 5500
#               
interface 25GE1/0/2
 description Dorado-A
 port link-type trunk
 port trunk allow-pass vlan 123
 stp edged-port enable
 dcb pfc enable nof mode manual
 jumboframe enable 5500
#
interface 25GE1/0/3
 description Dorado-B
 port link-type trunk
 port trunk allow-pass vlan 123
 stp edged-port enable
 dcb pfc enable nof mode manual
 jumboframe enable 5500
#               
interface 25GE1/0/4
 description Dorado-B
 port link-type trunk
 port trunk allow-pass vlan 123
 stp edged-port enable
 dcb pfc enable nof mode manual
 jumboframe enable 5500
#
interface 25GE1/0/9
 description Host-01
 port link-type trunk
 port trunk allow-pass vlan 123
 stp edged-port enable
 dcb pfc enable nof mode manual
 jumboframe enable 5500
#
interface 25GE1/0/11
 description Host-02
 port link-type trunk
 port trunk allow-pass vlan 123
 stp edged-port enable
 dcb pfc enable nof mode manual
 jumboframe enable 5500
#
lldp enable
#
ai-service
 #
 ai-ecn
  ai-ecn enable
  assign queue 3 model ai_ecn_centralizedstorage
 #
 inof
#
return
  • 为确保 RoCE 流量无损,在 ESXi 主机中将 PFC 优先级值配置为 3
[root@yaoge123:~] esxcli system module parameters set -m nmlx5_core -p "pfctx=0x08 pfcrx=0x08"
  • 重启后查看,pfctx和pfcrx值均为0x08
[root@yaoge123:~] esxcli system module parameters list -m nmlx5_core | grep pfc
pfcrx                int            0x08   Priority based Flow Control policy on RX.
   Notes: Must be equal to pfctx.
pfctx                int            0x08   Priority based Flow Control policy on TX.
   Notes: Must be equal to pfcrx.

ESXi 升级 Mellanox 网卡固件

    NVMe over RoCE 对RoCE网卡的固件兼容性有较高要求

    • 打开ESXi的SSH并进入维护模式,远程登录ESXi主机
    • 用 esxcfg-nics -l 查看网卡列表,用 esxcli network nic get -n 查看网卡驱动和固件版本
    [root@yaoge123:~] esxcfg-nics -l
    Name    PCI          Driver      Link Speed      Duplex MAC Address       MTU    Description                   
    vmnic0  0000:19:00.0 igbn        Up   1000Mbps   Full   **:**:**:**:**:** 1500   Intel Corporation I350 Gigabit Network Connection
    vmnic1  0000:19:00.1 igbn        Up   1000Mbps   Full   **:**:**:**:**:** 1500   Intel Corporation I350 Gigabit Network Connection
    vmnic2  0000:8a:00.0 nmlx5_core  Up   25000Mbps  Full   **:**:**:**:**:** 1500   Mellanox Technologies ConnectX-5 EN NIC; 10/25GbE; dual-port SFP28; PCIe3.0 x8; (MCX512A-ACU)
    vmnic3  0000:8a:00.1 nmlx5_core  Up   25000Mbps  Full   **:**:**:**:**:** 1500   Mellanox Technologies ConnectX-5 EN NIC; 10/25GbE; dual-port SFP28; PCIe3.0 x8; (MCX512A-ACU)
    vmnic4  0000:8b:00.0 nmlx5_core  Up   25000Mbps  Full   **:**:**:**:**:** 1500   Mellanox Technologies ConnectX-5 EN NIC; 10/25GbE; dual-port SFP28; PCIe3.0 x8; (MCX512A-ACU)
    vmnic5  0000:8b:00.1 nmlx5_core  Up   25000Mbps  Full   **:**:**:**:**:** 1500   Mellanox Technologies ConnectX-5 EN NIC; 10/25GbE; dual-port SFP28; PCIe3.0 x8; (MCX512A-ACU)
    [root@yaoge123:~] esxcli network nic get -n vmnic2
       Advertised Auto Negotiation: true
       Advertised Link Modes: Auto, 1000BaseCX-SGMII/Full, 10000BaseKR/Full, 25000BaseTwinax/Full
       Auto Negotiation: true
       Backing DPUId: N/A
       Cable Type: FIBRE
       Current Message Level: -1
       Driver Info: 
             Bus Info: 0000:8a:00:0
             Driver: nmlx5_core
             Firmware Version: 16.32.1010
             Version: 4.23.0.36
       Link Detected: true
       Link Status: Up 
       Name: vmnic2
       PHYAddress: 0
       Pause Autonegotiate: false
       Pause RX: true
       Pause TX: true
       Supported Ports: FIBRE, DA
       Supports Auto Negotiation: true
       Supports Pause: true
       Supports Wakeon: false
       Transceiver: internal
       Virtual Address: **:**:**:**:**:**
       Wakeon: None
    
    • VMware兼容性 搜索该网卡型号查询对应的驱动和固件版本
    • 下载 MFT,选择和ESXi版本匹配的安装包
    • 下载的Mellanox-MFT-Tools_*-package.zip解压,将解压出的.zip文件传至ESXi的/tmp,确认上传的.zip文件内根目录就有index.xml
    • 下载的Mellanox-NATIVE-NMST_*-package.zip解压,将解压出的.zip文件传至ESXi的/tmp,确认上传的.zip文件内根目录就有index.xml
    • 用 esxcli software component apply -d 安装上传的两个.zip,注意要写全路径
    [root@yaoge123:/tmp] esxcli software component apply -d /tmp/Mellanox-MFT-Tools_4.26.1.101-1OEM.801.0.0.21495797_22944840.zip 
    Installation Result
       Message: Operation finished successfully.
       Components Installed: Mellanox-MFT-Tools_4.26.1.101-1OEM.801.0.0.21495797
       Components Removed: 
       Components Skipped: 
       Reboot Required: false
       DPU Results: 
    [root@yaoge123:/tmp] esxcli software component apply -d /tmp/Mellanox-NATIVE-NMST_4.26.1.101-1OEM.801.0.0.21495797_22944879.zip 
    Installation Result
       Message: The update completed successfully, but the system needs to be rebooted for the changes to be effective.
       Components Installed: Mellanox-NATIVE-NMST_4.26.1.101-1OEM.801.0.0.21495797
       Components Removed: 
       Components Skipped: 
       Reboot Required: true
       DPU Results: 
    
    • 重启ESXi再打开SSH
    • 下载 Firmware ,查找对应网卡的兼容版本固件下载
    • 下载的fw-*.bin.zip解压,将解压出的.bin文件上传至ESXi的/tmp
    • 在/tmp下执行/opt/mellanox/bin/mlxfwmanager,会自动发现新固件文件,然后添加-u升级
    [root@yaoge123:/tmp] /opt/mellanox/bin/mlxfwmanager
    Querying Mellanox devices firmware ...
    
    Device #1:
    ----------
    
      Device Type:      ConnectX5
      Part Number:      MCX512A-ACU_Ax_Bx
      Description:      ConnectX-5 EN network interface card; 10/25GbE dual-port SFP28; PCIe3.0 x8; UEFI Enabled (x86/ARM)
      PSID:             MT_0000000425
      PCI Device Name:  mt4119_pciconf0
      Base GUID:        ***
      Base MAC:         ***
      Versions:         Current        Available     
         FW             16.32.1010     16.34.1002    
         PXE            3.6.0502       3.6.0700      
         UEFI           14.25.0017     14.27.0014    
    
      Status:           Update required
    
    Device #2:
    ----------
    
      Device Type:      ConnectX5
      Part Number:      MCX512A-ACU_Ax_Bx
      Description:      ConnectX-5 EN network interface card; 10/25GbE dual-port SFP28; PCIe3.0 x8; UEFI Enabled (x86/ARM)
      PSID:             MT_0000000425
      PCI Device Name:  mt4119_pciconf1
      Base GUID:        ***
      Base MAC:         ***
      Versions:         Current        Available     
         FW             16.32.1010     16.34.1002    
         PXE            3.6.0502       3.6.0700      
         UEFI           14.25.0017     14.27.0014    
    
      Status:           Update required
    
    ---------
    Found 2 device(s) requiring firmware update. Please use -u flag to perform the update.
    
    [root@yaoge123:/tmp] /opt/mellanox/bin/mlxfwmanager -u
    Querying Mellanox devices firmware ...
    
    Device #1:
    ----------
    
      Device Type:      ConnectX5
      Part Number:      MCX512A-ACU_Ax_Bx
      Description:      ConnectX-5 EN network interface card; 10/25GbE dual-port SFP28; PCIe3.0 x8; UEFI Enabled (x86/ARM)
      PSID:             MT_0000000425
      PCI Device Name:  mt4119_pciconf0
      Base GUID:        ***
      Base MAC:         ***
      Versions:         Current        Available     
         FW             16.32.1010     16.34.1002    
         PXE            3.6.0502       3.6.0700      
         UEFI           14.25.0017     14.27.0014    
    
      Status:           Update required
    
    Device #2:
    ----------
    
      Device Type:      ConnectX5
      Part Number:      MCX512A-ACU_Ax_Bx
      Description:      ConnectX-5 EN network interface card; 10/25GbE dual-port SFP28; PCIe3.0 x8; UEFI Enabled (x86/ARM)
      PSID:             MT_0000000425
      PCI Device Name:  mt4119_pciconf1
      Base GUID:        ***
      Base MAC:         ***
      Versions:         Current        Available     
         FW             16.32.1010     16.34.1002    
         PXE            3.6.0502       3.6.0700      
         UEFI           14.25.0017     14.27.0014    
    
      Status:           Update required
    
    ---------
    Found 2 device(s) requiring firmware update...
    
    Perform FW update? [y/N]: y
    Device #1: Updating FW ...     
    FSMST_INITIALIZE -   OK          
    Writing Boot image component -   OK                                                                                                                                                              Done
    Device #2: Updating FW ...     
    FSMST_INITIALIZE -   OK          
    Writing Boot image component -   OK                                                                                                                                                              Done
    
    Restart needed for updates to take effect.
    
    • 重启后再检查网卡的固件版本
    [root@yaoge123:~] esxcli network nic get -n vmnic2
       Advertised Auto Negotiation: true
       Advertised Link Modes: Auto, 1000BaseCX-SGMII/Full, 10000BaseKR/Full, 25000BaseTwinax/Full
       Auto Negotiation: true
       Backing DPUId: N/A
       Cable Type: FIBRE
       Current Message Level: -1
       Driver Info: 
             Bus Info: 0000:8a:00:0
             Driver: nmlx5_core
             Firmware Version: 16.34.1002
             Version: 4.23.0.36
       Link Detected: true
       Link Status: Up 
       Name: vmnic2
       PHYAddress: 0
       Pause Autonegotiate: false
       Pause RX: true
       Pause TX: true
       Supported Ports: FIBRE, DA
       Supports Auto Negotiation: true
       Supports Pause: true
       Supports Wakeon: false
       Transceiver: internal
       Virtual Address: **:**:**:**:**:**
       Wakeon: None
    

    GitLab CVE-2023-7028 临时应对措施

    一个非常无语的高危漏洞,任何人都可以重置任意账号的密码然后发送到指定邮箱

    对于容器部署来说,直接修改 /var/opt/gitlab/nginx/conf/gitlab-http.conf 文件,在其中添加

    location /users/password { 
    return 444;
    }

    然后重新加载nginx配置文件

    gitlab-ctl hup nginx

    DNSmasq 为HPC集群外容器提供集群内主机名解析

    在HPC集群中通常有DNS和本地hosts提供解析服务,以便节点间通过主机名互相通信,而不是直接使用IP地址。但是如果在集群外有一个独立服务器中的容器需要与集群内的节点通过主机名通讯,就需要通过DNS来给容器提供解析服务。

    通过自动化脚本将集群的hosts拷贝到独立服务器的一个目录下,如 /home/hpc/dns/hosts

    自己做一个dnsmasq的容器:

    [yaoge123]$ cat dnsmasq/Dockerfile 
    FROM alpine:latest
    RUN apk update \
     && apk upgrade \
     && apk add --no-cache \
                dnsmasq \
     && rm -rf /var/cache/apk/*
    

    编写docker-compose.yml:

    1. dnsmasq提供了DNS服务,需要指定ip地址,以便在下面其它容器配置中指定dns ip
    2. /home/hpc/dns 是存储hosts的本机目录
    3. 生产环境用 –keep-in-foreground,调试时用–no-daemon和–log-queries
    4. –domain-needed 一定要加,防止dnsmasq将没有域的主机名(没有.的)转发给上游DNS
    5. –cache-size= 改的比hosts文件行数多一些
    6. abc是要解析集群内主机名的容器,添加的dns就是为了用dnsmasq来提供解析服务
    7. 不要解析的就不要加dns
    services:
      dnsmasq:
        build: ./dnsmasq
        image: dnsmasq
        container_name: dnsmasq
        networks:
          default:
            ipv4_address: 192.168.100.200
        volumes:
          - /home/hpc/dns:/etc/dns:ro
        command:
          - dnsmasq
          - --keep-in-foreground
            #- --no-daemon
            #- --log-queries
          - --domain-needed
          - --no-hosts
          - --cache-size=3000
          - --hostsdir=/etc/dns
      abc:
        image: abc
        container_name: abc
        dns:
          - 192.168.100.200
      …………
    networks:
      default:
        driver: bridge
        ipam:
          driver: default
          config:
            - subnet: 192.168.100.0/24

    测试解析和查看 dnsmasq 缓存情况,evictions为0最好

    [yaoge123]# run --rm -it --network=docker_default --dns=192.168.100.200 alpine sh
    / # apk add bind-tools
    / # dig +short node_name
    / # for i in "cachesize.bind insertions.bind evictions.bind misses.bind hits.bind auth.bind servers.bind";do dig +short chaos txt $i;done

    OnlyOffice Document Server 容器部署和监控

    大体架构是:前端 Nginx 卸载SSL后反代给 OnlyOffice,OnlyOffice 将监控信息喂给 statsd-exporter,Prometheus 从 statsd-exporter 拉取数据,最终用 Grafana 可视化展示。

    先来 docker-compose.yml 配置如下,有一些注意修改的地方:

    1. 可以把一些onlyoffice插件挂进容器中 /var/www/onlyoffice/documentserver/sdkjs-plugins/ 目录下,启动时会自动加载。
    2. onlyoffice自带的中文字体少的可怜,一定要整理一些常用字体(特别是Windows/Office自带的字体),将ttf/otf字体文件挂进容器中 /usr/share/fonts/ 目录下,启动时会自动加载。
    3. onlyoffice的持久化配置挂进容器 /etc/onlyoffice/documentserver/local-production-linux.json,这样升级重启的时候配置才能保留下来;容器里面的配置文件改了也没用,重建就全丢了。
    4. JWT_SECRET 配置一个足够强的Token,和应用软件配置要一样。
    services:
      onlyoffice:
        image: onlyoffice/documentserver-ee
        container_name: onlyoffice
        volumes:
          - ./onlyoffice/logs:/var/log/onlyoffice
          - ./onlyoffice/data:/var/www/onlyoffice/Data
          - ./onlyoffice/lib:/var/lib/onlyoffice
          - ./onlyoffice/db:/var/lib/postgresql
          - ./onlyoffice/fonts/dejavu:/usr/share/fonts/dejavu
          - ./onlyoffice/fonts/founder:/usr/share/fonts/founder
          - ./onlyoffice/fonts/liberation:/usr/share/fonts/liberation
          - ./onlyoffice/fonts/libertinus:/usr/share/fonts/libertinus
          - ./onlyoffice/fonts/noto-cjk:/usr/share/fonts/noto-cjk
          - ./onlyoffice/fonts/noto-emoji:/usr/share/fonts/noto-emoji
          - ./onlyoffice/fonts/sarasa-gothic:/usr/share/fonts/sarasa-gothic
          - ./onlyoffice/fonts/source-code-pro:/usr/share/fonts/source-code-pro
          - ./onlyoffice/fonts/source-han-sans:/usr/share/fonts/source-han-sans
          - ./onlyoffice/fonts/source-han-serif:/usr/share/fonts/source-han-serif
          - ./onlyoffice/fonts/source-sans:/usr/share/fonts/source-sans
          - ./onlyoffice/fonts/source-serif:/usr/share/fonts/source-serif
          - ./onlyoffice/fonts/windows:/usr/share/fonts/windows
          - ./onlyoffice/local-production-linux.json:/etc/onlyoffice/documentserver/local-production-linux.json
        environment:
          - TZ=Asia/Shanghai
          - JWT_ENABLED=true
          - JWT_SECRET=yaoge123
      statsd-exporter:
        image: prom/statsd-exporter
        container_name: statsd-exporter
        ports:
          - 9102:9102
        depends_on:
          - onlyoffice 
      nginx:
        image: nginx:alpine
        container_name: nginx
        ports:
          - 80:80
          - 443:443
        volumes:
          - ./nginx/conf.d/:/etc/nginx/conf.d/:ro
          - ./nginx/ssl/:/etc/nginx/ssl/:ro
        environment:
          - TZ=Asia/Shanghai
      nginx-exporter:
        image: nginx/nginx-prometheus-exporter
        container_name: nginx-prometheus-exporter
        ports:
          - 9113:9113
        command:
          - -nginx.scrape-uri
          - http://nginx:8080/stub_status
        depends_on:
          - nginx
    ……

    在 local-production-linux.json 对 OnlyOffice 进行持久化配置,主要是三部分:

    1. 开启statsd监控推送,填写statsd-exporter的主机名和端口
    2. 开启自动保存
    3. 打开文件尺寸扩大至1GB(默认是100MB)
    {
            "statsd": {
                    "useMetrics": true,
                    "host": "statsd-exporter",
                    "port": "9125",
                    "prefix": "ds."
            },
    	"services": {
    		"CoAuthoring": {
    			"autoAssembly": {
    				"enable": true,
    				"interval": "5m"
    			}
    		}
    	},
    	"FileConverter": {
    		"converter": {
    			"maxDownloadBytes": 1073741824,
    			"downloadAttemptMaxCount": 3
    		}
    	}
    }
    

    Nginx 配置反代卸载SSL

    map $http_host $this_host {
        "" $host;
        default $http_host;
    }
    
    map $http_x_forwarded_proto $the_scheme {
         default $http_x_forwarded_proto;
         "" $scheme;
    }
    
    map $http_x_forwarded_host $the_host {
        default $http_x_forwarded_host;
        "" $this_host;
    }
    
    map $http_upgrade $proxy_connection {
        default upgrade;
        "" close;
    }
    
    server {
    	listen 80;
    	listen [::]:80;
    	server_name onlyoffice.nju.edu.cn;
    	rewrite ^ https://$http_host$request_uri? permanent;
    	server_tokens off;
    }
    
    server {
            listen 443 ssl http2;
            listen [::]:443 ssl http2;
    	server_name onlyoffice.nju.edu.cn;
    	server_tokens off;
    
            include ssl/nju_edu_cn.conf;
    
    	add_header X-Content-Type-Options nosniff;
    
    	location / {
    		proxy_pass http://onlyoffice;
    		proxy_http_version 1.1;
    		proxy_set_header Upgrade $http_upgrade;
    		proxy_set_header Connection $proxy_connection;
    		proxy_set_header X-Forwarded-Host $the_host;
    		proxy_set_header X-Forwarded-Proto $the_scheme;
    		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    	}
    }
    
    server {
    	listen 8080;
    	listen [::]:8080;
    	server_name localhost;
    
    	location /stub_status {
    		stub_status on;
    		access_log off;
    	}
    }
    
    

    在 Consul 中注册 OnlyOffice 和 Nginx 的监控

    [yaoge123 ~]$ curl -X PUT -d '{"id": "onlyoffice.nju.edu.cn_statsd-exporter","name": "statsd_exporter","address": "onlyoffice.nju.edu.cn","port": 9102,"tags": ["prometheus","vm"],"checks": [{"http": "http://onlyoffice.nju.edu.cn:9102/metrics","interval": "30s"}]}' http://consul:8500/v1/agent/service/register
    
    [yaoge123 ~]$ curl -X PUT -d '{"id": "onlyoffice.nju.edu.cn_nginx-exporter","name": "nginx_exporter","address": "onlyoffice.nju.edu.cn","port": 9113,"tags": ["prometheus","vm"],"checks": [{"http": "http://onlyoffice.nju.edu.cn:9113/metrics","interval": "30s"}]}' http://consul:8500/v1/agent/service/register

    在Grafana中导入基于官方Dashboard的修改版

    https://grafana.com/grafana/dashboards/17048