Daily Archives: May 28, 2012

Check Service MYSQL using Xinet.d , Telnet Service MYSQL


[root@svrrepo html]# vim /opt/mysqlchk

#!/bin/bash
MYSQL_HOST=”localhost”
MYSQL_PORT=”3306″
MYSQL_USERNAME=”root”
MYSQL_PASSWORD=”passowordku”

TMP_FILE=”/tmp/mysqlchk.out”
ERR_FILE=”/tmp/mysqlchk.err”

/usr/bin/mysql –host=$MYSQL_HOST –port=$MYSQL_PORT –user=$MYSQL_USERNAME \
–password=$MYSQL_PASSWORD -e”show databases;” > /dev/null
RETVAL=$?

if [ “${RETVAL}” -eq “0” ]
then
# mysql is fine, return http 200
/bin/echo -e “HTTP/1.1 200 OK\r\n”
/bin/echo -e “Content-Type: Content-Type: text/plain\r\n”
/bin/echo -e “\r\n”
/bin/echo -e “MySQL is running.\r\n”
/bin/echo -e “\r\n”
else
# mysql is fine, return http 503
/bin/echo -e “HTTP/1.1 503 Service Unavailable\r\n”
/bin/echo -e “Content-Type: Content-Type: text/plain\r\n”
/bin/echo -e “\r\n”
/bin/echo -e “MySQL is *down*.\r\n”
/bin/echo -e “\r\n”
fi

save wq!

[root@svrrepo html]# vim /etc/xinetd.d/mysqlchk

# /etc/xinetd.d/mysqlchk
# default: on
# description: mysqlchk
service mysqlchk
{
flags = REUSE
socket_type = stream
port = 9200
wait = no
user = nobody
server = /opt/mysqlchk
log_on_failure += USERID
disable = no
only_from = 0.0.0.0/0 # recommended to put the IPs that need
# to connect exclusively (security purposes)
per_source = UNLIMITED # Recently added (May 20, 2010)
# Prevents the system from complaining
# about having too many connections open from
# the same IP. More info:
# http://www.linuxfocus.org/English/November2000/article175.shtml
}

save wq!

[root@svrrepo html]# vim /etc/services
#wap-wsp 9200/tcp # WAP connectionless session service
mysqlchk 9200/tcp
wap-wsp 9200/udp # WAP connectionless session service

save wq!

[root@svrrepo html]# /etc/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]

[root@svrrepo html]# telnet 192.168.0.253 9022
Trying 192.168.0.253…
telnet: connect to address 192.168.0.253: Connection refused
[root@svrrepo html]# telnet 192.168.0.253 9200
Trying 192.168.0.253…
Connected to 192.168.0.253.
Escape character is ‘^]’.
HTTP/1.1 200 OK

Content-Type: Content-Type: text/plain

MySQL is running.

Connection closed by foreign host.

Advertisements

Load Balance Webserver + HAProxy On Centos 6.2 / 64 bit


“HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the Net.” reff http://www.howtoforge.com/setting-up-a-high-availability-load-balancer-with-haproxy-keepalived-on-debian-lenny

 

Keterangan:

Server : 192.168.0.253 berfungsi sebagai load balancer ( server inilah yang akan di akses oleh client)

Server : 192.168.0.7 & 192.168.0.11 sebagai web server, sekaligus tempat aplikasi web yang akan di akses. so pastikan sudah terinstall paket apache.

Server 192.168.0.253

Install haproxy (sesuaikan dengan versi nya apakah menggunakan 32 or 64 bit)

[root@svrrepo ~]# rpm -ivh http://mirrors.ispros.com.bd/fedora-epel/6/x86_64/epel-release-6-7.noarch.rpm

[root@svrrepo ~]# yum search haproxy
haproxy.x86_64 : HA-Proxy is a TCP/HTTP reverse proxy for high availability environments
[root@svrrepo ~]# yum install haproxy.x86_64
Setelah proses instalasi ini maka akan membentuk satu user haproxy di /etc/passwd
[root@svrrepo haproxy]# cat /etc/passwd
haproxy:x:497:497:HAProxy user:/var/lib/haproxy:/bin/false

[root@svrrepo ~]# cd /etc/haproxy/
Backup config aslinya

[root@svrrepo haproxy]# cp haproxy.cfg haproxy.cfg.def

[root@svrrepo html]# vim /etc/haproxy/haproxy.cfg

#tambahkan baris berikut

listen SVR253 192.168.0.253:80 # ip server load balancer
mode http
balance roundrobin
cookie JSESSIONID prefix
option httpchk HEAD /check.txt HTTP/1.0
option httpclose
option forwardfor
stats auth testing1:testing1 #username untuk authentikasi untuk mengakses statistic haproxy
server server7 192.168.0.7:80 check cookie A check  # ip server web server1
server server11 192.168.0.11:80 check cookie B check # ip server web server 2

save wq!

check configurasi valid or not
[root@svrrepo haproxy]# haproxy -f /etc/haproxy/haproxy.cfg -c
Restart service

[root@svrrepo haproxy]#service haproxy start

Register sebagai service (runlevel) so boot pada saat startup server

[root@svrrepo haproxy]#chkconfig haproxy on

Login ke server 192.168.0.7 & 192.168.0.11

[root@server11 ~]# vim /var/www/html/index.php
<?php phpinfo();?>
[root@telephony ~]# vim /var/www/html/index.php
<?php phpinfo();?>

Akses http://192.168.0.253/index.php
harusnya sudah muncul isi dari phpinfo();

Untuk memonitor apakah loadbalancing sudah jalan maka akses http://192.168.0.253/haproxy?stats dan login dengan username sesuai dengan config yang ada di haproxy.conf (testing1:testing1)

Coba amati log di server 192.168.0.7 & 192.168.0.11 dengan command tail -f /var/log/http/access.log, kemudian matikan salah satu webserver apa yang terjadi??? Juga amati Bytes IN/Out pada monitoring:D

shisdew

Listens until think alike

moses.spaceku@yahoo.com / voip ipbx

Hosted PBX, IP-PBX SOHO/ CALL CENTER, VOICE GATEWAY, VOICE CARD, COST EFECTIVE SOLUTIONS (LCR), GSM/CDMA GATEWAY

%d bloggers like this: