1. Linux用户使用FreeBSD,问FreeBSD ulimit怎么设置?
首先说明FreeBSD默认Shell是csh没有ulimit命令,但C Shell有limit命令。如果你想使用ulimit命令可以安装Bourne shell,Bash,Zsh
limit,ulimit比较
[neo@freebsd:~] limit
cputime unlimited
filesize unlimited
datasize 32768MB
stacksize 512MB
coredumpsize unlimited
memoryuse unlimited
memorylocked unlimited
maxproc 5547
descriptors 65536
sockbufsize unlimited
vmemorysize unlimited
NPTS unlimited
SWAP unlimited
[neo@freebsd:~] env | grep SHELL
SHELL=/usr/local/bin/zsh
[neo@freebsd:~] ulimit -a
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) 33554432
-s: stack size (kbytes) 524288
-c: core file size (blocks) unlimited
-m: resident set size (kbytes) unlimited
-l: locked-in-memory size (kb) unlimited
-u: processes 5547
-n: file descriptors 65536
-N 9: socket buffer size (kb) unlimited
-v: virtual memory size (kb) unlimited
-N 11: unlimited
-N 12: unlimited
在Freebsd上,你能使用sysctl命令:
以 nofile - max number of open files 为例,limit、ulimit、sysctl实现同样的功能。
csh% limit descriptors unlimited
或者
csh% limit descriptors 4096
sh$ ulimit -n unlimited
或者
sh$ ulimit -n 4096
sysctl kern.maxfiles=65536
sysctl kern.maxfilesperproc=65536
写入配置文件 sysctl.conf
[neo@freebsd:~] cat /etc/sysctl.conf
# $FreeBSD: src/etc/sysctl.conf,v 1.8.34.1.4.1 2010/06/14 02:09:06 kensmith Exp $
#
# This file is read when going to multi-user and its contents piped thru
# ``sysctl'' to adjust kernel values. ``man 5 sysctl.conf'' for details.
#
# Uncomment this to prevent users from seeing information about processes that
# are being run under another UID.
#security.bsd.see_other_uids=0
#vm.pmap.shpgperproc: 2000
#vm.pmap.pv_entry_max: 13338058
kern.ipc.shm_use_phys=1
kern.maxfiles=65536
#ulimit -n 65536
kern.maxfilesperproc=65536
kern.ipc.somaxconn=2048
[neo@freebsd:~] /etc/rc.d/sysctl reload
[neo@freebsd:~] sysctl -a | grep maxfiles
kern.maxfiles: 65536
kern.maxfilesperproc: 65536
其他参考http://www.freebsd.org/doc/zh_CN/books/handbook/configtuning-kernel-limits.html
FreeBSD 查看端口号范围,并修改meda076# sysctl net.inet.ip.portrange.first net.inet.ip.portrange.last
net.inet.ip.portrange.first: 10000
net.inet.ip.portrange.last: 65535
meda076# sysctl net.inet.ip.portrange.first=1024
net.inet.ip.portrange.first: 10000 -> 1024
meda076# sysctl net.inet.ip.portrange.first net.inet.ip.portrange.last
net.inet.ip.portrange.first: 1024
net.inet.ip.portrange.last: 65535