http://www.linuxhowtos.org/Tips%20and%20Tricks/ulimit.htm 写道
ulimit and sysctl
The ulimit and sysctl programs allow to limit system-wide resource use. This can help a lot in system administration, e.g. when a user starts too many processes and therefore makes the system unresponsive for other users.
Code Listing 1: ulimit example
# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 8191
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 8191
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
All these settings can be manipulated. A good example is this bash forkbomb that forks as many processes as possible and can crash systems where no user limits are set:
Warning: Do not run this in a shell! If no limits are set your system will either become unresponsive or might even crash.
Code Listing 2: A bash forkbomb
$ :(){ :|:& };:
Now this is not good - any user with shell access to your box could take it down. But if that user can only start 30 processes the damage will be minimal. So let's set a process limit:
Gentoo Note: A too small number of processes can break the use of portage. So, don't be too strict.
Code Listing 3: Setting a process limit
# ulimit -u 30
# ulimit -a
…
max user processes (-u) 30
…
If you try to run the forkbomb now it should run, but throw error messages "fork: resource temporarily unavailable". This means that your system has not allowed the forkbomb to start more processes. The other options of ulimit can help with similar problems, but you should be careful that you don't lock yourself out - setting data seg size too small will even prevent bash from starting!
sysctl is a similar tool: It allows to configure kernel parameters at runtime. If you wish to keep settings persistent across reboots you should edit /etc/sysctl.conf - be aware that wrong settings may break things in unforeseen ways.
Code Listing 4: Exploring sysctl variables
# sysctl -a
…
vm.swappiness = 60
…
The list of variables is quite long (367 lines on my system), but I picked out vm.swappiness here. It controls how aggressive swapping will be, the higher it is (with a maximum of 100) the more swap will be used. This can affect performance a lot on systems with little memory, depending on load and other factors.
Code Listing 5: Reducing swappiness
# sysctl vm.swappiness=0
vm.swappiness = 0
The effects of changing this setting are usually not felt instantly. But you can change many settings, especially network-related, this way. For servers this can offer a nice performance boost, but as with ulimit careless usage might cause your system to misbehave or slow down. If you don't know what a variable controls, you should not modify it!
分享到:
相关推荐
linux_ulimit的使用 linux_ulimit的使用 linux_ulimit的使用
Linux ulimit命令 Linux ulimit命令用于控制shell程序的资源。 ulimit为shell内建指令,可用来控制shell执行程序的资源。 语法 ulimit [-aHS][-c ][-d ][-f ][-m ][-n ][-p ][-s ][-t ][-u ][-v ] 参数: -a 显示...
通常我们通过终端连接到linux系统后执行ulimit -n 命令可以看到本次登录的session其文件描述符的限制,如下: $ulimit -n 1024 当然可以通过ulimit -SHn 102400 命令来修改该限制,但这个变更只对当前的...
Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。 Linux命令分类 这里存放Linux 命令大全并不全,你可以通过linux-command来搜索,它是把 command 目录里面搜集的...
设置Linux打开文件句柄/proc/sys/fs/file-max和ulimit -n的区别表示系统级别的能够打开的文件句柄的数量.是对整个系统的限制,并不是
/usr/bin/ulimit -a ``` 在limits.conf文件中添加以下行: ``` * soft nofile 8000 * hard nofile 65535 ``` 这将提高操作系统的文件描述符限制。 二、内核参数调整 在安装NBU for Linux 86_64之前,需要调整内核...
Git是一个分布式版本控制系统 先决条件 在macOS上安装 brew update && brew install hugo # Update ulimit sudo sysctl -w kern.maxfiles=65536 sudo sysctl -w kern....在Linux上安装 # Update ulimit sudo sysctl
永久修改进程打开文件最大值限制自动化配置脚本,是linux服务器/阿里云新机器必修改选项,安装redis, kafka,elasticsearch等服务器必改
有助于管理ulimit配置的角色。 例子 --- # Example of how to use the role - hosts: myhost vars: ulimit_config: - domain: '*' type: soft item: core value: 0 - domain: '*' type: hard item: rss ...
本文档详细介绍了虚拟机环境下安装alpine linux,同时在alpine里安装docker环境,不是单纯的配置docker下的alpine容器
linux的最大进程句柄数设置在Linux下,我们使用ulimit -n命令可以看到单个进程能够打开的最大文件句柄数量(socket连接也算在里面)。系统默认值1024。
看下linux主机上的ulimit-n的数据是多少,为改动过的是1024,最好要改的大一点。这个是linux下最大线程数,如果过小的话无法进行大并量的测试。 首先确定下做压力测试的工具和性能的监控工具,这个压测的工具使用...
Linux命令大全完整版 目 录 目 录 I 1. linux系统管理命令 1 adduser 1 chfn(change finger information) 1 chsh(change shell) 1 date 2 exit 3 finger 4 free 5 fwhois 5 gitps(gnu interactive tools ...
Linux too many open files 解决方案 Linux 系统中的打开文件数量限制问题是系统对程序打开文件数量的限制问题。这个限制可以通过 `ulimit -a` 命令来查看。默认情况下,Linux 系统的打开文件数量限制是 1024,可以...
ulimit -n 这个数字说明了一个普通用户能够在一个单独会话中所能打开最大的文件数目。注意。如果是root,以下操作不能使ulimit -n的输出增加。因为用户root用户不受这个ulimit限制。只有普通用户才会受这个限制。
用于测试服务器连接上限。linux服务器通过 ulimit -n 查看最大连接数。用这个程序来验证
验证-ulimit 验证当前 ulimit。
此外,Linux 系统中还存在 ulimit 命令,用于控制进程级别的资源使用,包括文件句柄数量、进程数量、core 文件大小等。ulimit 命令可以控制进程可以打开的文件句柄的数量,以免进程打开太多的文件句柄导致“Too many...
1. 之前用过的方法DbgHelp、qBreakpad生成Dump、Linux下配置ulimit -c unlimited生成core的方式功能都比较单一,并且需要配置环境,在程序中调用库,使用较为复杂。 2. 而ProcDump 使用非常简单,不需要配置环境,不...
1. 之前用过的方法DbgHelp、qBreakpad生成Dump、Linux下配置ulimit -c unlimited生成core的方式功能都比较单一,并且需要配置环境,在程序中调用库,使用较为复杂。 2. 而ProcDump 使用非常简单,不需要配置环境,不...