Increasing nproc for processes launched by systemd on CentOS 7

Solution 1:

systemd completely ignores /etc/security/limits*. If you are using an RPM that auto-squashes its systemd service file on update, you'll want to file a PR to ask them to mark those files as 'noreplace'

You need to update the .service file /usr/lib/systemd/system/<servicename>.service

[Unit]
Description=Some Daemon
After=syslog.target network.target

[Service]
Type=notify
LimitNOFILE=49152
ExecStart=/usr/sbin/somedaemon

[Install]
WantedBy=multi-user.target

sickill pointed out that you can also override the package-installed values (found in the above file) by adding them to /etc/systemd/system/<servicename>.d/override.conf

[Service]
LimitNOFILE=49152

This provides the added bonus of system-specific settings that aren't in danger of being overwritten on package update.

Then issue the command: systemctl daemon-reload

Solution 2:

Configuration files in /usr/lib/systemd/system/ should not be edited by hand and it is perfectly normal (if not expected) that an rpm will update files that it manages in this directory on update.

As @sickill and @Cherif KAOUA pointed out in comments [https://stackoverflow.com/questions/27849331/how-to-set-nginx-max-open-files/36423859#36423859] you should add custom configuration including limits into /etc/systemd/system/<servicename>.service.d/override.conf. eg:

[Service]
LimitNOFILE=65536

Then reload the systemctl daemon config:

systemctl daemon-reload

RHEL has a great section on systemd in their System Administrator Guide which among other things, lists where systemd unit files should be located and how to override defaults.