centos之Too many open files問題-修改linux最大檔案控制代碼數

來源:互聯網
上載者:User

標籤:io   os   ar   使用   sp   strong   檔案   on   問題   

linux伺服器大並發調優時,往往需要預先調優linux參數,其中修改linux最大檔案控制代碼數是最常修改的參數之一。

在linux中執行ulimit -a 即可查詢linux相關的參數,如下所示:

[[email protected] ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 256324
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 256324
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

預設情況下,linux最大檔案控制代碼數為1024個。當你的伺服器在大並發達到極限時,就會報出“too many open files”。

那麼如何修改linux最大檔案控制代碼數呢?其實很簡單:

1、ulimit -n 2048

這命令就可以修改linux最大檔案控制代碼數,修改以後使用ulimit -a 查看修改的狀態,如:

[[email protected] ~]# ulimit -n 2048
[[email protected] ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 256324
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 2048
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 256324
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

但是,這種方法只針對當前進程有效。重新開啟一個shell或者開啟一個進程,你就會發現參數還是ulimit -n xx修改之前的數字。那麼有沒有一勞永逸的方法呢?

當然有!那就是修改系統參數。

2、修改linux系統參數。vi /etc/security/limits.conf 添加

*  soft  nofile  65536

*  hard  nofile  65536

修改以後儲存,登出目前使用者,重新登入,執行ulimit -a ,ok ,參數生效了:

[[email protected] ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 256600
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 256600
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

註:

硬限制表明soft限制中所能設定的最大值。 soft限制指的是當前系統生效的設定值。 hard限制值可以被普通使用者降低。但是不能增加。 soft限制不能設定的比hard限制更高。 只有root使用者才能夠增加hard限制值。

可以最大設到:

655350

centos之Too many open files問題-修改linux最大檔案控制代碼數

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.