Last active
October 20, 2023 09:28
-
-
Save aliostad/3a2245915dee09454f37c760d51522fd to your computer and use it in GitHub Desktop.
BASH script for increasing file descriptors on linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAXFILE=65536 | |
CURRENT_MAXFILE=$(ulimit -n) | |
function update_sysctl(){ | |
UPDT="fs.file-max = $MAXFILE" | |
if ! grep "$UPDT" /etc/sysctl.conf; then | |
echo "$UPDT" >> /etc/sysctl.conf | |
fi | |
} | |
function update_limitsconf(){ | |
UPDT="* soft nproc $MAXFILE" | |
if ! grep "$UPDT" /etc/security/limits.conf; then | |
echo "* soft nproc $MAXFILE" >> /etc/security/limits.conf | |
echo "* hard nproc $MAXFILE" >> /etc/security/limits.conf | |
echo "* soft nofile $MAXFILE" >> /etc/security/limits.conf | |
echo "* hard nofile $MAXFILE" >> /etc/security/limits.conf | |
echo "root soft nofile $MAXFILE" >> /etc/security/limits.conf | |
echo "root hard nofile $MAXFILE" >> /etc/security/limits.conf | |
fi | |
} | |
function update_session_perm(){ | |
UPDT="session required pam_limits.so" | |
if ! grep "$UPDT" /etc/pam.d/common-session; then | |
echo "$UPDT" >> /etc/pam.d/common-session | |
echo "$UPDT" >> /etc/pam.d/common-session-noninteractive | |
fi | |
} | |
if [ $CURRENT_MAXFILE != $MAXFILE ]; then | |
update_sysctl | |
update_limitsconf | |
update_session_perm | |
# reboot ==> MAKE SURE YOU REBOOT!! | |
fi |
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure you reboot