Load Balancing PHP, Tomcat & Master Slave MySQL

Load Balancing
Load Balancing


Load Balancing PHP & Tomcat

MySQL Master 

MySQL Slave 


#
global
        pidfile /var/run/haproxy.pid
        log 127.0.0.1 local0
        log 127.0.0.1 local1 notice
        daemon
        user haproxy
        group haproxy
        stats socket /tmp/haproxy.socket user nobody group nobody mode 600 level admin
        node HAPROXY-APSS
        description HAPROXY-PHP-TOMCAT
        maxconn 40000
        ulimit-n  102400
        spread-checks 3
        #quiet

defaults
        log    global
        option  dontlognull
        #option tcp-smart-accept
        #option tcp-smart-connect
        retries 3
        #option forwardfor # insert x-forwarded-for header so that app servers can see both proxy and client IPs
        option redispatch # any server can handle any session
        timeout client 60s
        timeout connect 9s
        timeout server 30s
        timeout check 5s
        #option http-server-close
        userlist shareaholic_admins
        user admin insecure-password rahasia  # Real auth redacted

listen APP
        bind *:80
        mode http
        option  dontlognull
        option tcp-smart-accept
        option tcp-smart-connect
        option http-server-close
        option http-pretend-keepalive
        option forwardfor
        option httplog
        balance roundrobin
        #balance source
        #option forwardfor except 127.0.0.1
        mode http
        option httpchk
        balance roundrobin
 appsession PHPSESSID len 64 timeout 3h request-learn prefix
        cookie SRVNAME insert nocache indirect
        server www1 10.10.10.5:80 cookie www1 check
        server www2 10.10.10.6:80 cookie www2 check

listen TOMCAT
        bind *:8080
        mode http
        option  dontlognull
        option tcp-smart-accept
        option tcp-smart-connect
        option http-server-close
        option http-pretend-keepalive
        option forwardfor
        option httplog
        balance roundrobin
        mode http
        option httpchk
        balance roundrobin
        cookie JSESSIONID prefix
        cookie SRVNAME insert nocache indirect
        server java1 10.10.10.5:8080 cookie java1 check
        server java2 10.10.10.6:8080 cookie java2 check

listen STATS_PAGE *:9600
        stats enable
        mode http
        stats refresh 60s
        stats uri /stats # Real path redacted
        stats realm Haproxy\ Statistics
        stats auth admin:password # Real credentials redacted
        monitor-uri /monitor # Returns 200 if we're up; real path redacted
        errorfile 503 /usr/share/haproxy/503.http

cat /etc/my.cnf
# All files in this package is subject to the GPL v2 license
# More information is in the COPYING file in the top directory of this package.
# Copyright (C) 2011 severalnines.com

[MYSQLD]
user=mysql
basedir=/usr/
datadir=/var/lib/mysql/
socket=/var/lib/mysql/mysql.sock
pid-file=mysqld.pid
bind-address=0.0.0.0
port=3306
log-error=error.log
#log-output=FILE
relay-log=relay-bin
default-storage-engine=innodb

### INNODB
innodb-buffer-pool-size=11489M
innodb-flush-log-at-trx_commit=2
innodb-file-per-table=1
## You may want to tune the below depending on number of cores and disk sub
innodb_read_io_threads=8
innodb_write_io_threads=8
#innodb_io_capacity=20000
#innodb_io_capacity_max=40000
innodb-doublewrite=1
innodb_log_file_size=512M
innodb-log-files-in-group=2
innodb-buffer-pool-instances=4
innodb-thread-concurrency=0
## avoid statistics update when doing e.g show tables
innodb_stats_on_metadata=0
innodb-file-format=barracuda
innodb-flush-method = O_DIRECT

innodb_open_files = 2710

#REPLICATION SPECIFIC - GENERAL
#server-id must be unique across all mysql servers participating in replication.
server-id=1
auto_increment_increment=2
auto_increment_offset=1

#REPLICATION SPECIFIC - MASTER /SLAVE
#YOU MAY WANT TO TUNE sync-xxx
binlog-format=ROW
gtid-mode=ON
enforce-gtid-consistency=1
master-info-repository=TABLE
relay-log-info-repository=TABLE
slave-parallel-workers=0
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
expire-logs-days=5
sync-binlog=5
sync-master-info=0
sync-relay-log=5
sync-relay-log-info=0
log-bin=binlog
log-slave-updates=1

loose-rpl-semi-sync-master-enabled=1
loose-rpl-semi-sync-slave-enabled=1
loose-rpl-semi-sync-master-timeout=10000

relay-log-recovery=1
skip-slave-start=1
skip-name-resolve
explicit_defaults_for_timestamp=1

connect-timeout = 1000
max_connect_errors = 9999999
open_files_limit = 102400

#OTHER THINGS, BUFFERS ETC
key_buffer_size = 256M
max-allowed-packet = 16M
sort-buffer-size = 512K
read-buffer-size = 256K
read-rnd-buffer-size = 512K

#thread-cache-size=1024
myisam-sort-buffer_size = 8M
memlock=0
sysdate-is-now=1
max-connections=200
thread-cache-size=256
query-cache-type = 2
query-cache-size = 32M
table-open_cache=1024
lower-case-table-names=0


[MYSQL]
socket=/var/lib/mysql/mysql.sock
[client]
socket=/var/lib/mysql/mysql.sock
[MYSQLD_SAFE]
log-error=error.log
pid-file=mysqld.pid
basedir=/usr/
datadir=/var/lib/mysql/


# All files in this package is subject to the GPL v2 license
# More information is in the COPYING file in the top directory of this package.
# Copyright (C) 2011 severalnines.com

[MYSQLD]
user=mysql
basedir=/usr/
datadir=/var/lib/mysql/
socket=/var/lib/mysql/mysql.sock
bind-address=0.0.0.0
port=3306
default-storage-engine=innodb

log-error=error.log
log-output=FILE
#REPLICATION SPECIFIC - GENERAL
#server-id must be unique across all mysql servers participating in replication.
server-id=2

expire-logs-days=5
binlog-format=ROW
gtid-mode=ON
enforce-gtid-consistency=1
master-info-repository=TABLE
relay-log-info-repository=TABLE
slave-parallel-workers=0
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
auto-increment-increment=2
auto-increment-offset=2
relay-log=relay
explicit_defaults_for_timestamp=1
### INNODB
innodb-buffer-pool-size=11489M
innodb-flush-log-at-trx_commit=2
innodb-file-per-table=1
## You may want to tune the below depending on number of cores and disk sub
innodb_read_io_threads=8
innodb_write_io_threads=8
#innodb_io_capacity=20000
#innodb_io_capacity_max=40000
innodb-doublewrite=1
innodb_log_file_size=512M
innodb-log-files-in-group=2
innodb-buffer-pool-instances=4
innodb-thread-concurrency=0
## avoid statistics update when doing e.g show tables
innodb_stats_on_metadata=0
innodb-file-format=barracuda
innodb-flush-method = O_DIRECT
innodb_open_files = 2710

#REPLICATION SPECIFIC - SLAVE - YOU MAY WANT TO TUNE
relay-log-purge=1
sync-binlog=5
sync-master-info=0
sync-relay-log=5
sync-relay-log-info=0
relay-log-recovery=1
read-only=1

#skip-slave-start=1
skip-name-resolve

open_files_limit = 102400
connect-timeout = 1000
max_connect_errors = 9999999

log-bin=binlog
log-slave-updates=1
#OTHER THINGS, BUFFERS ETC
key_buffer_size = 256M
max-allowed-packet = 16M
sort-buffer-size = 512K
read-buffer-size = 256K
read-rnd-buffer-size = 512K
myisam-sort-buffer-size = 8M
memlock=0
sysdate-is-now=1
max-connections=200
thread-cache-size=256
query-cache-type = 2
query-cache-size = 32M
table-open_cache=1024
lower-case-table-names=0
[MYSQL]
socket=/var/lib/mysql/mysql.sock
[client]
socket=/var/lib/mysql/mysql.sock
[MYSQLD_SAFE]
pid-file=mysqld.pid
log-error=error.log
basedir=/usr/
datadir=/var/lib/mysql/