修改linux 最大文件限制數 ulimit

1)修改當前交互終端的limit值 

查詢當前終端的文件句柄數: ulimit -n 回車,通常的系統默認的1024. 

修改文件句柄數爲65535,ulimit -n 65535.此時系統的文件句柄數爲65535. 

2)將ulimit 值添加到/etc/profile文件中(適用於有root權限登陸的系統) 

爲了每次系統從新啓動時,均可以獲取更大的ulimit值,將ulimit 加入到/etc/profile 文件底部。 

echo ulimit -n 65535 >>/etc/profile 

source /etc/profile    #加載修改後的profile 

ulimit -n     #顯示65535,修改完畢!linux

3)OK,好多朋友都覺得大功告成了,能夠忽然發現本身再次登陸進來的時候,ulimit的值仍是1024,這是爲何呢? 
關鍵的緣由是你登陸的用戶是什麼身份,是否是root用戶,因爲服務器的root用戶權限很大,通常是不能用來登陸的,都是經過本身本人的登陸權限進行登陸,並經過sudo方式切換到root用戶下進行工做。 用戶登陸的時候執行sh腳本的順序: 
/etc/profile.d/file 
/etc/profile 
/etc/bashrc 
/mingjie/.bashrc 
/mingjie/.bash_profile 

因爲ulimit -n的腳本命令加載在第二部分,用戶登陸時因爲權限緣由在第二步還不能完成ulimit的修改,因此ulimit的值仍是系統默認的1024。 

解決辦法: 
修改linux的軟硬件限制文件/etc/security/limits.conf. 

在文件尾部添加以下代碼: bash

* soft nofile 65536服務器

* hard nofile 131072it

* soft nproc 2048登錄

* hard nproc 4096file

相關文章
相關標籤/搜索