MySQL Optimizations
By Mr.Seiko on Mar 24, 2016 | In Uncategorized
cPanel/WHM come with a pretty decent all-around configuration, but when you're running a more powerful box, you can beef up your settings to get a little better performance.
Today, I'll cover a few Tweaks that can be done to Apache and MySQL to get that little extra bang out of your server that's not just a little VPS running 4-5 sites.
For Easy Apache, I went with the following, to keep up with new features, but not be 'bleeding edge'
In the first stage we run the Easy Apache and selected the following:
Apache Version 2.4
PHP Version 5.5
In step 5 “Exhaustive Options List” selected – Deflate – Expires – MPM Prefork and – MPM Worker
Next item to review is the Apache Global Configuration limits
WHM » Service Configuration » Apache Configuration » “Global Configuration”
These are pretty generic numbers based on how many GB's of ram on the server, these can still be tweaked a little further based on your usage,
Apache Directive 2GB 6GB 12GB StartServers 4 8 16 MinSpareServers 4 8 16 MaxSpareServers 8 16 32 ServerLimit 64 128 256 MaxRequestWorkers 50 120 250 MaxConnectionsPerChild 1000 2500 5000 Keep-Alive On On On Keep-Alive Timeout 5 5 5 Max Keep-Alive Requests 50 120 120 Timeout 30 60 60
From here, I wanted to add in some basic Caching to Apache by default, so even is users don't specify Cache lifetimes, this will override.
WHM » Service Configuration » Apache Configuration » Include Editor » “Pre VirtualHost Include”
# Cache Control Settings for one hour cache <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=86400, public" </FilesMatch> <FilesMatch ".(xml|txt)$"> Header set Cache-Control "max-age=86400, public, must-revalidate" </FilesMatch> <FilesMatch ".(html|htm)$"> Header set Cache-Control "max-age=3600, must-revalidate" </FilesMatch> # Mod Deflate performs data compression <IfModule mod_deflate.c> <FilesMatch ".(js|css|html|php|xml|jpg|png|gif)$"> SetOutputFilter DEFLATE BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4.0[678] no-gzip BrowserMatch bMSIE no-gzip </FilesMatch> </IfModule>
With this, basic media files, such as images and flash vids are forcibly browser cached for a day, and html files for an hour.
This helps to account for the inaction of clients, and ensure that basic caches are in place. Making page loads a little faster, and server loads a little slower for repeat visitors.
In /etc/my.cnf I made the following additions to optimize the connections and buffering.
[mysqld] local-infile=0 max_connections = 600 max_user_connections=1000 key_buffer_size = 512M myisam_sort_buffer_size = 64M read_buffer_size = 1M table_open_cache = 5000 thread_cache_size = 384 wait_timeout = 20 connect_timeout = 10 tmp_table_size = 256M max_heap_table_size = 128M max_allowed_packet = 64M net_buffer_length = 16384 max_connect_errors = 10 concurrent_insert = 2 read_rnd_buffer_size = 786432 bulk_insert_buffer_size = 8M query_cache_limit = 5M query_cache_size = 128M query_cache_type = 1 query_prealloc_size = 262144 query_alloc_block_size = 65535 transaction_alloc_block_size = 8192 transaction_prealloc_size = 4096 max_write_lock_count = 8 slow_query_log log-error external-locking=FALSE open_files_limit=50000 [mysqld_safe] [mysqldump] quick max_allowed_packet = 16M [isamchk] key_buffer = 384M sort_buffer = 384M read_buffer = 256M write_buffer = 256M [myisamchk] key_buffer = 384M sort_buffer = 384M read_buffer = 256M write_buffer = 256M #### Per connection configuration #### sort_buffer_size = 1M join_buffer_size = 1M thread_stack = 192K
Then ran a Repair & optimize on the databases and restarted MySQL:
mysqlcheck --check --auto-repair --all-databases mysqlcheck --optimize --all-databases /etc/init.d/mysql restart
No feedback yet
| « cPanel Default Page | Preventing Outgoing Spam » |