CentOS 6.x limits changed on a existing running process

简介:
前段时间发了一篇关于CentOS 6.x ulimit配置文件变更为/etc/security/limits.d/90-nproc.conf  的文章.
但是如果你的系统中已经存在的进程的nproc是不会被变更过来的. 例如一个数据库服务器.
PostgreSQL所有的backend process都是从postmaster进程fork出来的, 如果postmaster进程的nproc还是老的配置的话, 资源限制依旧存在, 例如.
> psql
psql: could not fork new process for connection: Resource temporarily unavailable

could not fork new process for connection: Resource temporarily unavailable
这种情况通过修改 /etc/security/limits.d/90-nproc.conf是无法实现的, 
* soft    nproc   131072
* hard    nproc   131072
但是又不能重启数据库进程怎么办呢?
只要你的内核够新2.6.32+, 那么就可以通过编辑进程的limits来实现.
例如
> ps -ewf|grep postgres
postgres  5721  5720  0 Feb26 ?        19:11:05 postgres: logger process   
主进程号是5720
# cd /proc/5720
# cat 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            10485760             unlimited            bytes     
Max core file size        unlimited            unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             1024                 131072               processes 
Max open files            131072               131072               files     
Max locked memory         51200000000          51200000000          bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       256607               256607               signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        
软限制还是1024, 修改方法
# echo -n "Max processes=131072:131072" > limits
# cat 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            10485760             unlimited            bytes     
Max core file size        unlimited            unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             131072               131072               processes 
Max open files            131072               131072               files     
Max locked memory         51200000000          51200000000          bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       256607               256607               signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        
千万不要直接编辑这个文件.

限制问题解决了, 不会再报资源不足的错误.
> psql
psql (9.3.3)
Type "help" for help.
postgres=>

[参考]
相关文章
|
9月前
|
缓存 监控 网络协议
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(一)
译|Monitoring and Tuning the Linux Networking Stack: Sending Data
63 0
|
9月前
|
监控 Linux 调度
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(八)
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(八)
68 0
|
9月前
|
缓存 监控 网络协议
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(五)
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(五)
78 0
|
9月前
|
缓存 监控 Linux
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(九)
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(九)
133 0
|
9月前
|
缓存 监控 网络协议
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(四)
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(四)
66 1
|
9月前
|
存储 监控 网络协议
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(三)
译|Monitoring and Tuning the Linux Networking Stack: Sending Data(三)
76 0
failed to start lsb:bring up/down
centos 7 有的时候重启网络报错,failed to start lsb:bring up/down 解决方法: systemctl stop NetworkManager
Running Homebrew as root is extremely dangerous and no longer supported.
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/81113749 ...
2665 0
Starting a Gradle Daemon, 5 busy and 1 incompatible and 1 stopped Daemons could not be reused, use --status for details FAILURE: Build failed with an
执行gradle build出的问题,查看hs_err_pid11064.log日志文件发现,是电脑的RAM不足导致
3966 0