> For AI agents: the complete documentation index is available at https://www.tteam.icu/llms.txt, the full documentation bundle is available at https://www.tteam.icu/llms-full.txt.

# 内核参数调优

## 端口范围与保留配置

在高性能网络服务（如 API 网关、数据库连接池、微服务集群）中，通常需要对本地临时端口的分配策略进行优化。

:::tip
可以使用例如`sysctl -w net.ipv4.ip_local_port_range="30000 39999"`来临时修改参数

如果要永久修改，统一在 `/etc/sysctl.d/99-network-tuning.conf` 中管理（或追加至 `/etc/sysctl.conf`），然后执行`sysctl -p`来应用
:::

```ini
# ====================================================================
# 本地临时端口与保留端口配置
# ====================================================================

# 1. 自定义本地临时端口范围 (Ephemeral Ports)
# 默认值通常为: 32768 60999
# 作用: 规定了系统作为客户端发起主动连接时，允许自动分配的本地随机端口区间。
net.ipv4.ip_local_port_range = 30000 39999

# 2. 自定义系统保留端口 (Reserved Ports)
# 作用: 显式声明系统完全保留的端口区间。内核在自动分配临时端口时，会绝对避开此区间。
# 场景: 防止某些固定服务（如 Redis、自定义中间件）在启动时，其常用端口被系统提前随机占用。
net.ipv4.ip_local_reserved_ports = 40000-45000
```
