highly available LAMP project

##note: make sure to remove older versions
add-apt-repository ppa:vbernat/haproxy-1.5
apt-get update
apt-get install -y haproxy keepalived
apt-get install lvm2 xfsprogs

##setup lvm disk for storing webdata(html,php,image etc)

add => at end of /etc/sysctl.conf

net.ipv4.ip_nonlocal_bind=1  ##enable for floating ip address not binded to interfae

#run
sysctl -p

 Add firewall rules to allow VRRP communication using the multicast IP address 224.0.0.18 
 and the VRRP protocol (112) on each network interface that Keepalived will control, for example:  
 # iptables -I INPUT -i eth0 -d 224.0.0.0/8 -p vrrp -j ACCEPT  
 # iptables -I OUTPUT -o eth0 -d 224.0.0.0/8 -p vrrp -j ACCEPT  
 # service iptables save  


Keepalived is a piece of software which can be used to achieve high availability by assigning two or more nodes a virtual IP and monitoring those nodes, failing over when one goes down. Keepalived can do more, like load balancing and monitoring,
Keepalived performs failover on layer 4, or the Transport layer, upon which TCP conducts connection-based data transmissions. When a real server fails to reply to simple timeout TCP connection, keepalived detects that the server has failed and removes it from the server pool.

############### keepalive of  LB1


root@vm1:~# cat /etc/keepalived/keepalived.conf
# Settings for notifications
global_defs {
    notification_email {
        your@emailaddress.com     # Email address for notifications
    }
    notification_email_from loadb01@domain.ext  # The from address for the notifications
    smtp_server 127.0.0.1     # You can specifiy your own smtp server here
    smtp_connect_timeout 15
}

# Define the script used to check if haproxy is still working
vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2
    weight 2
}

# Configuation for the virtual interface
vrrp_instance VI_1 {
    interface eth0
    state MASTER        # set this to BACKUP on the other machine
    priority 100        # set this to number > 100 on the other machine
    virtual_router_id 51

    smtp_alert          # Activate email notifications

    authentication {
        auth_type PASS
        auth_pass myPassw0rd      # Set this to some secret phrase
    }

    # The virtual ip address shared between the two loadbalancers
    virtual_ipaddress {
        192.168.163.200
    }
   
    # Use the script above to check if we should fail over
    track_script {
        chk_haproxy
    }
}

####keepalive of LB2

root@vm2:/etc/keepalived# cat keepalived.conf
# Settings for notifications
global_defs {
    notification_email {
        your@emailaddress.com     # Email address for notifications
    }
    notification_email_from loadb01@domain.ext  # The from address for the notifications
    smtp_server 127.0.0.1     # You can specifiy your own smtp server here
    smtp_connect_timeout 15
}

# Define the script used to check if haproxy is still working
vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2
    weight 2
}

# Configuation for the virtual interface
vrrp_instance VI_1 {
    interface eth0
    state BACKUP        # set this to BACKUP on the other machine
    priority 101        # set this to 100 on the other machine
    virtual_router_id 51

    smtp_alert          # Activate email notifications

    authentication {
        auth_type PASS
        auth_pass myPassw0rd      # Set this to some secret phrase
    }

    # The virtual ip address shared between the two loadbalancers
    virtual_ipaddress {
        192.168.163.200
    }
   
    # Use the script above to check if we should fail over
    track_script {
        chk_haproxy
    }
}
############################

@Server 1  = vm3.demo.com

#gluster peer probe vm4.demo.com

#gluster volume create volume1 replica 2 transport tcp vm3.demo.com:/glusterdata vm4.demo.com:/glusterdata force

#gluster volume start volume1
#gluster volume info


#### @server 1  Edit   /etc/fstab  and mount
#### lvm mount params
/dev/vg1-01/lv1-01     /storagepool     xfs     defaults     0     0     ###for gluster data

####gluster volume mount  for shared web data
vm3.demo.com:/volume1      /storagepool    glusterfs defaults,_netdev   0   0


#mount -a               ##mount the FS and see the gluster fs changes




No comments:

Post a Comment