Memo

共 19 条灌水 · 4

vLLM 部署为 systemd 服务

配置 vLLM 环境,并且让他随着系统自启动

安装环境:

mkdir my-vllm
cd my-vllm

uv init
uv add vllm

编写 service 文件:

# vim /etc/systemd/system/vllm.service

[Unit]
Description=vLLM
After=network.target
Wants=network.target

[Service]
Type=simple
Environment=HF_ENDPOINT=https://hf-mirror.com
WorkingDirectory=/opt/vllm
ExecStart=uv run vllm serve "Qwen/Qwen3-Embedding-0.6B"
Restart=always
RestartSec=10
User=user
Group=user

[Install]
WantedBy=multi-user.target

vLLM,启动!

systemctl daemon-reload
systemctl enable --now vllm

默认端口

Oracle Linux Shell Script to Calculate Values Recommended Linux HugePages Configuration (Doc ID 401749.1)

Oracle Doc ID 401749.1 的脚本,自动配置 hugepage

#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
# on Oracle Linux
#
# Note: This script does calculation for all shared memory
# segments available when the script is run, no matter it
# is an Oracle RDBMS shared memory segment or not.
#
# This script is provided by Doc ID 401749.1 from My Oracle Support
# http://support.oracle.com
# Welcome text
echo "
This script is provided by Doc ID 401749.1 from My Oracle Support
(http://support.oracle.com) where it is intended to compute values for
the recommended HugePages/HugeTLB configuration for the current shared
memory segments on Oracle Linux. Before proceeding with the execution please note following:
* For ASM instance, it needs to configure ASMM instead of AMM.
* The 'pga_aggregate_target' is outside the SGA and
 you should accommodate this while calculating the overall size.
* In case you changes the DB SGA size,
 as the new SGA will not fit in the previous HugePages configuration,
 it had better disable the whole HugePages,
 start the DB with new SGA size and run the script again.
And make sure that:
* Oracle Database instance(s) are up and running
* Oracle Database 11g Automatic Memory Management (AMM) is not setup
 (See Doc ID 749851.1)
* The shared memory segments can be listed by command:
 # ipcs -m
Press Enter to proceed..."
read
# Check for the kernel version
KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`
# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`
if [ -z "$HPG_SZ" ];then
 echo "The hugepages may not be supported in the system where the script is being
executed."
 exit 1
fi
# Initialize the counter
NUM_PG=0
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | cut -c44-300 | awk '{print $1}' | grep "[0-9][0-9]*"`
do
 MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
 if [ $MIN_PG -gt 0 ]; then
 NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
 fi
done
RES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" | bc -q`
# An SGA less than 100MB does not make sense
# Bail out if that is the case
if [ $RES_BYTES -lt 100000000 ]; then
 echo "***********"
 echo "** ERROR **"
 echo "***********"
 echo "Sorry! There are not enough total of shared memory segments allocated for
HugePages configuration. HugePages can only be used for shared memory segments
that you can list by command:
 # ipcs -m
of a size that can match an Oracle Database SGA. Please make sure that:
* Oracle Database instance is up and running
* Oracle Database 11g Automatic Memory Management (AMM) is not configured"
 exit 1
fi
# Finish with results
case $KERN in
 '2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
 echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;
 '2.6') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
 '3.8') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
 '3.10') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
 '4.1') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
 '4.14') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
 '4.18') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
 '5.4') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
 *) echo "Kernel version $KERN is not supported by this script (yet). Exiting." ;;
esac
# End

dm-delay 模拟慢速磁盘

速查

# 创建一个 10G 大小的 ram disk
sudo modprobe brd rd_nr=1 rd_size=1048576
sudo blockdev --getsize /dev/ram0

# 创建 delayed dm,延迟为 500ms
export RAM_SIZE=$(blockdev --getsize /dev/ram0)
echo "0 $RAM_SIZE delay /dev/ram0 0 500" | sudo dmsetup create delayed

# 重新加载参数
echo "0 $RAM_SIZE delay /dev/ram0 0 500" | sudo dmsetup reload delayed

delayed 参数

<device> <offset> <delay> [<write_device> <write_offset> <write_delay> [<flush_device> <flush_offset> <flush_delay>]]

暂停 I/O

sudo dmsetup suspend /dev/dm-0
sudo dmsetup resume  /dev/dm-0

检查 delayed 设备的 I/O 延迟

fio --name a --filename=/dev/dm-0 --bs=4k --rw=randread --ioengine=libaio --direct=1 --iodepth=1 --numjobs=1 --time_based=1 --runtime=10
fio --name a --filename=/dev/dm-0 --bs=4k --rw=randread --ioengine=sync --direct=1 --iodepth=1 --numjobs=1 --time_based=1 --runtime=10

允许 perf 采集内核回溯

出现以下报错时:

Perf-based stall detector creation failed (EACCESS), try setting /proc/sys/kernel/perf_event_paranoid to 1 or less to enable kernel backtraces: falling back to posix timer.

perf_event_paranoid 设为 1:

sudo sh -c 'echo 1 > /proc/sys/kernel/perf_event_paranoid'

修复 xfs.h 的 void 指针算术错误

Clang 编译 XFS 头文件时,void * 不能直接参与指针算术。将:

void *next = ((void *)gpr + gpr->gpr_reclen);
return next;

改为:

void *next = ((char *)gpr + gpr->gpr_reclen);
return (struct xfs_getparents_rec *)next;

使用 nftables 模拟丢包

丢弃目标端口的入站 TCP 流量:

sudo nft create table ip filter
sudo nft add chain ip filter input { type filter hook input priority 0 \; }
sudo nft add rule ip filter input tcp dport 3888 counter drop

恢复前先查看 handle,再删除对应规则:

sudo nft list chain ip filter input
sudo nft delete rule ip filter input handle n

系统编程资料