- RAID
- linux句柄导致 max_connection 失效
- /etc/security/limits.conf
- Each line describes a limit for a user in the form:
- Where:
can be: - - a user name
- - a group name, with @group syntax
- - the wildcard *, for default entry
- - the wildcard %, can be also used with %group syntax,
- for maxlogin limit
- - NOTE: group and wildcard limits are not applied to root.
- To apply a limit to the root user,
must be - the literal username root.
can have the two values: - - “soft” for enforcing the soft limits
- - “hard” for enforcing hard limits
- can be one of the following:
- - core - limits the core file size (KB)
- - data - max data size (KB)
- - fsize - maximum filesize (KB)
- - memlock - max locked-in-memory address space (KB)
- - nofile - max number of open files
- - rss - max resident set size (KB)
- - stack - max stack size (KB)
- - cpu - max CPU time (MIN)
- - nproc - max number of processes
- - as - address space limit (KB)
- - maxlogins - max number of logins for this user
- - maxsyslogins - max number of logins on the system
- - priority - the priority to run user process with
- - locks - max number of file locks the user can hold
- - sigpending - max number of pending signals
- - msgqueue - max memory used by POSIX message queues (bytes)
- - nice - max nice priority allowed to raise to values: [-20, 19]
- - rtprio - max realtime priority
- - chroot - change root to directory (Debian-specific)
- * soft core 0
- root hard core 100000
- * hard rss 10000
- @student hard nproc 20
- @faculty soft nproc 20
- @faculty hard nproc 50
- ftp hard nproc 0
- ftp - chroot /ftp
- @student - maxlogins 4
- End of file
RAID
RAID 卡缓存
- 如果磁盘存储采用 RAID 多磁盘阵列
- 会有一个 RAID 卡,里面有个缓存,可以缓存写入磁盘阵列的数据
- 一般缓存级别要设置为
write back
,即数据先进入缓存,后续慢慢写入磁盘阵列 - RAID 卡自带电源,防止掉电造成数据丢失
- RAID 卡在一定周期内会自动对锂电池进行一次充放电,避免电池损坏
- 此时缓存级别会自动设置为
write through
,即数据不经过缓存,直接写磁盘阵列- 会造成性能退化!
- 此时缓存级别会自动设置为
linux句柄导致 max_connection 失效
- linux 句柄默认是 1024,会影响到进程对文件句柄的使用数量
- 从而会影响到 MySQL 设置中 max_connection 失效
/etc/security/limits.conf
可以设置用户或者组对资源文件的使用阈值 ```shell root@akarin:~# cat /etc/security/limits.conf/etc/security/limits.conf
#Each line describes a limit for a user in the form:
#
#Where:
can be: - a user name
- a group name, with @group syntax
- the wildcard *, for default entry
- the wildcard %, can be also used with %group syntax,
for maxlogin limit
- NOTE: group and wildcard limits are not applied to root.
To apply a limit to the root user,
must be the literal username root.
#can have the two values: - “soft” for enforcing the soft limits
- “hard” for enforcing hard limits
#- can be one of the following:
- core - limits the core file size (KB)
- data - max data size (KB)
- fsize - maximum filesize (KB)
- memlock - max locked-in-memory address space (KB)
- nofile - max number of open files
- rss - max resident set size (KB)
- stack - max stack size (KB)
- cpu - max CPU time (MIN)
- nproc - max number of processes
- as - address space limit (KB)
- maxlogins - max number of logins for this user
- maxsyslogins - max number of logins on the system
- priority - the priority to run user process with
- locks - max number of file locks the user can hold
- sigpending - max number of pending signals
- msgqueue - max memory used by POSIX message queues (bytes)
- nice - max nice priority allowed to raise to values: [-20, 19]
- rtprio - max realtime priority
- chroot - change root to directory (Debian-specific)
#
#
* soft core 0
root hard core 100000
* hard rss 10000
@student hard nproc 20
@faculty soft nproc 20
@faculty hard nproc 50
ftp hard nproc 0
ftp - chroot /ftp
@student - maxlogins 4
End of file
root soft nofile 65535 root hard nofile 65535
- soft nofile 65535
- hard nofile 65535
- 说明(其实就是看上面的注释
- 第一列表示用户和组(@开头), `*` 表示任何一个用户。第二列表示软限制还是硬限制,第三列表示限制的资源类型,第四列表示限制的最大值
- hard 和 soft 的区别: soft 是一个警告值,而 hard 则是一个真正意义的阀值,超过就会报错,一般情况下都是设为同一个值。
- core 是内核文件,nofile 是文件描述符,noproc 是进程,一般情况下前者不需要设置
- `ulmit` 来进行**暂时性**的查看和设置(**针对 conf 中的 `*` 用户对 `nofile` 文件的控制数量**)
- 查看
- `ulimit -n` 查看 soft limit
- `ulimit -Hn` 查看 hard limit
- 设置
- `ulimit -Sn <number>` 设置 soft limit
- `ulimit -Hn <number>` 设置 hard limit
- 永久性设置
- 方式一: 在 `/etc/security/limits.conf` 添加 `*` 的数量控制 (注意不能超过 `/proc/sys/fs/nr_open)` (单个进程可分配的最大文件数) 的数量)
soft nofile 65535
hard nofile 65535 ```
- 方式二: 在 `/etc/rc.local` 填入 `ulimit -HSn 65535` ,即每次启动都进行一次对 `*` 用户对 nofile 资源的 soft limit 和 hard limit 的临时性设置
!其他参考本文为CSDN博主「fanren224」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明
! 一些概念 Linux下设置最大文件打开数nofile及nr_open、file-max