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=>

[参考]
相关文章
|
7月前
|
网络协议 Linux 网络安全
【Linux环境】centos出现“FirewallD is not running”怎么办,如何解决
【Linux环境】centos出现“FirewallD is not running”怎么办,如何解决
222 0
|
12月前
|
网络协议 Ubuntu 关系型数据库
centos出现“FirewallD is not running”怎么办
centos出现“FirewallD is not running”怎么办
157 0
|
2天前
|
安全 Linux 开发者
CentOS 7安装全解析:适合初学者的指导
CentOS 7安装全解析:适合初学者的指导
|
2天前
|
关系型数据库 MySQL Linux
在Centos7中:通过Docker安装MySQL5.7(保姆级)
在Centos7中:通过Docker安装MySQL5.7(保姆级)
|
2天前
|
存储 安全 Linux
Centos停止更新?这篇博客教会你安装平替Centos的操作系统安装Anolis
Centos停止更新?这篇博客教会你安装平替Centos的操作系统安装Anolis
|
4天前
|
关系型数据库 MySQL Linux
Linux CentOs7 安装Mysql(5.7和8.0版本)密码修改 超详细教程
Linux CentOs7 安装Mysql(5.7和8.0版本)密码修改 超详细教程
|
9天前
|
运维 安全 Linux
如何在CentOS7一键安装宝塔面板并实现固定地址访问内网宝塔进行管理
如何在CentOS7一键安装宝塔面板并实现固定地址访问内网宝塔进行管理
|
9天前
|
Linux 测试技术 数据安全/隐私保护
CentOS安装MeterSphere并实现无公网IP远程访问本地测试平台
CentOS安装MeterSphere并实现无公网IP远程访问本地测试平台

热门文章

最新文章