Skip to content

Chris' Laboratory

chrislee.kr – Personal blog as bookshelves

Menu
  • Home
  • Github
  • Contact Me
Menu

VPS – Apache & MySQL Performance Tuning

Posted on 13/03/201429/08/2020 by Chris Lee
Read Time:3 Minute, 4 Second

Apache

1. Open/Create /var/www/vhosts/{hostname}/conf/vhosts.conf

2. Add oradjust below code

KeepAlive On
MaxKeepAliveRequests 29
KeepAliveTimeout 15

3. Copy to make backup of apache configuration

# cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.YYYY-MM-DD.bak

4. Execute below shell script one by one

# ramCount=`awk 'match($0,/vmguar/) {print $4}' /proc/user_beancounters`
# ramBase=-16 && for ((;ramCount>1;ramBase++)); do ramCount=$((ramCount/2)); done
# perl -0 -p -i -e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?StartServers\s*?)\s\d+/\1\ '"$ramBase"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?MinSpareServers\s*?)\s\d+/\1\ '"$ramBase"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?MaxSpareServers\s*?)\s\d+/\1\ '"$(($ramBase*2 + 1))"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?ServerLimit\s*?)\s\d+/\1\ '"$(( 50 + (($ramBase**2)*10) + (($ramBase-2)*10) ))"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?MaxClients\s*?)\s\d+/\1\ '"$(( 50 + (($ramBase**2)*10) + (($ramBase-2)*10) ))"'/;' \
-e 's/(\<IfModule\sprefork\.c\>(\n|[^\n])*?MaxRequestsPerChild\s*?)\s\d+/\1\ '"$(( 2048 + ($ramBase*256) ))"'/;' /etc/httpd/conf/httpd.conf
/etc/init.d/httpd restart

5. Create fake swap using following shell script

# free -m
# vi fakeswap.sh

6. Copy and Paste below script to fakeswap.sh

#!/bin/bash

SWAP="${1:-512}"

NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0"

umount /proc/meminfo 2> /dev/null
sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo

free -m
# chmod +x fakeswap.sh
# sh fakeswap.sh 1024
# free -m

 

MySQL

1. Backup current MySQL configuration

# cp /etc/my.cnf /etc/my.cnf.YYYY-MM-DD.bak
# vi /etc/my.cnf

2. Add/Replace below configuration and adjust values (CAUTION: this is just example)

[mysqld]
key_buffer_size = 384M
table_open_cache = 5096
max_connections = 400
key_buffer = 128MB
myisam_sort_buffer_size = 64MB
join_buffer_size = 5M
read_buffer_size = 2M
sort_buffer_size = 2M
read_rnd_buffer_size = 8M
table_cache = 2048
thread_cache_size = 8
interactive_timeout = 25
wait_timeout = 1000
connect_timeout = 10
max_allowed_packet = 32M
max_connect_errors = 10
query_cache_limit = 6M
query_cache_size = 64M
query_cache_type = 1
tmp_table_size = 64M
max_heap_table_size = 64M

local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

innodb_buffer_pool_size=120M
innodb_additional_mem_pool_size=500K
innodb_log_buffer_size=500K
innodb_thread_concurrency=2
[mysqld_safe]
open_files_limit = 8192
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
innodb_buffer_pool_size=120M
innodb_additional_mem_pool_size=500K
innodb_log_buffer_size=500K
innodb_thread_concurrency=2

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

local-infile=0
# /etc/rc.d/init.d/mysql restart

3. Download mysqltuner.pl

https://github.com/major/MySQLTuner-perl/blob/master/mysqltuner.pl

4. Execute mysqltuner.pl and follow suggestions

# chmod 777 mysqltuner.pl
# ./mysqltuner.pl

 

 

 

 

 

Reference:

https://kb.mediatemple.net/questions/246/Making+it+Better%3A+Basic+Apache+performance+tuning+%28httpd%29#dv

http://linux-problem-solver.blogspot.com.au/2013/08/create-fake-swap-in-openvz-vps-if-you-get-swapon-failed-operation-not-permitted-error.html

http://www.maxwhale.com/how-to-optimize-mysql-for-1gb-memory-vps/

 

 

Share

Facebook
Twitter
LinkedIn
Email

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • Databases (11)
    • MongoDB (4)
    • MS-SQL (1)
    • MySQL (6)
  • E-Commerce (8)
    • Magento (8)
  • Finance (2)
  • Frameworks (84)
    • Adobe Flex (1)
    • Angular (ngx) (3)
    • Codeigniter (6)
    • CSS (5)
    • Django (2)
    • Javascript (13)
    • Node.js (6)
    • PHP (17)
    • React Native (4)
    • React.js (1)
    • Sencha Touch (4)
    • Terraform (1)
    • Vue.js (1)
    • WordPress (4)
    • Yii2 (3)
  • General Documents (15)
  • Marketing (3)
  • Mobile Development (33)
    • Android (20)
    • iPhone (13)
  • Platforms (21)
    • Arduino (2)
    • Docker (5)
    • Google App Engine (5)
    • Raspberry Pi (5)
    • Samsung Smart TV (4)
  • Security (17)
  • Server (31)
    • Linux (13)
  • Tools (14)
    • SVN (7)
  • Uncategorized (2)

Search

Recent Posts

  • Bootstrapping Kubernetes cluster with kubeadm
  • Taint all resources in the one module
  • Alpine – Plugin caching_sha2_password could not be loaded
  • npm link with peerDependencies
  • How to setup Gitlab runner with KVM enabled

Recent Comments

  • Obayed on Binance Auto Trading Bot – Buy low/Sell high with stop loss limit/Trade multiple coins
  • Ari on How to install memcache.so/memcached.so for MAMP Pro (Mac)
  • Mida ali on Binance Auto Trading Bot – Buy low/Sell high with stop loss limit/Trade multiple coins
  • Chris Lee on How to install memcache.so/memcached.so for MAMP Pro (Mac)
  • Chris Lee on Setting Up A VPN Server On OSX 10.6

Tags

1 ajax amazon android android-addpart browser chrislee-kr codeigniter codeigniter-tcpdf com-apple-net-racoon CSS CSS history hack delpaigmail-com entity-addpart-double exception-printing-is-disabled-by-default-for-security-reasons ext-plugins-listpagingplugin ext-plugins-listpagingplugin-example f iphone javascript jquery-defaultchecked jquery-samsung-smart-tv listpagingplugin mac magento-exception-printing-is-disabled-by-default-for-security-reasons magento-sample-data-exception-printing-is-disabled-by-default-for-security-reasons nu-vot null-core-errors-confignotfound-config-mk9engine-ini php samsung-smart-tv-jquery samsung-smart-tv-sdk-ajax samsung-smart-tv-sdk-jquery samsung-tv-sdk samsung-tv-sdk-jquery samsung tv sencha-smart-tv sencha-touch-list-paging smart-tv-jquery sqlite subversion svn tcedook tcpdf-codeigniter uilinebreakmodecharacterwrap-is-deprecated unknown-column-link-area

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2023 Chris' Laboratory | Powered by Minimalist Blog WordPress Theme