mac os OS X 优山美地(Yosemite)如何提高最大连接数限制

超过系统最大文件打开数之后,系统报 too many open files

mac os yosemite 之后,网上原来提高最大打开端口号限制的方法都不可行了。最新的办法而下:

1, 查看限制:

 ulimit -a


2,  创建新的配置文件,配置系统打开最多文件限制(如果没有的话)

sudo vi /Library/LaunchDaemons/limit.maxfiles.plist

文件内容

 

   

      Label

        limit.maxfiles

      ProgramArguments

       

          launchctl

          limit

          maxfiles

          655360

          655360

       

      RunAtLoad

       

      ServiceIPC

       

   

 


3,创建每个最大进程数限制的配置文件:

 sudo vi /Library/LaunchDaemons/limit.maxproc.plist

配置内容:

 

   

      Label

        limit.maxproc

      ProgramArguments

       

          launchctl

          limit

          maxproc

          2048

          2048

       

      RunAtLoad

       

      ServiceIPC

       

   

 


4,以上两个文件 需要owned byroot:wheel

读写权限:-rw-r--r--

5,执行launchctl limit是配置生效。也许需要重启电脑(本人系统需要, OS X 10.10.3)

最好查看配置是否生效:

$ ulimit -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

file size               (blocks, -f) unlimited

max locked memory       (kbytes, -l) unlimited

max memory size         (kbytes, -m) unlimited

open files                      (-n) 655360

pipe size            (512 bytes, -p) 1

stack size              (kbytes, -s) 8192

cpu time               (seconds, -t) unlimited

max user processes              (-u) 2048

virtual memory          (kbytes, -v) unlimited


6,打开端口后限制。

查看socket端口范围限制:

$ sysctl -a | grep port

kern.ds_supgroups_supported: 1

kern.ipc_portbt: 0

kern.hv_support: 1

vfs.generic.nfs.client.callback_port: 0

vfs.generic.nfs.server.require_resv_port: 0

vfs.generic.nfs.server.export_hash_size: 64

net.inet.ip.portrange.lowfirst: 1023

net.inet.ip.portrange.lowlast: 600

net.inet.ip.portrange.first: 1024

net.inet.ip.portrange.last: 65535

net.inet.ip.portrange.hifirst: 49152

net.inet.ip.portrange.hilast: 65535

net.inet.tcp.randomize_ports: 0

net.inet.udp.randomize_ports: 1

net.inet.ipsec.esp_port: 4500

machdep.misc.fast_uexc_support: 1


系统默认端口打开范围大小只有大概1500个,

修改办法:

打开(没有就创建)文件 /etc/sysctl.conf

sudo vi  /etc/sysctl.conf

添加以下两行:

net.inet.ip.portrange.first=1024

net.inet.ip.portrange.last=65535

第一行指定最小端口,低于1024的端口,系统预留,部分已经默认分配给常见应用了。一般需要root才能分配这低于1024的端口范围,不建议使用,除非你知道你在做什么。

第二行最大只能到达65535=2^16 -1。因为ipv4端口只占16bits,因此最大只能到达65535。

因此一个客户端,配置一个ipv4地址,能够创建的最大连接数为65535-1024=64511。

如何使用mac os 创建连接测试服务器,考虑带其他应用程序占用的端口,一般配置最大创建64000个连接,基本到达系统最大限制了。



你可能感兴趣的:(mac,os,ox,x)