服务器中 ulimit 的配置

系统级别 查看并修改 ulimit

ulimit

ulimit -a 
# 命令的输出信息: 
# core file size           (blocks, -c) 0
# data seg size            (kbytes, -d) unlimited  # 一个进程的数据段的最大值
# scheduling priority              (-e) 0
# file size                (blocks, -f) unlimited  # Shell创建文件的最大体积, 1block = 512bytes
# pending signals                  (-i) 1031426    # 最多允许多少个待处理的信号
# max locked memory        (kbytes, -l) 64         # 每个进程可以锁住的物理内存的最大值
# max memory size          (kbytes, -m) unlimited  # 每个进程可以使用的常驻内存的最大值
# open files                       (-n) 65536      # 每个进程可以同时打开的最大文件数, 不能是unlimited
# pipe size             (512 bytes, -p) 8          # 管道的最大值, 1block = 512bytes
# POSIX message queues      (bytes, -q) 819200     # POSIX的消息队列的最大值
# real-time priority               (-r) 0
# stack size               (kbytes, -s) 10240      # 单个进程能够使用的最大栈大小
# cpu time                (seconds, -t) unlimited  # 单个进程的最大CPU时间, 也就是可使用CPU的秒数, 到硬极限时, 这个进程就会立即自杀; 到软极限时, 每秒发送一次限制超时信号SIGXCPU
# max user processes               (-u) 131072     # 单个用户可同时运行的最大进程数, 不能是unlimited
# virtual memory           (kbytes, -v) unlimited  # 每个进程可使用的最大虚拟内存
# file locks                       (-x) unlimited  # 每个进程能锁住的最大文件个数

修改 ulimit

sed -i '/\# End of file/i * soft nofile 65535' /etc/security/limits.conf
sed -i '/\# End of file/i * hard nofile 65535' /etc/security/limits.conf
echo ulimit -SHn 65535 >> /etc/profile
source /etc/profile

查看 nginx ulimit

# ps aux | awk '{print $11}'
# netstat -anlp | grep 80 | awk '{print $7}' | grep nginx
# netstat -anlp | grep nginx | grep 80 | awk '{print $7}'  | awk '{split($0,a,"/");print a[1]}'

cat  /proc/$(cat /var/run/nginx.pid)/limits
# Limit                     Soft Limit           Hard Limit           Units
# Max cpu time              unlimited            unlimited            seconds
# Max file size             unlimited            unlimited            bytes
# Max data size             unlimited            unlimited            bytes
# Max stack size            8388608              unlimited            bytes
# Max core file size        0                    unlimited            bytes
# Max resident set          unlimited            unlimited            bytes
# Max processes             13165                13165                processes
# Max open files            65535                65535                files
# Max locked memory         65536                65536                bytes
# Max address space         unlimited            unlimited            bytes
# Max file locks            unlimited            unlimited            locks
# Max pending signals       13165                13165                signals
# Max msgqueue size         819200               819200               bytes
# Max nice priority         0                    0
# Max realtime priority     0                    0
# Max realtime timeout      unlimited            unlimited            us

grep 'open files' /proc/$(cat /var/run/nginx.pid)/limits

# Max open files            1024                 4096                 files

vim /usr/lib/systemd/system/nginx.service

# 在[Service]模块下添加

# LimitNOFILE=65535

systemctl daemon-reload 
systemc	restart nginx

grep 'open files' /proc/$(cat /var/run/nginx.pid)/limits
# Max open files            65535                65535                files 


# 查看某个进程打开的文件及文件描述符
ll proc/$(cat /var/run/nginx.pid)/fd
ll proc/430315/fd

tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/access.json

tail -f /var/log/nginx/error.log

curl http://t1.wwwfff.top/get_json
curl http://119.29.161.77/get_json

curl http://127.0.0.1/get_text

# https://t1.wwwfff.top/my/wql.html

参考

https://blog.csdn.net/qq_43233213/article/details/104379607

https://zhuanlan.zhihu.com/p/60799795

https://www.cnblogs.com/grey-wolf/p/13335275.html

排查规则错误

posted @ 2025-04-22 11:56  cerofang  阅读(36)  评论(0)    收藏  举报