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/

Howto Power DNS block porn


Power DNS
Power DNS

 Howto Power DNS block porn
#############DEBIAN##############
apt-get install mysql-client mysql-server pdns-server pdns recursor pdns-backend-mysql pdns-server

#cat /etc/powerdns/pdns.conf
allow-recursion=127.0.0.1, 172.17.17.0/30, 172.16.0.0/12,192.168.0.0/16,10.0.0.0/8
config-dir=/etc/powerdns
daemon=yes
disable-axfr=yes
distributor-threads=4
guardian=yes
launch=gmysql
gmysql-host=127.0.0.1
gmysql-user=pdns
gmysql-password=rahasia
gmysql-dbname=pdns
gmysql-socket=/var/run/mysqld/mysqld.sock
max-cache-entries=10000000
lazy-recursion=yes
local-address=0.0.0.0
local-port=53
master=yes
module-dir=/usr/lib/powerdns
recursor=127.0.0.1:5300
setgid=pdns
setuid=pdns
socket-dir=/var/run
webserver=yes
webserver-address=192.168.111.2
webserver-port=8081
wildcards=on
version-string=powerdns

############CENTOS#############
yum install pdns pdns-backend-mysql pdns-server  pdns-recursor
chkconfig --levels 235 pdns on
chkconfig --levels 235 pdns-recursor on

#############
cat /etc/pdns/pdns.conf
setgid=pdns
setuid=pdns
launch=gmysql
gmysql-host=127.0.0.1
gmysql-user=pdns
gmysql-password=rahasia
gmysql-dbname=pdns
allow-recursion=127.0.0.1,172.16.0.0/12,192.168.0.0/16,10.0.0.0/8
config-dir=/etc/pdns
daemon=yes
disable-axfr=yes
distributor-threads=4
guardian=yes
gmysql-socket=/var/lib/mysql/mysql.sock
lazy-recursion=yes
local-address=0.0.0.0
local-port=53
master=yes
module-dir=/usr/lib64/pdns
recursor=127.0.0.1:5300
socket-dir=/var/run
webserver=yes
webserver-address=192.168.0.99
webserver-port=8081
wildcard-url=on
version-string=powerdns


#############
#cat /etc/pdns-recursor/recursor.conf
setuid=pdns-recursor
setgid=pdns-recursor
config-dir=/etc/pdns-recursor/
allow-from=127.0.0.0/8, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12
local-address=127.0.0.1
local-port=5300
quiet=yes
#############


wget "http://urlblacklist.com/cgi-bin/commercialdownload.pl?type=download&file=bigblacklist" -O /tmp/bigblacklist.tar.bz2
tar xvf bigblacklist.tar.bz2 -C /tmp/
cd /tmp
cp blacklists/porn/domains /tmp/
mv blackdomains /var/lib/mysql/powerdns/
mysql -uroot -pvertrigo -Dpdns -e "LOAD DATA INFILE 'blackdomains' INTO TABLE domains"
mysql -uroot -pvertrigo -Dpdns -e "select id,name from domains" > forrecord
awk '{print "NULL" "\t" $1 "\t" $2 "\t" "A" "\t" "118.98.97.100" "\t" "86400" "\t" "0" "\t" "1286888925" }' forrecord > sqlrecords
awk '{print "NULL" "\t" $1 "\t" "*."$2 "\t" "A" "\t" "118.98.97.100" "\t" "86400" "\t" "0" "\t" "1301888925" }' forrecord > wildcard
awk '{print "NULL" "\t" $1 "\t" $2 "\t" "SOA" "\t" "nms fahmi@idmail.or.id 1" "\t" "86400" "\t" "1301888925" "\t" "NULL" }' forrecord > soarecords
cp soarecords  /var/lib/mysql/pdns
cp wildcard /var/lib/mysql/pdns
cp sqlrecords  /var/lib/mysql/pdns
mysql -uroot -pvertrigo -Dpdns -e "LOAD DATA INFILE 'sqlrecords' INTO TABLE records"
mysql -uroot -pvertrigo -Dpdns -e "LOAD DATA INFILE 'wildcard' INTO TABLE records"
mysql -uroot -pvertrigo -Dpdns -e "LOAD DATA INFILE 'soarecords' INTO TABLE records"