|
Firstly, thank you for sharing on https://hostloc.com/forum.php?mod=viewthread&highlight=%E9%98%BF%E9%87%8C
Secondly, thanks to @dole for the pleasant transaction.
From @dole's account, I received three years of service. The method was changing the security code of the real name account.
Due to the need for original real-name verification during the change of registration information, it is best to push the machine to your own real-name account.
1. Pushing the machine needs the machine to be on for at least five days
2. Pushing the machine needs to have 100 balance in the account, not the migration account. Of course, if there are mistakes, it can be refunded and approximately 5 minutes after being credited back to the original payment channel account.
3. When pushing the machine, you need to pay attention that the exchange machine (i.e., vpc subnet) of the receiving account should maintain consistency with the original machine
4. Do not use special symbols when naming the switch, such as / . * etc. Otherwise, it will cause an ECS transfer failure
5. Before migrating, unbind the IP address of the public IP network of the machine and recycle the IP and shared bandwidth, avoiding subsequent billing issues
6. To avoid traffic exceeding, copied the script from V2EX. And modified some logic. The Alibaba Cloud shared bandwidth charging choice is to take the maximum value of the outgoing flow only, i.e., take the single direction maximum rather than the sum of both directions. The script is as follows:
[root@ aliyun-hk-1 /data/scripts]
09:59:12 # cat check_traffic.sh
#!/bin/bash
# 设置网卡名称
INTERFACE="eth0"
# 设置流量限制(单位:GB )
LIMIT=150
# 检查 vnstat 和 jq 是否已安装
if ! command -v vnstat &> /dev/null; then
echo "vnstat 未安装,请安装后重试。"
exit 1
fi
if ! command -v jq &> /dev/null; then
echo "jq 未安装,请安装后重试。"
exit 1
fi
# 检查 bc 是否已安装
if ! command -v bc &> /dev/null; then
echo "bc 未安装,请安装后重试。"
exit 1
fi
# 获取当前流量(单位:KB )
VNSTAT_JSON=$(vnstat -i $INTERFACE --json)
echo "vnstat JSON 输出: $VNSTAT_JSON"
# 使用 jq 解析 JSON 数据获取接收和发送的流量(单位:KB )
RX=$(echo $VNSTAT_JSON | jq -r '.interfaces[0].traffic.total.rx')
TX=$(echo $VNSTAT_JSON | jq -r '.interfaces[0].traffic.total.tx')
# 输出解析结果
echo "接收流量 (RX): $RX KB"
echo "发送流量 (TX): $TX KB"
# 检查 RX 和 TX 是否为有效的数字
if ! [[ $RX =~ ^[0-9]+$ ]] || ! [[ $TX =~ ^[0-9]+$ ]]; then
echo "RX 或 TX 不是有效的数字。"
exit 1
fi
# 计算总流量(单位:GB )
# 判断 RX 和 TX 中较大的值
if [ "$RX" -gt "$TX" ]; then
TOTAL=$(echo "scale=2; $RX / 1024 / 1024 /1024" | bc)
echo "总流量 (TOTAL): $TOTAL GB (基于接收流量)"
else
TOTAL=$(echo "scale=2; $TX / 1024 / 1024 /1024" | bc)
echo "总流量 (TOTAL): $TOTAL GB (基于发送流量)"
fi
# 检查是否超过流量限制
if (( $(echo "$TOTAL >= $LIMIT" | bc -l) )); then
echo "流量限制已超出,执行关机。"
#sudo ip link set $INTERFACE down
init 0
else
echo "当前流量未超出限制。"
fi
[root@ aliyun-hk-1 /data/scripts]
09:59:19 # cat reset_network.sh
#!/bin/bash
# 停止 vnStat 服务
sudo systemctl stop vnstat # 如果使用 systemd 管理服务
# 删除 vnStat 数据库文件(根据需要修改网络接口名称)
sudo rm -f /var/lib/vnstat/* # 删除所有 vnstat 数据库文件
# 重新启动 vnStat 服务
sudo systemctl start vnstat # 如果使用 systemd 管理服务
echo "vnStat 流量统计数据已重置。"
|
|