Have a look at load.sh
file below, it contains all necessary commands to automate the process of changing system limits.
This guide has been tested on macOS High Sierra and Mojave. If you'd like to learn a theory, please continue reading.
This text is the section about OS X Yosemite (which also works for macOS Sierra) from https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x
_The last time i visited this link it was dead (403), so I cloned it here from the latest snapshot in Archive.org's Wayback Machine