/proc/sys目录下存放着大多数内核参数,并且可以在系统运行时进行更改,不过重新启动机器就会失效。/etc/sysctl.conf是一个允许改变正在运行中的Linux系统的接口,它包含一些TCP/IP堆栈和虚拟内存系统的高级选项,修改内核参数永久生效。也就是说/proc/sys下内核文件与配置文件sysctl.conf中变量存在着对应关系。

设置或重新设置联网功能: 如IP转发、IP碎片去除以及源路由检查、TCP/IP堆栈和虚拟内存

sysctl [-n] [-e] -w variable=value

sysctl [-n] [-e] -p <filename> (default /etc/sysctl.conf)

sysctl [-n] [-e] -a

常用参数的意义:

-w   临时改变某个指定参数的值,如 sysctl -w net.ipv4.ip_forward=1

-a   显示所有的系统参数

-p   从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载

如果仅仅是想临时改变某个系统参数的值,可以用两种方法来实现,例如想启用IP路由转发功能:

1) #echo 1 > /proc/sys/net/ipv4/ip_forward

2) #sysctl -w net.ipv4.ip_forward=1

以上两种方法都可能立即开启路由功能,但如果系统重启,或执行了

# service network restart

使用命令,所设置的值即会丢失,如果想永久保留配置,可以修改/etc/sysctl.conf文件。将 net.ipv4.ip_forward=0改为net.ipv4.ip_forward=1

etc/systcl:内核参数说明:

net.ipv4.ip_forward = 0 # 想启用IP路由转发功能

# Do not accept source routing

net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel

kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.

# Useful for debugging multi-threaded applications.

kernel.core_uses_pid = 1

# Disable netfilter on bridges.

#net.bridge.bridge-nf-call-ip6tables = 0

#net.bridge.bridge-nf-call-iptables = 0

#net.bridge.bridge-nf-call-arptables = 0

# Controls the default maxmimum size of a mesage queue

kernel.msgmnb = 65536

# Controls the maximum size of a message, in bytes

kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes

kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages

kernel.shmall = 4294967296

vm.swappiness = 0

net.ipv4.neigh.default.gc_stale_time=120

net.ipv4.conf.all.rp_filter=1

net.ipv4.conf.default.rp_filter=1

net.ipv4.conf.default.arp_announce = 2

net.ipv4.conf.all.arp_announce=2

#允许TIME-WAIT套接字数量的最大值。超过些数字,TIME-WAIT套接字将立刻被清除同时打印警告信息。默认是180000,过多的TIME-WAIT套接字会使webserver变慢

net.ipv4.tcp_max_tw_buckets = 5000

#UDP和TCP连接中本地端口(不包括连接的远端)的取值范围
net.ipv4.ip_local_port_range = 1024  61000

#解决TCP的SYN攻击。与性能无关

net.ipv4.tcp_syncookies = 1

#三次握手建立阶段SYN请求队列的最大长度,默认是1024。设置大一些可以在繁忙时将来不及处理的请求放入队列,而不至于丢失客户端的请求

net.ipv4.tcp_max_syn_backlog = 1024

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_synack_retries = 1

net.ipv4.conf.lo.arp_announce=2

#表示进程(例如一个worker进程)可能同时打开的最大句柄数,直接限制最大并发连接数

fs.file-max=65535

#当keepalive启用时,TCP发送keepalive消息的频率。默认是2个小时。将其调小一些,可以更快的清除无用的连接.
net.ipv4.tcp_keepalive_time = 600

fs.inotify.max_user_instances = 8192

#当服务器主动关闭链接时,socket保持FN-WAIT-2状态的最大时间

net.ipv4.tcp_fin_timeout = 30

#1代表允许将状态为TIME-WAIT状态的socket连接重新用于新的TCP连接。对于服务器来说有意义,因为有大量的TIME-WAIT状态的连接

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.ip_local_port_range = 1024 65000

net.ipv4.route.gc_timeout = 100

net.ipv4.tcp_syn_retries = 1

net.core.somaxconn = 65535

#当网卡接收的数据包的速度大于内核处理的速度时,会有一个队列保存这些数据包。这个参数就是这个队列的最大值。

net.core.netdev_max_backlog = 262144

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_max_orphans = 262144

#net.netfilter.nf_conntrack_max = 1048576

#net.netfilter.nf_conntrack_tcp_timeout_established = 1200

######Edited by wangzizhe#########################

# Avoid a smurf attack

net.ipv4.icmp_echo_ignore_broadcasts = 1

# Turn on protection for bad icmp error messages

net.ipv4.icmp_ignore_bogus_error_responses = 1

# Turn on and log spoofed, source routed, and redirect packets

net.ipv4.conf.all.log_martians = 1

net.ipv4.conf.default.log_martians = 1

# No source routed packets here

net.ipv4.conf.all.accept_source_route = 0

#net.ipv4.conf.default.accept_source_route = 0

# Turn on reverse path filtering

#net.ipv4.conf.all.rp_filter = 1

#net.ipv4.conf.default.rp_filter = 1

# Make sure no one can alter the routing tables

net.ipv4.conf.all.accept_redirects = 0

net.ipv4.conf.default.accept_redirects = 0

net.ipv4.conf.all.secure_redirects = 0

net.ipv4.conf.default.secure_redirects = 0

# Don’t act as a router

#net.ipv4.ip_forward = 0

net.ipv4.conf.all.send_redirects = 0

net.ipv4.conf.default.send_redirects = 0

# Turn on execshild

kernel.exec-shield = 1

kernel.randomize_va_space = 1

# Optimization for port usefor LBs

# Increase system file descriptor limit

#fs.file-max = 65535

# Allow for more PIDs (to reduce rollover problems); may break some programs 32768

kernel.pid_max = 65536

# Increase system IP port limits

#net.ipv4.ip_local_port_range = 2000 65000

#TCP接收/发送缓存(用于TCP接收滑动窗口)的最小值、默认值、最大值

net.ipv4.tcp_rmem = 4096 87380 8388608

net.ipv4.tcp_wmem = 4096 87380 8388608

# Increase Linux auto tuning TCP buffer limits

# min, default, and max number of bytes to use

# set max to at least 4MB, or higher if you use very high BDP paths

# Tcp Windows etc

#内核套接字接收/发送缓存区的最大值

net.core.rmem_max = 8388608

net.core.wmem_max = 8388608

#内核套接字接收/发送缓存区的默认值
net.core.rmem_default = 262144
net.core.wmem_default = 262144

#net.core.netdev_max_backlog = 5000

net.ipv4.tcp_window_scaling = 1

sysctl的更多相关文章

  1. /etc/sysctl.conf参数解释

    /etc/sysctl.conf参数解释: fs.file max = 999999 #表示进程(例如一个worker进程)可能同时打开的最大句柄数,直接限制最大并发连接数 net.ipv4.tcp_ ...

  2. LINUX优化得很好的sysctl.conf配置

    最近找了个不错的sysctl.conf的优化参数,在网站响应上已经算不错了的,time超时连接据说几乎为0了.  系统:centos 5.x sysctl.conf配置参数: kernel.msgmn ...

  3. sysctl kernel parameter Optimization note

    syncookies cookies the connection state,when the ack arrives,then deal with the pause connection,ver ...

  4. FreeBSD_11-系统管理——{Part_6 - SYSCTL}

    sysctl 常见参数 Name Type Changeable 示例 & 示意 kern.ostype string no FreeBSD kern.osrelease string no ...

  5. sysctl命令详解

    个人一般sysctl -p 或sysctl -a比较多使用 sysctl配置与显示在/proc/sys目录中的内核参数.可以用sysctl来设置或重新设置联网功能,如IP转发.IP碎片去除以及源路由检 ...

  6. procps包里面的sysctl命令

    procps包里面的sysctl命令 --http://www.cnblogs.com/createyuan/p/3740917.html?utm_source=tuicool&utm_med ...

  7. 优化Linux内核参数/etc/sysctl.conf sysctl 《高性能Linux服务器构建实战:运维监控、性能调优与集群应用》

    优化Linux内核参数/etc/sysctl.conf  sysctl  <高性能Linux服务器构建实战:运维监控.性能调优与集群应用> http://book.51cto.com/ar ...

  8. linux包之procps之sysctl命令

    概述 [root@localhost ~]# rpm -qf /sbin/sysctlprocps-3.2.8-25.el6.x86_64 我们常常在 Linux 的 /proc/sys 目录下,手动 ...

  9. sysctl.conf

    linux系统接口 允许改变正在运作linux系统接口Tcp/IP堆栈和虚拟内存系统的高级选项 用来控制Linux网络配置/proc/sys/net/core/ TCP/IP参数修改添加到/etc/s ...

  10. linux /etc/sysctl.conf 禁止别人ping自己

    vi /etc/sysctl.conf如果希望屏蔽别人 ping 你的主机,则加入以下代码:# Disable ping requestsnet.ipv4.icmp_echo_ignore_all = ...

随机推荐

  1. 《Python基础教程(第二版)》学习笔记 -> 第四章 字典

    字典是Python中唯一内建的映射类型. 字典中的值并没有特殊的顺序,但是都存储在一个特定的键(Key)里.键可以是数字.字符串甚至是元组. 字典的使用 某些情况下,字典比列表更加适用: 表征游戏棋盘 ...

  2. 【译】 AWK教程指南 5AWK中的数组

    awk程序中允许使用字符串当做数组的下标(index).利用这个特色十分有助于资料统计工作.(使用字符串当下标的数组称为Associative Array) 首先建立一个数据文件,并取名为 reg.d ...

  3. 从IRP说起(转)

    原文链接:http://www.cnblogs.com/zhuyp1015/archive/2012/03/14/2396595.html IRP(I/O request package)是操作系统内 ...

  4. 【Spark学习】Spark 1.1.0 with CDH5.2 安装部署

    [时间]2014年11月18日 [平台]Centos 6.5 [工具]scp [软件]jdk-7u67-linux-x64.rpm spark-worker-1.1.0+cdh5.2.0+56-1.c ...

  5. 【转】 hive简介,安装 配置常见问题和例子

    原文来自:  http://blog.csdn.net/zhumin726/article/details/8027802 1 HIVE概述 Hive是基于Hadoop的一个数据仓库工具,可以将结构化 ...

  6. 网吧局域网里的设置外网IP地址、设置内网IP地址、限制内网速度和路由器共享

    现在啊,网吧的需求越来越高,同时在经济比较充裕的情况下,作为网吧的老板可能希望打造全千兆的网吧,让每个进入网吧的人都能充分体验高速的感觉,当然更重要的是在同行竞争中处于上游,特别是对网络游戏爱好者的吸 ...

  7. A Tour of Go Channels

    Channels are a typed conduit through which you can send and receive values with the channel operator ...

  8. nyoj 811 变态最大值

    变态最大值 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 Yougth讲课的时候考察了一下求三个数最大值这个问题,没想到大家掌握的这么烂,幸好在他的帮助下大家算是解 ...

  9. nyoj 79 拦截导弹

    拦截导弹 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 某国为了防御敌国的导弹袭击,发展中一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到 ...

  10. [C语言 - 11] 语言编译执行

    使用gcc编译器 1.预编译 gcc -E Hello.c -o Hello.i 2.汇编 gcc -S Hello.i -o Hello.s   3.编译 gcc -c Hello.s -o Hel ...