diff --git a/docs/mongodb_guide.md b/docs/mongodb_guide.md index 276fd193..a6a7d3cf 100644 --- a/docs/mongodb_guide.md +++ b/docs/mongodb_guide.md @@ -138,6 +138,12 @@ These variables apply to advanced situations. | `mongodb_mongod_service_delay` | Integer | The time in seconds between retries when starting the mongod service. | 10 | | `mongodb_status_poll` | Integer | The maximum number of times to query for the replicaset status before the set converges or we fail. | 3 | | `mongodb_status_interval` | Integer | The number of seconds to wait between polling executions. | 10 | +| `mongodb_sysctl_file` | String | The name of the MongoDB sysctl file | /etc/sysctl.d/98-mongodb.conf | +| `mongodb_net_ipv4_tcp_keepalive_time` | Integer | Time (in seconds) that a TCP connection remains idle before the kernel starts sending keepalive probes to verify the connection is still alive. | 300 | +| `mongodb_net_core_somaxconn` | Integer | Controls the backlog queue size for incoming connections. When the queue is full, new connection attempts are rejected. | 65535 | +| `mongodb_vm_zone_reclaim_mode` | Integer | Controls whether the kernel reclaims memory from local zones before allocating from remote NUMA nodes. | 0 | +| `mongodb_vm_swappiness` | Integer | Balances between swapping out anonymous pages (process memory) versus dropping page cache (file system buffers). | 1 | +| `mongodb_vm_max_map_count` | Integer | Maximum number of memory map areas (virtual memory areas/VMAs) a process can create. | 262144 | ## Configuring TLS diff --git a/roles/mongodb/defaults/main/kernel_params.yml b/roles/mongodb/defaults/main/kernel_params.yml new file mode 100644 index 00000000..4f533571 --- /dev/null +++ b/roles/mongodb/defaults/main/kernel_params.yml @@ -0,0 +1,10 @@ +# Copyright (c) 2024, Itential, Inc +# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) +--- +# Kernel parameters +mongodb_sysctl_file: /etc/sysctl.d/98-mongodb.conf +mongodb_net_ipv4_tcp_keepalive_time: 300 +mongodb_net_core_somaxconn: 65535 +mongodb_vm_zone_reclaim_mode: 0 +mongodb_vm_swappiness: 1 +mongodb_vm_max_map_count: 262144 diff --git a/roles/mongodb/tasks/install-adjust-kernel-params.yml b/roles/mongodb/tasks/adjust-kernel-params.yml similarity index 62% rename from roles/mongodb/tasks/install-adjust-kernel-params.yml rename to roles/mongodb/tasks/adjust-kernel-params.yml index 87f7dc99..7db5bc70 100644 --- a/roles/mongodb/tasks/install-adjust-kernel-params.yml +++ b/roles/mongodb/tasks/adjust-kernel-params.yml @@ -17,34 +17,39 @@ - name: Adjust keepalive ansible.posix.sysctl: name: net.ipv4.tcp_keepalive_time - value: 300 - -- name: Disable zone reclaim mode - ansible.posix.sysctl: - name: vm.zone_reclaim_mode - value: 0 + value: "{{ mongodb_net_ipv4_tcp_keepalive_time }}" + state: present + sysctl_file: "{{ mongodb_sysctl_file }}" + reload: true - name: Increase throughput settings ansible.posix.sysctl: name: net.core.somaxconn - value: 65535 + value: "{{ mongodb_net_core_somaxconn }}" + state: present + sysctl_file: "{{ mongodb_sysctl_file }}" + reload: true + +- name: Disable zone reclaim mode + ansible.posix.sysctl: + name: vm.zone_reclaim_mode + value: "{{ mongodb_vm_zone_reclaim_mode }}" + state: present + sysctl_file: "{{ mongodb_sysctl_file }}" + reload: true - name: Set vm swappiness ansible.posix.sysctl: name: vm.swappiness - value: 1 + value: "{{ mongodb_vm_swappiness }}" + state: present + sysctl_file: "{{ mongodb_sysctl_file }}" + reload: true -# Set Soft User Limits -- name: Set number of procs - community.general.pam_limits: - domain: mongod - limit_type: soft - limit_item: nproc - value: 32000 - -- name: Set number of files - community.general.pam_limits: - domain: mongod - limit_type: soft - limit_item: nofile - value: 64000 +- name: Set vm max_map_count + ansible.posix.sysctl: + name: vm.max_map_count + value: "{{ mongodb_vm_max_map_count }}" + state: present + sysctl_file: "{{ mongodb_sysctl_file }}" + reload: true diff --git a/roles/mongodb/tasks/install-mongodb.yml b/roles/mongodb/tasks/install-mongodb.yml index 7833c7c5..d2d1784b 100644 --- a/roles/mongodb/tasks/install-mongodb.yml +++ b/roles/mongodb/tasks/install-mongodb.yml @@ -53,7 +53,7 @@ - name: Adjust Kernel parameters ansible.builtin.import_tasks: - file: install-adjust-kernel-params.yml + file: adjust-kernel-params.yml - name: Configure SELinux ansible.builtin.include_tasks: