Skip to content

Instantly share code, notes, and snippets.

@jpswade
Last active February 10, 2016 20:43
Show Gist options
  • Save jpswade/3e1231bdb711f63d8bba to your computer and use it in GitHub Desktop.
Save jpswade/3e1231bdb711f63d8bba to your computer and use it in GitHub Desktop.
#fix_apache
#http://lists.bitfolk.com/lurker/message/20140907.170406.4b9ef2e5.en.html
echo start>>httpd.log
echo ps -C httpd -FH>>httpd.log
ps -C httpd -FH>>httpd.log
echo ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr>>httpd.log
ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr>>httpd.log
#cat /etc/httpd/conf/httpd.conf | grep LoadModule
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
sed -i 's|^LoadModule|#LoadModule|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule mime_module modules/mod_mime.so|LoadModule mime_module modules/mod_mime.so|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule dir_module modules/mod_dir.so|LoadModule dir_module modules/mod_dir.so|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule alias_module modules/mod_alias.so|LoadModule alias_module modules/mod_alias.so|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule authz_host_module modules/mod_authz_host.so|LoadModule authz_host_module modules/mod_authz_host.so|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule log_config_module modules/mod_log_config.so|LoadModule log_config_module modules/mod_log_config.so|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule autoindex_module modules/mod_autoindex.so|LoadModule autoindex_module modules/mod_autoindex.so|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule negotiation_module modules/mod_negotiation.so|LoadModule negotiation_module modules/mod_negotiation.so|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule setenvif_module modules/mod_setenvif.so|LoadModule setenvif_module modules/mod_setenvif.so|g' /etc/httpd/conf/httpd.conf
sed -i 's|#LoadModule rewrite_module modules/mod_rewrite.so|LoadModule rewrite_module modules/mod_rewrite.so|g' /etc/httpd/conf/httpd.conf
service httpd restart
a=`ps -eo pmem,cmd | sort -k 1 -nr | grep httpd | head -n 1 | cut -d" " -f2`
f=`free -m | awk '/Mem/ {print $4}'`
mc=`printf "%.0f" $(echo "$f/$a" | bc)`
#tail -f /var/log/httpd/error_log
#http://wiki.vpslink.com/Low_memory_MySQL_/_Apache_configurations
sed -i 's|StartServers 8|StartServers 1|g' /etc/httpd/conf/httpd.conf
sed -i 's|MinSpareServers 5|MinSpareServers 1|g' /etc/httpd/conf/httpd.conf
sed -i "s|MaxSpareServers 20|MaxSpareServers $mc|g" /etc/httpd/conf/httpd.conf
sed -i 's|ServerLimit 256|ServerLimit 50|g' /etc/httpd/conf/httpd.conf
sed -i "s|MaxClients 256|MaxClients $mc|g" /etc/httpd/conf/httpd.conf
sed -i 's|MaxRequestsPerChild 4000|MaxRequestsPerChild 2000|g' /etc/httpd/conf/httpd.conf
service httpd restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment