模拟高负载测试脚本
持续写入测试脚本
#!/bin/bash
# write_test.sh - 持续向 /boot/ 中的文件追加内容
TEST_FILE="/boot/rsync_test.log"while true; doecho "写入测试数据 - $(date '+%Y-%m-%d %H:%M:%S')" >> "$TEST_FILE"sleep 1 # 每秒写入一次
done
启动持续写入脚本:
nohup ./write_test.sh > /dev/null 2>&1 &
nohup
确保脚本在后台持续运行,即使终端关闭也不会停止。- 日志会写入
/boot/rsync_test.log
。
验证写入是否正常:
tail -f /boot/rsync_test.log
输出应类似:
写入测试数据 - 2023-11-21 14:30:00
写入测试数据 - 2023-11-21 14:30:01
...
模拟多文件并发写入
#!/bin/bash
# multi_write_test.sh - 模拟多文件并发写入
for i in {1..5}; dowhile true; doecho "文件 $i 写入数据 - $(date)" >> "/boot/test_$i.log"sleep 0.5done &
done
- 后台启动 5 个并发写入进程。
模拟大文件写入测试(模拟高负载)
- 在
/boot/
目录下创建名为large_file.bin
的二进制文件。 - 每次写入 100MB 的随机数据(来自
/dev/urandom
)。 - 每 10 秒循环执行一次,模拟高负载磁盘写入场景。
#!/bin/bash
# large_file_test.sh - 持续写入大文件
while true; dodd if=/dev/urandom of=/boot/large_file.bin bs=1M count=100 conv=notruncsleep 10
done