изменить и применить limit.conf без перезагрузки

39345
mahmood

Я добавил строку, /etc/security/limits.confчтобы увеличить количество открытых файлов.

* hard nofile 4096 root hard nofile 16384 

Однако, когда я запускаю, ulimit -nон говорит 1024, который является значением по умолчанию. Я вышел из системы и вошел в систему, но все еще вижу 1024. Как я могу применить изменение?

10

2 ответа на вопрос

12
Tombart

Changes made by ulimit command:

$ ulimit -n 4096 $ ulimit -Hn 16384 

will apply only for current user and session. In order to make it permanent, you have to modify /etc/security/limits.conf by adding your limits:

* soft nofile 4096 * hard nofile 16384 

However, wildcard * won't apply for root user. In order to do so, you have to state it explicitly:

* soft nofile 4096 * hard nofile 16384 root soft nofile 4096 root hard nofile 16384 

These limits will be applied after reboot.

If you want to apply changes without reboot, modify /etc/pam.d/common-session by adding this line at the end of file:

session required pam_limits.so 

Upon next login you should see updated limits, you can check them (soft and hard limits):

$ ulimit -a $ ulimit -Ha 
У меня была проблема с этим подходом, которая была действительно странной. Я использую Ubuntu 14 и включил `pam_limits.so` в` / etc / pam.d / common-session`. Я настроил в `/ etc / security / limit.conf` пользователя x жесткие и мягкие ограничения для` nofile` 64000. `sudo -ux` затем` ulimit -a` показывает, что изменения не были применены. Я понял, что `su` и` sudo` имеют разные конфигурации pam, поэтому для правильной работы мне нужно было включить `pam_limits.so` в` / etc / pam.d / common-session-noninteractive`. Если вам интересно, каков вариант использования - я использую ansible и sudo для смены пользователя. hakcho 6 лет назад 1
По какой-то причине мне пришлось добавить его в `/ etc / pam.d / common-session-noninteractive`, чтобы он работал. Sumit 5 лет назад 0
6
Flup

If you're using bash, ulimit -n will only display the soft limit. To get the hard limit, you need to do ulimit -Hn.

On my system, I see this:

$ ulimit -n 1024 $ ulimit -Hn 4096 

Похожие вопросы