`

linux 学习の ulimit and sysctl

阅读更多
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!
 
1
3
分享到:
评论
2 楼 vb2005xu 2012-12-12  
http://py.qq.com/web/ QQ 云输入法
1 楼 vb2005xu 2012-12-12  
http://baike.baidu.com/view/225343.htm grub 使用指南

相关推荐

    linux_ulimit的使用

    linux_ulimit的使用 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系统下的大文件描述符限制

    通常我们通过终端连接到linux系统后执行ulimit -n 命令可以看到本次登录的session其文件描述符的限制,如下:  $ulimit -n  1024  当然可以通过ulimit -SHn 102400 命令来修改该限制,但这个变更只对当前的...

    Linux命令搜索工具linux-command.zip

    Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。   Linux命令分类 这里存放Linux 命令大全并不全,你可以通过linux-command来搜索,它是把 command 目录里面搜集的...

    marmot-cn#readingNotes#设置linux打开文件句柄:proc:sys:fs:file-max和ulimit

    设置Linux打开文件句柄/proc/sys/fs/file-max和ulimit -n的区别表示系统级别的能够打开的文件句柄的数量.是对整个系统的限制,并不是

    gitdvcs.com:Git是一个分布式版本控制系统

    Git是一个分布式版本控制系统 先决条件 在macOS上安装 brew update && brew install hugo # Update ulimit sudo sysctl -w kern.maxfiles=65536 sudo sysctl -w kern....在Linux上安装 # Update ulimit sudo sysctl

    ulimit nr_open 自动化配置脚本

    永久修改进程打开文件最大值限制自动化配置脚本,是linux服务器/阿里云新机器必修改选项,安装redis, kafka,elasticsearch等服务器必改

    ansible-ulimit:有助于管理 ulimit 配置的角色

    有助于管理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 ...

    linux的最大进程句柄数设置

    linux的最大进程句柄数设置在Linux下,我们使用ulimit -n命令可以看到单个进程能够打开的最大文件句柄数量(socket连接也算在里面)。系统默认值1024。

    linux下使用ab进行压力测试

    看下linux主机上的ulimit-n的数据是多少,为改动过的是1024,最好要改的大一点。这个是linux下最大线程数,如果过小的话无法进行大并量的测试。  首先确定下做压力测试的工具和性能的监控工具,这个压测的工具使用...

    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 ...

    增加系统的最大打开文件数

    ulimit -n 这个数字说明了一个普通用户能够在一个单独会话中所能打开最大的文件数目。注意。如果是root,以下操作不能使ulimit -n的输出增加。因为用户root用户不受这个ulimit限制。只有普通用户才会受这个限制。

    alpine下配置docker环境

    本文档详细介绍了虚拟机环境下安装alpine linux,同时在alpine里安装docker环境,不是单纯的配置docker下的alpine容器

    scoket端口检测

    用于测试服务器连接上限。linux服务器通过 ulimit -n 查看最大连接数。用这个程序来验证

    verify-ulimit:验证当前 ulimit

    验证-ulimit 验证当前 ulimit。

    C++(Qt)软件崩溃调试-学会使用ProcDump (5)20230402.pdf

    1. 之前用过的方法DbgHelp、qBreakpad生成Dump、Linux下配置ulimit -c unlimited生成core的方式功能都比较单一,并且需要配置环境,在程序中调用库,使用较为复杂。 2. 而ProcDump 使用非常简单,不需要配置环境,不...

    C++(Qt)软件崩溃调试-学会使用ProcDump(5)20230403.pdf

    1. 之前用过的方法DbgHelp、qBreakpad生成Dump、Linux下配置ulimit -c unlimited生成core的方式功能都比较单一,并且需要配置环境,在程序中调用库,使用较为复杂。 2. 而ProcDump 使用非常简单,不需要配置环境,不...

    ulimit设置句柄数

    放到服务器上运行一段时间抛出Toomanyopenfiles的异常。...放到服务器上运行一段时间抛出Toomanyopenfiles的异常。  异常信息简单的信息如下:  I/Oexception(java.net.SocketException)caughtwhenprocessingrequest:...

    ulimit命令 控制shell程序的资源

    为提高性能,可以根据设备资源情况,设置各linux用户的最大进程数,我们可以用ulimit来显示当前的各种用户进程限制。 ulimit为shell内建命令,可用来控制shell执行程序的资源。 语法格式:ulimit [参数] 常用参数...

    Linux命令大全(CHM格式离线版)

    Linux命令大全(CHM格式离线版) Linux命令大全(修改版) 进行重新编译的说明 文件传输 bye ftp ftpcount ftpshut ftpwho ncftp tftp uucico uucp uupick uuto 备份压缩 ar bunzip2 bzip2 bzip2recover compress cpio ...

Global site tag (gtag.js) - Google Analytics