Linux 中设置打开文件数目限制的方法

 

设置打开文件数目限制是为了避免资源被耗尽,增加安全及稳定性。

 

001、查看软限制

(base) [root@pc1 software]# ulimit -Sn
1024

 

002、查看硬限制

(base) [root@pc1 software]# ulimit -Hn
4096

 

003、设置软限制

(base) [root@pc1 software]# ulimit -Sn 2000
(base) [root@pc1 software]# ulimit -Sn
2000

 

004、设置硬限制

(base) [root@pc1 software]# ulimit -Hn 4000
(base) [root@pc1 software]# ulimit -Hn
4000

 

005、同时设置软硬限制

(base) [root@pc1 software]# ulimit -n 8000
(base) [root@pc1 software]# ulimit -Hn
8000
(base) [root@pc1 software]# ulimit -Sn
8000

 

006、设置永久生效

(base) [root@pc1 software]# echo "ulimit -n 10000" >> ~/.bashrc       ## 写入配置文件,重启系统后仍然生效
(base) [root@pc1 software]# source ~/.bashrc
(base) [root@pc1 software]# ulimit -Hn
10000
(base) [root@pc1 software]# ulimit -Sn
10000

 

 

参考: 

01、https://www.linuxprobe.com/linux-modify-limit-ways.html

 

posted @ 2023-11-12 22:44  小鲨鱼2018  阅读(445)  评论(0编辑  收藏  举报