首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可设置文件描述符值,如nproc和nofile linux

可设置文件描述符值,如nproc和nofile linux
EN

Stack Overflow用户
提问于 2020-09-01 23:26:11
回答 1查看 288关注 0票数 0

我有下面的攻略来设置一个用户在linux的文件描述符值,我有下面的代码,这是测试和工作良好,我正在寻找是否缩短代码使用类似vars的东西。

准确地说,我希望使用模块pam_limits one,并同时介绍增加nofilesnproc值的两个操作。

代码语言:javascript
复制
---
- name: Setting File-descriptor Values for db_user
  hosts: all
   become: yes
   become_method: sudo
   become_user: root
   tasks:
    - name: Setting-up file-max limit
      sysctl:
       name: fs.file-max
       value: '1618107'
       state: present
       reload: yes

    - name: setting-up nofile limit
      pam_limits:
       domain: db_user
       limit_type: "{{ item }}"
       limit_item: nofile
       value: '260000'
      loop:
       - soft
       - hard

    - name: setting-up nproc limit
      pam_limits:
       domain: db_user
       limit_type: "{{ item }}"
       limit_item: nproc
       value: '16383'
      loop:
       - soft
       - hard
...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-02 01:08:14

一种方法是,你可以像下面这样使用loop,但是,我看到你的softhard的限制值是相同的,因此你可以更好地使用-,就像我在下面的注释中提到的那样。

代码语言:javascript
复制
---
- name: Setting File-descriptor Values for db_user
  hosts: all
  become: yes
  become_method: sudo
  become_user: root
  tasks:
    - name: Setting-up file-max limit
      sysctl:
        name: fs.file-max
        value: 1618107
        state: present
        reload: yes
    - name: Setting-up nofles and nproc limit for db_user
      pam_limits:
        domain: db_user
        limit_type: "{{item.limit_type}}"
        limit_item: "{{item.limit_item}}"
        value: "{{item.value}}"
      loop:
        # Add nofile and nproc, both soft and hard, limit for the user db_user with a comment.
        # Type "-" for enforcing both soft and hard resource limits together for more details read `man limits.conf`.
        - { limit_type: '-', limit_item: 'nofile', value: 260000 }
        - { limit_type: '-', limit_item: 'nproc', value: 16383 }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63690755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档