linux小知识

[toc]

free

检测系统内存Mem和交换空间swap

1
2
3
4
root@raspbian:~# free -h
total used free shared buff/cache available
Mem: 7.7Gi 405Mi 6.8Gi 17Mi 481Mi 7.1Gi
Swap: 1.0Gi 0B 1.0Gi

total:内存总大小

used:已用

free:空闲

available:可用

swap:交换

hdparm

检查磁盘性能,指定-t选项检查磁盘(评估硬盘的读取效率(不经过磁盘cache)),指定-T 平估硬盘快取的读取效率

1
2
3
4
5
6
7
8
9
10
11
12
root@raspbian:~# hdparm -t /dev/mmcblk0

/dev/mmcblk0:
HDIO_DRIVE_CMD(identify) failed: Invalid argument
Timing buffered disk reads: 132 MB in 3.02 seconds = 43.65 MB/sec

root@raspbian:~# hdparm -tT /dev/mmcblk0

/dev/mmcblk0:
Timing cached reads: 1914 MB in 2.00 seconds = 958.37 MB/sec
HDIO_DRIVE_CMD(identify) failed: Invalid argument
Timing buffered disk reads: 132 MB in 3.03 seconds = 43.63 MB/sec

查找命令在哪个软件包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 比如说我需要iostat
root@raspbian:~# apt-cache search iostat
dstat - versatile resource statistics tool
ganglia-modules-linux - Ganglia extra modules for Linux (IO, filesystems, multicpu)
ifstat - InterFace STATistics Monitoring
nicstat - print network traffic statistics
pcp-import-iostat2pcp - Tool for importing data from iostat into PCP archive logs
r-cran-epi - GNU R epidemiological analysis
r-cran-epibasix - GNU R Elementary Epidemiological Functions
r-cran-kmi - GNU R Kaplan-Meier Multiple Imputation
r-cran-rms - GNU R regression modeling strategies by Frank Harrell
sysstat - system performance tools for Linux

# 挑一个吧
root@raspbian:~# apt-get install sysstat

iostat

1
2
3
4
5
6
7
8
root@raspbian:~# iostat
Linux 5.10.78-Release-OPENFANS+20211111-v8 (raspbian) 09/04/2022 _aarch64_ (4 CPU)
#cpu使用情况
avg-cpu: %user %nice %system %iowait %steal %idle
0.75 0.00 0.45 0.09 0.00 98.71
#磁盘使用情况
Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn
mmcblk0 2.71 136.86 24.05 1074327 188817

-c:显示cpu使用情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 2秒5次列出cpu情况
root@raspbian:~# iostat -c 2 5
Linux 5.10.78-Release-OPENFANS+20211111-v8 (raspbian) 09/04/2022 _aarch64_ (4 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
0.75 0.00 0.44 0.08 0.00 98.73


avg-cpu: %user %nice %system %iowait %steal %idle
0.37 0.00 0.25 0.00 0.00 99.38


avg-cpu: %user %nice %system %iowait %steal %idle
0.13 0.00 0.13 0.00 0.00 99.75


avg-cpu: %user %nice %system %iowait %steal %idle
0.25 0.00 0.12 0.00 0.00 99.62


avg-cpu: %user %nice %system %iowait %steal %idle
0.12 0.00 0.38 0.00 0.00 99.50

-d:磁盘使用情况

1
2
3
4
5
6
7
8
9
10
11
12
# 2秒3次
root@raspbian:~# iostat -d 2 3
Linux 5.10.78-Release-OPENFANS+20211111-v8 (raspbian) 09/04/2022 _aarch64_ (4 CPU)

Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn
mmcblk0 2.53 124.41 22.50 1074327 194285

Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn
mmcblk0 3.00 0.00 16.00 0 32

Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn
mmcblk0 1.00 0.00 36.00 0 72

-x:指定磁盘设备名称

1
2
3
4
5
6
7
8
9
10
11
12
# 指定/dev/mmcblk0磁盘设备2秒3次
root@raspbian:~# iostat -dx /dev/mmcblk0 2 3
Linux 5.10.78-Release-OPENFANS+20211111-v8 (raspbian) 09/04/2022 _aarch64_ (4 CPU)

Device r/s w/s rkB/s wkB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq-sz wareq-sz svctm %util
mmcblk0 1.45 1.00 118.12 21.71 0.77 1.31 34.61 56.73 5.45 10.22 0.02 81.67 21.76 2.42 0.59

Device r/s w/s rkB/s wkB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq-sz wareq-sz svctm %util
mmcblk0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

Device r/s w/s rkB/s wkB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq-sz wareq-sz svctm %util
mmcblk0 0.00 7.50 0.00 34.00 0.00 1.00 0.00 11.76 0.00 7.00 0.05 0.00 4.53 0.80 0.60

sar

1
2
3
4
5
6
7
8
9
10
root@raspbian:~# sar -u 2 5 
Linux 5.10.78-Release-OPENFANS+20211111-v8 (raspbian) 09/04/2022 _aarch64_ (4 CPU)

10:32:27 AM CPU %user %nice %system %iowait %steal %idle
10:32:29 AM all 1.38 0.00 1.00 0.00 0.00 97.62
10:32:31 AM all 7.50 0.00 1.38 0.00 0.00 91.12
10:32:33 AM all 0.25 0.00 0.87 0.00 0.00 98.88
10:32:35 AM all 0.25 0.00 0.00 0.00 0.00 99.75
10:32:37 AM all 0.50 0.00 0.13 0.00 0.00 99.37
Average: all 1.97 0.00 0.67 0.00 0.00 97.35

lsof

查看端口服务,-i查看对应端口服务

1
2
3
4
5
6
root@raspbian:~# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 834 root 3u IPv4 26704 0t0 TCP *:ssh (LISTEN)
sshd 834 root 4u IPv6 26706 0t0 TCP *:ssh (LISTEN)
BT-Panel 1147 root 13u IPv4 43447 0t0 TCP raspbian:11716->raspbian:ssh (ESTABLISHED)
sshd 4694 root 3u IPv4 42753 0t0 TCP raspbian:ssh->raspbian:11716 (ESTABLISHED)

netstat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
root@raspbian:~# netstat 
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 6 10.71.10.25:8101 10.68.65.140:5937 ESTABLISHED
tcp 0 176 raspbian:ssh raspbian:11716 ESTABLISHED
tcp 160 0 raspbian:11716 raspbian:ssh ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 43560 /run/user/0/systemd/notify
unix 3 [ ] DGRAM 15265 /run/systemd/notify
unix 16 [ ] DGRAM 15276 /run/systemd/journal/dev-log
unix 2 [ ] DGRAM 15282 /run/systemd/journal/syslog
unix 7 [ ] DGRAM 15291 /run/systemd/journal/socket
unix 2 [ ] DGRAM 24174 @00001
unix 3 [ ] STREAM CONNECTED 22269
unix 2 [ ] DGRAM 27827
unix 2 [ ] DGRAM 22165
unix 3 [ ] STREAM CONNECTED 21099 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 22163
unix 2 [ ] DGRAM 22143
unix 2 [ ] DGRAM 22139
unix 3 [ ] STREAM CONNECTED 22433
unix 3 [ ] STREAM CONNECTED 22432
unix 3 [ ] STREAM CONNECTED 19284 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 26018 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 26017
unix 2 [ ] DGRAM 25873
unix 3 [ ] STREAM CONNECTED 25871
unix 3 [ ] STREAM CONNECTED 25870
unix 3 [ ] STREAM CONNECTED 18705 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 27250 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 25862
unix 3 [ ] STREAM CONNECTED 30216 /run/containerd/containerd.sock.ttrpc
unix 3 [ ] STREAM CONNECTED 32039
unix 3 [ ] STREAM CONNECTED 18236 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 29646 /run/containerd/containerd.sock.ttrpc
unix 3 [ ] STREAM CONNECTED 20201
unix 3 [ ] STREAM CONNECTED 32038
unix 3 [ ] STREAM CONNECTED 20289
unix 3 [ ] STREAM CONNECTED 29570 /run/containerd/s/efda43ab145a8b986f0fd3455c3b2956d5def686d2807c67031ad6563f9958db
unix 3 [ ] STREAM CONNECTED 31928
unix 3 [ ] STREAM CONNECTED 24063 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 20541
unix 3 [ ] STREAM CONNECTED 27836
unix 2 [ ] DGRAM 16406
unix 3 [ ] STREAM CONNECTED 20777
unix 3 [ ] STREAM CONNECTED 43564
unix 3 [ ] STREAM CONNECTED 21400
unix 3 [ ] STREAM CONNECTED 20542
unix 2 [ ] DGRAM 14168
unix 3 [ ] STREAM CONNECTED 21401
unix 2 [ ] DGRAM 18426
unix 3 [ ] STREAM CONNECTED 44613 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 18148
unix 2 [ ] DGRAM 43546
unix 3 [ ] STREAM CONNECTED 24181 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 18312
unix 3 [ ] STREAM CONNECTED 18430
unix 2 [ ] DGRAM 41797
unix 3 [ ] STREAM CONNECTED 28070
unix 3 [ ] STREAM CONNECTED 18313 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 21097 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 17383 /run/systemd/journal/stdout
unix 3 [ ] DGRAM 15267
unix 3 [ ] STREAM CONNECTED 25700
unix 3 [ ] STREAM CONNECTED 43538
unix 3 [ ] STREAM CONNECTED 17927
unix 3 [ ] STREAM CONNECTED 25701 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 41806 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 18147
unix 3 [ ] STREAM CONNECTED 16734
unix 3 [ ] STREAM CONNECTED 20214 /run/systemd/journal/stdout
unix 3 [ ] DGRAM 15266
unix 3 [ ] STREAM CONNECTED 14309 /run/systemd/journal/stdout
unix 3 [ ] DGRAM 43561
unix 3 [ ] STREAM CONNECTED 27733
unix 2 [ ] DGRAM 16736
unix 3 [ ] STREAM CONNECTED 26790 /var/run/dbus/system_bus_socket
unix 3 [ ] DGRAM 16739
unix 2 [ ] DGRAM 43549
unix 2 [ ] STREAM CONNECTED 41786
unix 3 [ ] STREAM CONNECTED 25802
unix 3 [ ] DGRAM 16740
unix 3 [ ] DGRAM 43562
unix 3 [ ] STREAM CONNECTED 26994 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 20539
unix 3 [ ] STREAM CONNECTED 20421
unix 3 [ ] STREAM CONNECTED 21092
unix 3 [ ] STREAM CONNECTED 18951
unix 2 [ ] DGRAM 23682
unix 2 [ ] DGRAM 20376
unix 3 [ ] STREAM CONNECTED 26990
unix 3 [ ] STREAM CONNECTED 21100 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 18774
unix 2 [ ] DGRAM 23957
unix 3 [ ] STREAM CONNECTED 26995 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 21091
unix 3 [ ] STREAM CONNECTED 22616
unix 3 [ ] STREAM CONNECTED 21096 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 18237 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 25678 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 21101 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 29575
unix 3 [ ] STREAM CONNECTED 21083
unix 3 [ ] STREAM CONNECTED 20213 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 24486
unix 3 [ ] STREAM CONNECTED 20428
unix 2 [ ] DGRAM 21055
unix 3 [ ] STREAM CONNECTED 28819 /run/containerd/containerd.sock
unix 3 [ ] STREAM CONNECTED 21098 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 21056
unix 3 [ ] STREAM CONNECTED 18933
unix 3 [ ] STREAM CONNECTED 23569
unix 3 [ ] STREAM CONNECTED 21035 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 21095 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 22801 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 21054
unix 3 [ ] STREAM CONNECTED 21093 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 19104 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 28821
unix 3 [ ] STREAM CONNECTED 21034
unix 3 [ ] STREAM CONNECTED 21094 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 28525 /run/containerd/containerd.sock
unix 2 [ ] DGRAM 19014
unix 3 [ ] STREAM CONNECTED 20929 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 23753 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 31073 /run/containerd/s/f173b4c37ec27fe764ea6843063c75576d07f7ac21d51986b75d8e816f41033e
unix 3 [ ] STREAM CONNECTED 18929
unix 3 [ ] STREAM CONNECTED 24056
unix 3 [ ] STREAM CONNECTED 26698
unix 3 [ ] STREAM CONNECTED 20778 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 18853
unix 2 [ ] DGRAM 23961
unix 2 [ ] DGRAM 18992
unix 3 [ ] STREAM CONNECTED 20853

top、htop

1
root@raspbian:~# top
1
root@raspbian:~# htop

last

last可用查看用户登录系统的记录,包括用户名、登录的远程名称或者ip地址以及登录时间。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
root@raspbian:~# last
root pts/0 127.0.0.1 Sun Sep 4 09:43 still logged in
root pts/0 127.0.0.1 Sun Sep 4 09:16 - 09:36 (00:20)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 still running
root pts/0 10.8.3.28 Sat Sep 3 10:07 - 10:07 (00:00)
root pts/0 127.0.0.1 Sat Sep 3 09:13 - 09:15 (00:01)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 still running
root pts/0 10.8.3.28 Fri Sep 2 13:17 - crash (-19237+05:17)
root pts/1 127.0.0.1 Thu Sep 1 10:42 - 10:51 (00:08)
root pts/0 10.8.3.28 Thu Sep 1 10:10 - 13:45 (03:35)
root pts/1 10.71.22.140 Thu Sep 1 08:55 - 09:33 (00:38)
root pts/1 10.71.22.140 Thu Sep 1 08:40 - 08:54 (00:14)
root pts/0 10.71.22.140 Thu Sep 1 08:38 - 09:33 (00:55)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 still running
root pts/0 10.8.3.28 Wed Aug 31 23:58 - crash (-19235+15:58)
root pts/1 10.8.3.28 Wed Aug 31 23:13 - crash (-19235+15:13)
root pts/0 127.0.0.1 Wed Aug 31 23:11 - 23:50 (00:38)
root pts/0 127.0.0.1 Wed Aug 31 23:06 - 23:11 (00:04)
root pts/0 127.0.0.1 Wed Aug 31 23:03 - 23:06 (00:02)
root pts/0 127.0.0.1 Wed Aug 31 23:02 - 23:02 (00:00)
root pts/0 127.0.0.1 Wed Aug 31 23:00 - 23:02 (00:02)
root pts/0 127.0.0.1 Wed Aug 31 22:57 - 22:58 (00:01)
root pts/0 127.0.0.1 Wed Aug 31 22:54 - 22:56 (00:02)
root pts/0 127.0.0.1 Wed Aug 31 22:31 - 22:52 (00:21)
root pts/0 10.73.159.18 Wed Aug 31 14:28 - 14:29 (00:00)
root pts/0 10.73.159.18 Wed Aug 31 14:28 - 14:28 (00:00)
root pts/0 10.73.159.18 Wed Aug 31 14:19 - 14:19 (00:00)
root pts/0 10.73.159.18 Wed Aug 31 14:19 - 14:19 (00:00)
root pts/0 10.73.159.18 Wed Aug 31 14:16 - 14:19 (00:02)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 still running
root pts/0 10.73.159.18 Wed Aug 31 14:14 - down (00:00)
root pts/0 10.73.159.18 Wed Aug 31 14:13 - 14:14 (00:00)
root pts/0 10.73.159.18 Wed Aug 31 14:10 - 14:13 (00:02)
root pts/0 127.0.0.1 Tue Aug 30 22:26 - 14:10 (15:43)
root pts/0 127.0.0.1 Tue Aug 30 20:46 - 22:26 (01:39)
root pts/0 127.0.0.1 Tue Aug 30 20:42 - 20:45 (00:02)
root pts/2 10.67.44.114 Tue Aug 30 20:11 - 20:13 (00:01)
root pts/2 127.0.0.1 Tue Aug 30 20:09 - 20:10 (00:01)
root pts/0 127.0.0.1 Tue Aug 30 18:33 - 20:31 (01:58)
root pts/0 127.0.0.1 Tue Aug 30 17:31 - 18:33 (01:01)
root pts/0 127.0.0.1 Tue Aug 30 16:49 - 16:58 (00:09)
root pts/0 127.0.0.1 Tue Aug 30 15:57 - 16:27 (00:30)
root pts/0 127.0.0.1 Tue Aug 30 14:56 - 15:06 (00:10)
root pts/0 127.0.0.1 Tue Aug 30 14:48 - 14:51 (00:02)
root pts/0 127.0.0.1 Tue Aug 30 14:36 - 14:44 (00:08)
root pts/0 127.0.0.1 Tue Aug 30 14:21 - 14:24 (00:02)
root pts/0 127.0.0.1 Tue Aug 30 13:34 - 14:20 (00:45)
root pts/0 127.0.0.1 Tue Aug 30 13:13 - 13:14 (00:00)
root pts/0 127.0.0.1 Tue Aug 30 12:43 - 13:13 (00:29)
root pts/0 127.0.0.1 Tue Aug 30 12:31 - 12:39 (00:08)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 - 14:14 (19235+06:14)
root pts/1 127.0.0.1 Tue Aug 30 12:12 - down (00:17)
root pts/1 127.0.0.1 Tue Aug 30 12:12 - 12:12 (00:00)
root pts/0 127.0.0.1 Tue Aug 30 12:10 - down (00:19)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 - 12:30 (19234+04:30)
root pts/0 127.0.0.1 Mon Aug 29 08:57 - 10:01 (01:04)
root pts/0 127.0.0.1 Mon Aug 29 08:49 - 08:57 (00:08)
root pts/0 127.0.0.1 Mon Aug 29 08:16 - 08:17 (00:01)
root pts/0 127.0.0.1 Mon Aug 29 08:16 - 08:16 (00:00)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 - 12:30 (19234+04:30)
root pts/0 10.8.3.28 Sun Aug 28 21:53 - 22:10 (00:17)
root pts/0 10.8.3.28 Sun Aug 28 20:17 - 21:44 (01:27)
root pts/0 10.8.3.28 Sun Aug 28 20:12 - 20:12 (00:00)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 - 12:30 (19234+04:30)
root pts/0 192.168.1.100 Sun Aug 28 13:27 - crash (-19232+05:27)
pi pts/0 192.168.1.100 Sun Aug 28 01:10 - 01:15 (00:04)
root pts/1 127.0.0.1 Sun Aug 28 00:45 - 00:45 (00:00)
root pts/1 127.0.0.1 Sun Aug 28 00:45 - 00:45 (00:00)
pi pts/0 192.168.1.100 Sun Aug 28 00:30 - 01:09 (00:38)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 - 12:30 (19234+04:30)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 - 18:13 (17941+10:13)
reboot system boot 5.10.78-Release- Thu Jan 1 08:00 - 18:12 (17941+10:12)

wtmp begins Thu Jan 1 08:00:03 1970

ulimit

Too many open files是Linux系统中常见的错误,从字面意思上看就是说程序打开的文件数过多,不过这里的files不单是文件的意思,也包括打开的通讯链接(比如socket),正在监听的端口等等,所以有时候也可以叫做句柄(handle),这个错误通常也可以叫做句柄数超出系统限制。引起的原因就是进程在某个时刻打开了超过系统限制的文件数量以及通讯链接数。

通过命令ulimit -a可以查看当前系统设置的最大句柄数是多少

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
core file size          (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 31767
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) 31767
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

可以看到,open files的配置是1024,可以通过如下命令将open files增加

1
ulimit -n 65535

这种修改方式可以临时把文件打开数量增加到65535,但是系统重启后这个配置会失效。

还有一种方式是修改系统的配置文件,以Ubuntu为例,配置文件默认在

1
/etc/security/limits.conf

在这个配置文件中增加

1
2
* soft nofile 65535
* hard nofile 65535