---
title: "Linux系统文件句柄数设置"
author: "hpgary"
date: "2018-01-19T12:29:13Z"
tags: []
categories: ["操作系统"]
slug: "linux"
draft: false
lastmod: "2018-02-05T14:01:17Z"
id: 2408225
url: "https://hpgary.iteye.com/blog/2408225"
---

默认情况下Linux最大文件句柄数为1024个，当你的服务器在大并发达到极限时，就会报出“too many open files”

 

     那么如何查看文件句柄数据呢？

     使用命令就可以查看：

root@hks03test:~# ulimit -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 63712

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited

**open files                      (-n) 1024**

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 8192

cpu time               (seconds, -t) unlimited

max user processes              (-u) 63712

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

 

    那么如何设置Linux文件句柄数呢？（这只是临时方案，重启后恢复原来的值）

    

```
 ulimit -n 65535
```

    再次查看 open files 就会是 65535 ， elasticsearch5.* 最低标准是 65535 

   

   永久修改： vi /etc/security/limits.conf 

   

```
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
```

  设置好后，重新登录系统 生效。