zoukankan      html  css  js  c++  java
  • 修改程序ulimit限制(不重启应用)

    由于线上应用特殊,不能随意重启,找到2种动态修改程序ulimits限制的方法。下面举例修改nginx的core file大小限制

    方法一:prlimit工具修改

    #安装新版本的util-linux,由于util-linux版本需要大于等于2.21以上才支持prlimit命令(如果系统有此命令请忽略安装步骤)。
    cd /usr/local/src
    wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.27/util-linux-2.27.1.tar.gz
    tar -zxvf util-linux-2.27.1.tar.gz
    cd util-linux-2.27.1
    ./configure --prefix=/usr/share/doc/util-linux-2.27
    make && make install
    cd /usr/share/doc/util-linux-2.27/bin && cp prlimit /usr/bin/
    
    #找出nginx进程
    root@VM-131-5-ubuntu:/etc/security# ps -ef |grep nginx |grep -v grep
    root      6034     1  0 17:16 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
    nginx     6037  6034  0 17:16 ?        00:00:00 nginx: worker process      
    
    #找到进程的core文件大小限制
    root@VM-131-5-ubuntu:/etc/security# cat /proc/6034/limits  |grep core
    Max core file size        0                    unlimited            bytes     
    
    #使用prlimit命令修改core文件大小限制
    root@VM-131-5-ubuntu:/etc/security# prlimit -p 6034 --core=unlimited: 
    
    #再次查看该nginx进程的core文件大小限制
    root@VM-131-5-ubuntu:/etc/security# cat /proc/6034/limits  |grep core
    Max core file size        unlimited            unlimited            bytes  
     
    
    方法二:python3+ resource模块
    
    #找出nginx进程
    root@VM-131-5-ubuntu:/etc/security# ps -ef |grep nginx |grep -v grep
    root     16436     1  0 13:01 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
    nginx    16439 16436  0 13:01 ?        00:00:00 nginx: worker process                   
    
    #找到进程的core文件大小限制
    root@VM-131-5-ubuntu:/etc/security# cat /proc/16436/limits  |grep core
    Max core file size        0                    unlimited            bytes  
    
    #利用python3 resource模块修改core文件大小限制
    root@VM-131-5-ubuntu:/etc/security# python3
    Python 3.4.3 (default, Nov 12 2018, 22:25:49) 
    [GCC 4.8.4] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import resource
    >>> resource.prlimit(16436,resource.RLIMIT_CORE,(-1,-1))   
    (0, -1)
    >>> exit()
    
    
    #再次查看该nginx进程的core文件大小限制
    root@VM-131-5-ubuntu:/etc/security# cat /proc/16436/limits |grep core 
    Max core file size     unlimited         unlimited       bytes
    
    #调整句柄
    resource.RLIMIT_NOFILE
  • 相关阅读:
    (OK)(OK) running two Android-x86 in VirtualBox, they connect to NS3(MANETs) via "ethernet bridge"
    (OK) running two Android-x86 in VirtualBox, they connect to "ethernet bridge"
    (OK) virtualbox — VBoxManage internalcommands — with UUID already exists
    (OK) netcat transfer file to android from fedora23
    Setting VirtualBox to use it's built-in VNC server (ver. >= 4.2 I think)
    (OK) Android 6.0 (Marshmallow) Install apk
    netcat——Useful netcat examples on Linux
    Android下pm 命令详解
    (OK) Ubuntu 15.10: KVM vs. Xen vs. VirtualBox Virtualization Performance
    Virtualization solutions on Linux systems
  • 原文地址:https://www.cnblogs.com/xingxiz/p/10364706.html
Copyright © 2011-2022 走看看