`

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 的使用 `ulimit` 是一个在 Linux 和其他类 Unix 操作系统中常用的命令行工具,用于设置或显示对当前 shell 进程及其子进程的资源限制。这些限制可以包括最大文件大小、最大核心文件大小、最大数据...

    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学习基础教程是针对初学者的一份详尽指南,涵盖了Linux系统的入门知识、基本操作、性能调优以及问题解决策略。Linux是一种广泛使用的开源操作系统,它以其稳定性和灵活性深受开发者和系统管理员的喜爱。本教程...

    linux 学习--句柄学习

    Linux系统通过限制同一时间打开的最大文件数来控制资源的使用,这个限制可以通过`ulimit`命令或者修改`/etc/security/limits.conf`配置文件来调整。同时,每个进程都有一个文件描述符的上限,超过这个上限,进程将...

    获取和修改linux socket最大连接数,linux,系统

    在Linux操作系统中,Socket是进程间通信的一种方式,它提供了网络通信的能力。Socket的最大连接数是一个重要的系统资源限制,关乎到服务器的并发处理能力。本文将深入探讨如何获取和修改Linux Socket的最大连接数,...

    Linux下安装Weblogic

    * 编辑 /etc/profile 文件,添加 oracle 用户的 ulimit 配置 三、创建相关用户和组 * 创建 oinstall 和 dba 组,作为软件安装和支持组的拥有者 * 创建 oracle 用户和密码,添加到 oinstall 和 dba 组 四、安装 ...

    linux系统安装oracle11G完整版

    知识点:sysctl 命令是 Linux 系统中用于设置和查看内核参数的命令,通过执行 sysctl -p 命令,可以使内核参数生效。 5. 编辑 /etc/profile 文件 编辑 /etc/profile 文件,添加 ulimit 命令,以限制 Oracle 用户的...

    linux下安装oracle

    3. 修改 Linux 内核,修改 `/etc/sysctl.conf` 文件,添加以下内容: ``` fs.file-max = 6815744 fs.aio-max-nr = 1048576 kernel.shmall = 2097152 kernel.shmmax = 2147483648 kernel.shmmni = 4096 kernel.sem = ...

    Linux简单调优与JVM参数.docx

    在这里,我们可以通过修改 /etc/sysctl.conf 文件来调整 TCP 参数。例如,我们可以将 net.core.rmem_default 设置为 256960,以提高 TCP 接收缓冲区的大小。 JVM 参数调优 JVM 参数调优是指对 JVM 应用程序的配置...

    并发时-修改Linux系统下的大文件描述符限制

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

    Linux基础学习3

    【Linux基础学习3】主要涉及Linux操作系统的基础知识,特别是文件系统、程序管理和用户资源限制。在这一主题中,我们关注的重点是Linux中的交互式输入、系统资源限制以及shell脚本中的变量操作和历史命令管理。 1. ...

    linux上安装oracle11g详细步骤

    * 编辑 `/etc/sysctl.conf` 文件,添加以下参数: + `Kernel.shmmall=2097152` + `Kernel.shmmax=2147483648` + `Kernel.shmmni=4096` + `Kernel.sem=250 32000 100 128` + `Fs.file-max=6815744` + `Fs.aio-...

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

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

    linux-Linux性能优化实战案例

    在《Linux性能优化实战》案例中,我们深入探讨了如何利用Linux系统工具和技术来提升系统的运行效率和性能。Linux作为一款开源操作系统,其强大的可定制性和丰富的工具集使其成为性能优化的理想平台。以下是一些核心...

    linux打开文件数

    在Linux系统中,对文件的管理是其核心功能之一,其中“打开文件数”是一个重要的概念,涉及到系统资源管理和性能优化。本文将深入探讨Linux如何管理打开文件数,包括查看当前打开文件数的方法、理解系统限制以及如何...

    Linux高性能服务器编程PDF和代码

    理解CPU、内存、磁盘I/O的性能指标,调整系统参数,如ulimit、sysctl等。 6. **并发模型**:了解事件驱动编程(如libevent、libev、libuv)和反应器模式,以及协程(green thread)的概念,这些都是构建高并发...

    Linux_Performance_Tuning.pdf

    Linux性能调优是确保系统在高负载下稳定运行的关键步骤。根据文件内容,我们将探讨Linux系统性能调优的核心知识点,包括不同命令的使用,以及如何调整CPU、内存、磁盘I/O和网络设置。 Linux系统性能调优的介绍 ...

    Linux性能调优指南,IBM专家资深指导

    《Linux性能调优指南》是IBM专家团队倾力打造的一份深入浅出的教程,旨在帮助用户提升...通过学习这份文档,你可以掌握一套完整的Linux性能调优体系,无论是在日常维护还是故障排查中,都能游刃有余地应对各种挑战。

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

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

    linux安装oracle11g

    ### Linux环境下Oracle 11g数据库的安装及配置 #### 一、Linux环境准备 **1. 检查基本需求** 确保服务器满足Oracle 11g的基本硬件要求,包括但不限于内存大小和交换分区大小。 - **内存大小**: 可以通过`grep ...

Global site tag (gtag.js) - Google Analytics