# Ubuntu 系统初始化

```bash
# 设置系统进程和文件描述符限制
echo '* soft noproc 655350' | sudo tee -a /etc/security/limits.conf
echo '* hard noproc 655350' | sudo tee -a /etc/security/limits.conf
echo '* soft nofile 655350' | sudo tee -a /etc/security/limits.conf
echo '* hard nofile 655350' | sudo tee -a /etc/security/limits.conf
  
# 为 root 用户设置进程和文件描述符限制
echo 'root soft noproc 655350' | sudo tee -a /etc/security/limits.conf
echo 'root hard noproc 655350' | sudo tee -a /etc/security/limits.conf
echo 'root soft nofile 655350' | sudo tee -a /etc/security/limits.conf
echo 'root hard nofile 655350' | sudo tee -a /etc/security/limits.conf
  
# 设置 systemd 的文件描述符限制
echo 'DefaultLimitNOFILE=655360' | sudo tee -a /etc/systemd/user.conf
echo 'DefaultLimitNOFILE=655360' | sudo tee -a /etc/systemd/system.conf
echo "session required pam_limits.so" >> /etc/pam.d/common-session
echo "session required pam_limits.so" >> /etc/pam.d/common-session-noninteractive

  
# 设置 ulimit 限制
echo 'ulimit -HSn 1024000' | sudo tee -a /etc/profile.d/limits.sh
chmod +x /etc/profile.d/limits.sh
```

<pre class="language-bash"><code class="lang-bash"><strong>$ cat /etc/sysctl.conf
</strong><strong>vm.swappiness = 0
</strong>kernel.sysrq = 1

net.ipv4.tcp_mtu_probing = 1
net.ipv4.neigh.default.gc_stale_time = 120
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_slow_start_after_idle = 0

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
#net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_max_tw_buckets = 5000
net.core.somaxconn = 32768
net.ipv4.tcp_max_syn_backlog = 56384
net.core.netdev_max_backlog = 56384
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.optmem_max = 16777216
net.ipv4.tcp_rmem = 1024 4096 16777216
net.ipv4.tcp_wmem = 1024 4096 16777216
net.ipv4.ip_local_port_range = 1024 65535
net.netfilter.nf_conntrack_max = 1000000
fs.file-max = 655350
</code></pre>

```bash
reboot
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/centos/shell/ubuntu-xi-tong-chu-shi-hua.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
