Chinaunix首页 | 论坛 | 博客
  • 博客访问: 637378
  • 博文数量: 244
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-27 09:53
个人简介

记录学习,记录成长

文章分类

全部博文(244)

我的朋友

分类: LINUX

2015-07-23 16:55:11

1.可以用echo value >/proc/sys/xxx....的办法将更改原来的内核参数
例如:
[root@localhost ipv4]# cat ip_forward 
1
[root@localhost ipv4]# pwd
/proc/sys/net/ipv4
[root@localhost ipv4]# echo 0 > /proc/sys/net/ipv4/ip_forward 
[root@localhost ipv4]# cat ip_forward 
0

或者
2.用sysctl命令设置
sysctl   -w  xxx.xx=value   (此时在/proc/sys目录中,xxx是该目录下的子目录,有几层目录就用几个.号)
如:
[root@localhost sys]# pwd
/proc/sys
[root@localhost sys]# cat net/ipv4/ip_forward
1
[root@localhost sys]# sysctl -w net.ipv4.ip_forward=0
net.ipv4.ip_forward = 0
[root@localhost sys]# cat net/ipv4/ip_forward
0
注意:上述1,2方法是设置后立即生效,但重启后失效

3.让2方法永久有效:写入/etc/sysctl.conf中即可
我的/etc/sysctl.conf文件内容,把相关的值更改一下就行了;
[root@localhost sys]# cat /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 1

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# 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

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 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 = 4294967295

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 268435456

4.虽然3方法是永久有效,但它不会立即生效,可以用sysctl命令让其立即生效
sysctl命令解释:

sysctl 用来设置系统的核心参数
-a 显示当前所有内核参数配置
-A 以表格的形式显示
-e 模糊模式
-n 忽略关键词
-w 设置变量值
-p<文件> 指定配置文件
-h 显示帮助信息
-V 版本信息 

用法:

[root@localhost ~]# sysctl -a     #显示所有系统核心设置
[root@localhost ~]# sysctl -w net.ipv4.tcp_max_syn_backlog=256 #设置环境变量
[root@localhost ~]# sysctl -p #立马生效




阅读(1114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~