首页 > 为什么无法修改ulimit的值?

为什么无法修改ulimit的值?

问题已解决。因为我是root登录的。怎么改都没效果。以其他用户登录时的确是已经修改过的。所以我是这么配置的

* - nofile 65535
root - nofile 65535

==================分割线:原问题 /ect/security/limits.conf:

* - nofile 65535
* - nproc 65535

/etc/sysctl.conf:

fs.file-max=65535

系统重启后。ulimit -a max open files仍然是1024


CentOS嘛?試試這個可否:

cat<< EOF >> /etc/security/limits.conf

*       soft    nofile  65535
*       hard    nofile  65535

EOF

如果这个问题是发生在SSH session里的话,那么可能是SSH服务器没有配置为使用PAM (UsePAM yes)而导致。

/etc/security/limits.conf是给pam_limits模块使用的配置文件(参考man limits.conf)。
对于SSH session来说,要使limits.conf生效,则必须确保SSH服务器的配置中UsePAM的选项是有效的。
编辑/etc/ssh/sshd_config,确认以下的行有效:

UsePAM yes

更改配置后重启SSH服务器:

/etc/init.d/sshd restart

顺便提两点和解决这个问题没有直接关系的:
1. 要使limits.conf的更改生效,不需要重启系统。只要重新登录就可以。
2. 一个比较笨的规避方法是在当前用户的.bashrc里加入ulimit -n 65535,:)



cp /etc/sysctl.conf /etc/sysctl.conf.bak
cat >> /etc/sysctl.conf <<EOF
# Add
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog =  32768
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535
EOF

#使用更改生效:
sysctl -p

##  系统限制(limits)参数设置
#-------------------------------------------------------------------------------
cat >> /etc/security/limits.conf <<EOF
# Add
* soft nproc 10240
* hard nproc 10240
* soft nofile 10240
* hard nofile 10240
#
EOF

fs.file-max=65535
【热门文章】
【热门文章】