Linux資源使用配置文件 /etc/security/limits.conf
http://www.linuxidc.com/Linux/2012-05/59489.htm
Linux就這個范兒P561
Linux處於穩定性的考慮,默認情況下對系統資源都做了限制,有一些Linux發行版會保守一些,如果不是很極端的話,盡量不要修改
還有一個限制最大打開文件描述符的地方,通過procfs文件系統來調整 cat /proc/sys/fs/file-max
這個文件主要是用來限制用戶對系統資源的使用,具體的使用方法 man 5 limits.conf,里面便給出了詳細的用法
- user@db-2:~$ cat /etc/security/limits.conf
- # /etc/security/limits.conf
- #
- #Each line describes a limit for a user in the form:
- #
- #<domain> <type> <item> <value>
- #
- #Where:
- #<domain> can be:
- # - an user name
- # - a group name, with @group syntax
- # - the wildcard *, for default entry
- # - the wildcard %, can be also used with %group syntax,
- # for maxlogin limit
- #
- #<type> can have the two values:
- # - "soft" for enforcing the soft limits # 軟限制,必須比硬限制的值要小
- # - "hard" for enforcing hard limits # 硬限制
- #
- #<item> can be one of the following:
- # - core - limits the core file size (KB)
- # - data - max data size (KB)
- # - fsize - maximum filesize (KB)
- # - memlock - max locked-in-memory address space (KB)
- # - nofile - max number of open files # 最大打開的文件數(以文件描敘符,file descriptor計數)
- # - rss - max resident set size (KB)
- # - stack - max stack size (KB)
- # - cpu - max CPU time (MIN)
- # - nproc - max number of processes
- # - as - address space limit
- # - maxlogins - max number of logins for this user
- # - maxsyslogins - max number of logins on the system
- # - priority - the priority to run user process with
- # - locks - max number of file locks the user can hold
- # - sigpending - max number of pending signals
- # - msgqueue - max memory used by POSIX message queues (bytes)
- # - nice - max nice priority allowed to raise to
- # - rtprio - max realtime priority
- #
- #<domain> <type> <item> <value>
- #
- root soft nofile 200000
- root hard nofile 200000
- admin hard nofile 65536
- admin soft nofile 65536
- # End of file
每行的格式:
用戶名/用戶組 類型(硬限制、軟限制) 選項 值
比如很多朋友可能在使用mysql的時候遇到too many open files的錯誤,此時便可以通過將運行mysqld的用戶的 nofile(最大打開文件數)這個值增大一點,例如
db_running_user - nofile 設定一個合理的值
注意上面的第二列 ‘-’表示hard和soft,可以顯示的為soft和hard寫兩行
我這只是舉一個例子,這個文件還可以配置很多資源的使用,但是一般的情況下用默認的就行,當你有特殊需求或者自己對這些參數的來龍去脈又相當了解,你可以去改這些默認的參數,查看當前用戶的這些資源使用限制情況可以使用 ulimit -a(查看ulimit的使用方法,用man ulimit無效,可以用help ulimit)
那么對它的修改什么時候生效呢?每次重新login的時候生效,至於原因則是我參考的那篇文章里面說了。
自己的疑問:
1. 為什么要同時有soft和hard這兩個限制?這個soft和hard應該是代表兩種類型的閥值吧,一定不能超過hard限制,但是可以超過soft限制,有一個hard不就夠了么?
知道設置兩個參數的意義在於:hard是一個上限在運行期間不可以調大但���以調小,而soft只能比hard小,在運行期間可以調大。 我也用mysqld測試過,它讀取的是soft值,但是我又不解的是,既然修改/etc/security/limits.conf要重新login才生效,那么這些修改的意義不就沒有了嗎?因為要重新登錄,意味着服務要重啟
應該是這個解釋比較合理,soft是一個警告值,而hard則是一個真正意義的閥值,超過就會報錯
http://www.linuxidc.com/Linux/2012-05/59489.htm
改最大連接數
vi /etc/security/limits.conf
* hard nproc h1
* hard nofile h1
vi /etc/security/limits.d/90-nproc.conf
* hard nproc h2
echo '* hard nproc 65535' >>/etc/security/limits.conf //centos5 echo '* hard nofile 65535' >>/etc/security/limits.conf echo '* hard nproc 65535' >>/etc/limits.d/90-nproc.conf //centos6
注意: hard nproc h2,root用戶不受nproc 限制
lnmp第二部分
http://www.cnblogs.com/MYSQLZOUQI/p/4996262.html
nginx配置文件
nginx.conf user nobody nobody; //使用哪個用戶和組來啟動子進程 主進程必須是root 1024以下的端口必須是root用戶監聽 worker_processes 2; //開啟多少個子進程 error_log /usr/local/nginx/logs/nginx_error.log crit; //日志級別crit pid /usr/local/nginx/logs/nginx.pid; worker_rlimit_nofile 51200; //打開文件描述符的個數 events { use epoll; //事件模型 worker_connections 6000; 每個worker支持多少連接 曾經設置過10240 nginx做反向代理 導致502錯誤 最好不要設置那么大 }