
实验 *** 作:
1、查看打开文件的限制数 ulimit -a
显示文件的打开数项为open files (-n) 1024修改
2、修改
临时生效:ulimit -n 65536 (不需要设,直接设置永久)
永久生效:
vim /etc/security/limits.conf添加
* soft nofile 65536
* hard nofile 65536
vim /etc/sysctl.conf中添加fs.file-max=655350
/sbin/sysctl -p 使立即生效
cat /proc/sys/fs/file-max 查看是否设置成功
3、ubuntu的一个问题记录
用到使LInux的文件打开数为65534个,而且需要永久生效,于是将配置写到了:
vim /etc/security/limits.conf
* soft nofile 65534
* hard nofile 65534
重新登录后limit.conf的配置都不生效,后来发现,ubuntu有个bug,root用户必须注明用户
root soft nofile 65534
root hard nofile 65534
也就是写成上面那样,重新登录,不需要重启,ulimit -a可以看到文件打开数已经是65534了,这就是limits.conf不生效的原因,注 意ubuntu一定不能直接用*
limits.conf文件实际是
Linux
PAM(插入式认证模块,Pluggable
Authentication
Modules)中
pam_limits.so
的配置文件,而且只针对于单个会话。limits.conf的格式如下:username@groupname
type
resource
limitusername@groupname:设置需要被限制的用户名,组名前面加@和用户名区别。也可以用通配符*来做所有用户的限制。type:有
soft,hard
和
-,soft
指的是当前系统生效的设置值。hard
表明系统中所能设定的最大值。soft
的限制不能比har
限制高。用
-
就表明同时设置了
soft
和
hard
的值。resource:core
-
限制内核文件的大小date
-
最大数据大小fsize
-
最大文件大小memlock
-
最大锁定内存地址空间nofile
-
打开文件的最大数目rss
-
最大持久设置大小stack
-
最大栈大小cpu
-
以分钟为单位的最多
CPU
时间noproc
-
进程的最大数目as
-
地址空间限制maxlogins
-
此用户允许登录的最大数目要使
limits.conf
文件配置生效,必须要确保
pam_limits.so
文件被加入到启动文件中。查看
/etc/pam.d/login
文件中有:ls
/lib/security/pam_limits.so
如果不作限制,可能一行代码就让你很惨了,甚至需要你重启一下。
你可以把下面这行代码复制粘贴到终端里执行测试一下是否需要限制
:(){
::
}
:例如我的:*
soft
core
0*
hard
rss
102400truth
soft
nproc
2047truth
hard
nproc
16384truth
soft
nofile
1024truth
hard
nofile
65536truth
hard
cpu
10同时编辑sudo
gedit
/etc/pam.d/login加入#禁止调试文件session
required
/lib/security/pam_limits.so系统重启后可尝试
:(){
::
}
:这时会出现bash:
fork:
资源临时不可用
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)