Chinaunix首页 | 论坛 | 博客
  • 博客访问: 736195
  • 博文数量: 803
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 5015
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-28 10:29
文章分类

全部博文(803)

文章存档

2011年(1)

2008年(802)

我的朋友

分类:

2008-10-29 11:43:58


  我们常常在 Linux 的 /proc/sys 目录下,手动设定一些 kernel 的参数或是直接 echo 特定的值给一个 proc下的虚拟档案,俾利某些档案之开启,常见的例如设定开机时自动启动 IP Forwarding:
  echo “1” > /proc/sys/net/ipv4/ip_forward
  
  其实,在 Linux 我们还可以用 sysctl command 便可以简易的去检视、设定或自动配置 特定的 kernel 设定。我们可以在系统提示符号下输入「sysctl -a」,摘要如后:abi.defhandler_coff = 117440515
  
  dev.raid.speed_limit_max = 100000
  
  net.ipv4.conf.default.send_redirects = 1
  
  net.ipv4.conf.default.secure_redirects = 1
  
  net.ipv4.conf.default.accept_redirects = 1
  
  net.ipv4.conf.default.mc_forwarding = 0
  
  net.ipv4.neigh.lo.delay_first_probe_time = 5
  
  net.ipv4.neigh.lo.base_reachable_time = 30
  
  net.ipv4.icmp_ratelimit = 100
  
  net.ipv4.inet_peer_gc_mintime = 10
  
  net.ipv4.igmp_max_memberships = 20
  
  net.ipv4.ip_no_pmtu_disc = 0
  
  net.core.no_cong_thresh = 20
  
  net.core.netdev_max_backlog = 300
  
  net.core.rmem_default = 65535
  
  net.core.wmem_max = 65535
  
  vm.kswapd = 512 32 8
  
  vm.overcommit_memory = 0
  
  vm.bdflush = 30 64 64 256 500 3000 60 0 0
  
  vm.freepages = 351 702 1053
  
  kernel.sem = 250 32000 32 128
  
  kernel.panic = 0
  
  kernel.domainname = (none)
  
  kernel.hostname = pc02.shinewave.com.tw
  
  kernel.version = #1 Tue Oct 30 20:11:04 EST 2001
  
  kernel.osrelease = 2.4.9-13
  
  kernel.ostype = Linux
  
  fs.dentry-state = 1611 969 45 0 0 0
  
  fs.file-nr = 1121 73 8192
  
  fs.inode-state = 1333 523 0 0 0 0 0
  
  
  
  
  从上述的语法我们大概可看出 sysctl 的表示法乃把目录结构的「/」以「.」表示,一层一层的连结下去。当然以echo 特定的值给一个 proc下的虚拟档案也是可以用 sysctl加以表示,例如:
  
  #sysctl –w net.ipv4.ip_forward =”1”
  
  
  或是直接在 /etc/sysctl.conf 增删修改特定档案的 0,1值亦可:
  
  # Enables packet forwarding
  
  net.ipv4.ip_forward = 1
  
  # Enables source route verification
  
  net.ipv4.conf.default.rp_filter = 1
  
  # Disables the magic-sysrq key
  
  kernel.sysrq = 0
  
  当然如果考虑 reboot 后仍有效, 直接在 /etc/sysctl.conf 增删修改特定档案的 0,1值才可使之保留设定(以RedHat 为例,每次开机系统启动后, init 会执行 /etc/rc.d/rc.sysinit,便会使用 /etc/sysctl.conf 的预设值去执行 sysctl)。
  
  相关参考档案:
  
  /sbin/sysctl
  
  /etc/sysctl.conf
  
  sysctl 及sysctl.conf manpage
  
  /usr/src/-x.y.z/Documentation/sysctl/*
  
  /usr/share/doc/kernel-doc-x.y.z/sysctl/* (RedHat)
  
  
【责编:admin】

--------------------next---------------------

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