curl -s -X 'GET' 'http://127.0.0.1:9801/api/v2/client/mp-speeder' -H 'accept: */*' -H 'Content-Type: application/json'
/var/log/mp-sdk.log 以及 /var/log/mp-speeder.log。/usr/local/bin/mp-speeder/udping -hUsage of /usr/local/bin/mp-speeder/udping:-C intping count-I stringbind interface name-c stringprobe address, IP:PORT-i durationping interval (default 1s)-l intpayload length-logLevel stringlog level, default info-o output to shell-v show version-w durationping timeout (default 1s)
-c stringprobe address, IP:PORT
参考命令:/usr/local/bin/mp-speeder/udping -C 100 -I eth0 -c 49.7.248.202:8888 -i 0.1s -l 200
参考命令:/usr/local/bin/mp-speeder/udping -C 100 -I mp_tun0 -c 49.7.248.202:8888 -i 0.1s -l 200
参考命令:iperf3 -c x.x.x.x -p 5201 -u -b 100M -B eth0
参考命令:iperf3 -c x.x.x.x -p 5201 -u -b 100M -B 192.18.0.1
curl -X 'GET' 'http://127.0.0.1:9801/api/v2/client/flowStatistics' -H 'accept: application/json' -H 'all: true'
/usr/local/bin/mp-speeder/mp_check.sh(如果该目录下无 mp_check.sh,可将以下文件拷入该目录)。代码解释代码改写#!/bin/bash# 设置颜色输出YELLOW='\\033[0;33m'GREEN='\\033[0;32m'RED='\\033[0;31m'NC='\\033[0m' # No Color# 全局变量,用于存储加速网卡列表interfaces=""# 函数:检查进程是否运行check_process() {local process_name=$1if pgrep -f "$process_name" > /dev/null; thenecho -e "${GREEN}[✓] 进程 $process_name 正在运行${NC}"return 0elseecho -e "${RED}[✗] 进程 $process_name 未运行${NC}"return 1fi}# 函数:检查网卡是否存在并启动check_interface() {local interface=$1if ip link show "$interface" &> /dev/null; thenif ip link show "$interface" | grep -q "UP"; thenecho -e "${GREEN}[✓] 网卡 $interface 已启动且状态正常${NC}"return 0elseecho -e "${RED}[✗] 网卡 $interface 存在但未启动${NC}"return 1fielseecho -e "${RED}[✗] 网卡 $interface 不存在${NC}"return 1fi}# 函数:检查 rp_filtercheck_rp_filter() {if sysctl net.ipv4.conf.mp_tun0.rp_filter | grep -q "net.ipv4.conf.mp_tun0.rp_filter = 1"; thenecho -e "${RED}[✗] rp_filter 未关闭${NC}"return 0elseecho -e "${GREEN}[✓] rp_filter 已关闭${NC}"return 1fi}# 函数:检查策略路由check_policy_routing() {# 检查策略规则是否存在if ip rule | grep -q "from 198.18.0.1 lookup"; thenlocal table_num=$(ip rule | grep "from 198.18.0.1 lookup " | awk '{print $NF}')echo -e "${GREEN}[✓] 找到策略规则: from 198.18.0.1 lookup $table_num${NC}"# 检查路由表中的默认路由if ip route show table "$table_num" | grep -q "default dev mp_tun0"; thenecho -e "${GREEN}[✓] 路由表 $table_num 中存在正确的默认路由${NC}"elseecho -e "${RED}[✗] 路由表 $table_num 中未找到正确的默认路由${NC}"return 1fielseecho -e "${RED}[✗] 未找到策略规则: from 198.18.0.1${NC}"return 1fi# 检查基于源ip的策略规则是否存在for iface in $interfaces; do# 获取网卡IP地址local ip_addr=$(ip addr show $iface | awk '/inet / {print $2}' | cut -d/ -f1|head -n 1)if [ -z "$ip_addr" ]; thenecho -e "${YELLOW}[-] 网卡 $iface 未配置IP地址,无法通过此网卡加速,建议检查${NC}"continuefi# 检查策略规则是否存在if ip rule | grep -q "from $ip_addr lookup"; thenlocal table_num=$(ip rule | grep "from $ip_addr lookup" | awk '{print $NF}')echo -e "${GREEN}[✓] 找到网卡 $iface ($ip_addr) 的策略规则: lookup $table_num${NC}"# 检查路由表中是否有路由if ip route show table "$table_num" | grep -q "dev $iface"; thenecho -e "${GREEN}[✓] 路由表 $table_num 配置正确${NC}"elseecho -e "${RED}[✗] 路由表 $table_num 中未找到路由${NC}"return 1fielseecho -e "${YELLOW}[-] 未找到网卡 $iface ($ip_addr) 的策略规则,可能影响加速效果,建议开启SDK策略路由管理${NC}"fidonereturn 0}# 函数:检查 speeder 状态check_speeder_status() {local responseresponse=$(curl -s -X 'GET' 'http://127.0.0.1:9801/api/v2/client/mp-speeder' -H 'accept: */*' -H 'Content-Type: application/json')if echo "$response" | grep -q '"ready":true'; thenecho -e "${GREEN}[✓] speeder 正在运行且加速状态正常${NC}"# 提取加速网卡列表interfaces=$(echo "$response" | sed -n 's/.*"interfaces":\\[\\([^]]*\\)\\].*/\\1/p' | sed 's/"//g' | sed 's/:[0-9]*//g' | tr ',' ' ')echo -e "${GREEN}[✓] 加速网卡列表: $interfaces${NC}"return 0elseecho -e "${RED}[✗] speeder 未运行或加速状态异常${NC}"return 1fi}# 函数:检查 引流规则check_iptables_rules() {echo "开始检查 引流规则..."# 检查 引流规则if iptables -L mp_route_mark -nv -t mangle | grep -q "0x1/0xf"; thenecho -e "${GREEN}[✓] 引流规则检查通过${NC}"elseecho -e "${YELLOW}[-] 未检查到引流规则,请确认是否符合预期${NC}"fireturn 0}# 函数:检查 L3 功能check_l3_functionality() {echo "开始检查 L3 功能..."# 检查wireguard虚拟口状态# /usr/local/bin/mp-speeder/wg show# interface: 09yg7kk9di# public key: ISh0Y01aQ3dig5gyuivFnQe8lxi8Sdp3epNReVIYVSI=# private key: (hidden)# listening port: 55368# peer: RzZ9m8lgMVeFzILbkfLmlM9I3ZBuGoP4hrfe78Vjzg0=# endpoint: 198.18.0.5:10001# allowed ips: 192.168.18.0/28# latest handshake: 1 minute ago# transfer: 3.66 MiB received, 17.26 MiB sent# persistent keepalive: every 15 secondslocal responseresponse=$(/usr/local/bin/mp-speeder/wg show)if echo "$response" | grep -q "latest handshake"; thenecho -e "${GREEN}[✓] wireguard 虚拟口状态正常${NC}"elseecho -e "${RED}[✗] wireguard 虚拟口状态异常${NC}"return 1fi# 检查路由表local interface_name=$(echo "$response" | grep "interface:" | awk '{print $2}')local allowed_ips=$(echo "$response" | grep "allowed ips:" | awk '{print $3}')if [ -z "$interface_name" ] || [ -z "$allowed_ips" ]; thenecho -e "${RED}[✗] 无法从 wireguard 配置中获取接口名或允许的 IP${NC}"return 1fi# 检查路由表local routing_tables=$(ip route)local expected_route="$allowed_ips dev $interface_name scope link"if echo "$routing_tables" | grep -q "$expected_route"; thenecho -e "${GREEN}[✓] 路由表中存在正确的路由: $expected_route${NC}"elseecho -e "${RED}[✗] 路由表中未找到正确的路由: $expected_route${NC}"return 1fi# 检查endpoint是否符合198.18.x.x形式local endpoint=$(echo "$response" | grep "endpoint:" | awk '{print $2}')if echo "$endpoint" | grep -q "198.18."; thenecho -e "${GREEN}[✓] endpoint符合198.18.x.x形式${NC}"elseecho -e "${RED}[✗] endpoint不符合198.18.x.x形式${NC}"return 1fi# 检查引流规则# iptables -L -nv -t mangle 的结果中必须存在以下规则# 1、OUTPUT链中有mp_route_bypass、mp_route_mark、mp_l3_route三个chain,且mp_route_bypass必须在第一个# 2、mp_route_bypass链中需要有这样一条规则,destination为allowed_ips,target是ACCEPT# 3、mp_l3_route链中需要有这样一条规则,destination为endpoint,target是MARKlocal mangle_rules=$(iptables -L OUTPUT -nv -t mangle)# 1. 检查 OUTPUT 链中的 chain 顺序if ! echo "$mangle_rules" | grep -q "mp_route_bypass" || \\! echo "$mangle_rules" | grep -q "mp_route_mark" || \\! echo "$mangle_rules" | grep -q "mp_l3_route"; thenecho -e "${RED}[✗] OUTPUT 链中缺少必要的 chain${NC}"return 1fi# 确认 mp_route_bypass 在第一位if ! iptables -L OUTPUT 1 -nv -t mangle | grep -q "mp_route_bypass"; thenecho -e "${RED}[✗] mp_route_bypass 不在 OUTPUT 链的第一位${NC}"return 1fi# 2. 检查 mp_route_bypass 链中的规则if ! iptables -L mp_route_bypass -nv -t mangle | grep -q "ACCEPT.*$allowed_ips"; thenecho -e "${RED}[✗] mp_route_bypass 链中缺少目标为 $allowed_ips 的 ACCEPT 规则${NC}"return 1fi# 3. 检查 mp_l3_route 链中的规则endpoint=$(echo "$endpoint" | awk -F ':' '{print $1}')if ! iptables -L mp_l3_route -nv -t mangle | grep -q "$endpoint.*MARK.*0x1/0xf"; thenecho -e "${RED}[✗] mp_l3_route 链中缺少目标为 $endpoint 的 MARK 规则${NC}"return 1fiecho -e "${GREEN}[✓] iptables 规则检查通过${NC}"echo "L3 功能检查完成"return 0}# 解析命令行参数while [[ "$#" -gt 0 ]]; docase $1 in-h|--help)echo "用法: $0 [选项]"echo "选项:"echo " -h, --help 显示帮助信息"echo " -l, --l3-check 检查 L3 功能"exit 0;;-l|--l3-check)l3_check=trueshift;;*)echo -e "${RED}[✗] 未知参数: $1${NC}"exit 1;;esacdoneecho "开始系统检查..."echo "----------------------------------------"echo "1. 检查关键进程状态:"# 检查 mp-sdk 进程check_process "mp-sdk"if [ $? -ne 0 ]; thenecho -e "\\n${RED}检查失败,停止后续检查${NC}"exit 1fi# 检查 mp-speeder 进程check_process "mp-speeder"if [ $? -ne 0 ]; thenecho -e "\\n${RED}检查失败,停止后续检查${NC}"exit 1fiecho -e "\\n2. 检查网卡状态:"check_interface "mp_tun0"if [ $? -ne 0 ]; thenecho -e "\\n${RED}检查失败,停止后续检查${NC}"exit 1fiecho -e "\\n3. 检查加速状态:"check_speeder_statusif [ $? -ne 0 ]; thenecho -e "\\n${RED}检查失败,停止后续检查${NC}"exit 1fiecho -e "\\n4. 检查rp_filter配置:"check_rp_filterif [ $? -ne 0 ]; thenecho -e "\\n${RED}检查失败,停止后续检查${NC}"exit 1fiecho -e "\\n5. 检查策略路由配置:"check_policy_routingif [ $? -ne 0 ]; thenecho -e "\\n${RED}检查失败,停止后续检查${NC}"exit 1fiecho -e "\\n6. 检查引流规则配置:"check_iptables_rulesif [ $? -ne 0 ]; thenecho -e "\\n${RED}检查失败,停止后续检查${NC}"exit 1fi# 如果指定了 --l3-check 参数,则执行 L3 功能检查if [ "$l3_check" = true ]; thenecho -e "\\n5. 检查 L3 功能:"check_l3_functionalityif [ $? -ne 0 ]; thenecho -e "\\n${RED}L3 功能检查失败${NC}"exit 1fifiecho "----------------------------------------"echo -e "${GREEN}所有检查项目均正常!${NC}"exit 0
检测内容 | 具体内容 | 检测异常结果项 | 解决方案 |
检查进程是否运行 | - | 进程未运行 | 1. SDK 进程不存在:配置了开机自启动,检查服务状态,也可以使用 Systemctl restart mp-sdk。2. mp-speeder 进程不存在:检查是否未调用 API 启动加速,调用 API 启动加速即可。 |
检查网卡是否存在 | - | 网卡存在但未启动 | 查看“检查 speeder 状态”。 |
| - | 网卡不存在 | 检查是否有 tun 内核模块(modinfo tun)。 |
检查 rp_filter | - | rp_filter 未关闭 | sysctl -w net.ipv4.conf.mp_tun0.rp_filter=0。 |
检查策略路由 | - | 路由表中未找到正确的默认路由 | 重启 SDK。 |
| - | 未找到策略规则 | 重启 SDK。 |
检查基于源 ip 的策略规则是否存在 | 获取网卡 IP 地址 | 网卡未配置 IP 地址,无法通过此网卡加速,建议检查 | 建议关注,可不处理。 |
| 检查策略规则是否存在 | 路由表中未找到路由 | 重启 SDK。 |
| | 未找到网卡的策略规则,可能影响加速效果,建议开启 SDK 策略路由管理 | 开启 SDK 策略路由管理。 |
检查 speeder 状态 | - | 未运行或加速状态异常 | 1. 调用 API 启动加速。 2. 启动失败,自查可能原因:datakey 失效,网络未连通。 3. 其他情况联系腾讯云运维人员。 |
检查 引流规则 | - | 未检查到引流规则,请确认是否符合预期 | 1. 确认是否调用 API 添加引流策略。 2. 添加失败一般为引流规则配置问题,例如 TCP、UDP 等拼写错误、端口号超过65536等,自查排除此类问题。 3. 其他联系腾讯云运维人员。 |
检查 L3 功能 | 检查 wireguard 虚拟口状态 | wireguard 虚拟口状态异常 | 1. 无 wireguard 虚拟口可能是网络原因,与控制器失联,优先排除。 2. 其他情况联系腾讯云运维人员。 |
| 检查路由表 | 路由表中未找到正确的路由 | 1. 如果机器存在与 L3 相同的路由,需要形成 ECMP 场景,当前不支持。 2. 其他情况联系腾讯云运维人员。 |
| 检查 endpoint 是否符合198.18.x.x 形式 | endpoint 不符合198.18.x.x 形式 | 联系腾讯云运维人员。 |
| 检查引流规则-检查 OUTPUT 链中的 chain 顺序 | OUTPUT 链中缺少必要的 chain | 联系腾讯云运维人员。 |
| | mp_route_bypass 不在 OUTPUT 链的第一位 | 此问题一般为用户手动添加了其他规则,请自查。 |
| 检查引流规则-检查 mp_route_bypass 链中的规则 | mp_route_bypass 链中缺少目标的 ACCEPT 规则 | 此问题一般为用户手动删除了对应规则,请自查。 |
| 检查 mp_l3_route 链中的规则 | mp_l3_route 链中缺少目标端的 MARK 规则 | 此问题一般为用户手动删除了对应规则,请自查。 |
参考命令:curl --interface eth0 ip.sb
/usr/local/etc/mp-speeder/mp_client_extend.conf 文件配置 -disableCrypto,关闭数据加解密功能。/var/log/mp-sdk.log,同一时刻是否有多次出现“Server started on ……”。/var/log/mp-sdk.log中的policyRouteManagement,是否在开启加速时快速调用了关闭和开启。文档反馈