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




kill killall kill processes kill signals

root@vm1:/home/user1# pgrep haproxy
926
root@vm1:/home/user1# killall -0 haproxy
root@vm1:/home/user1# echo $?
0
root@vm1:/home/user1# killall -0 jpt_process
haproxyd: no process found
root@vm1:/home/user1# echo $?
1

Many UNIX dæmons store their process IDs in a file in /var/run when they are started. Using kill -0 to test the pid is a lot easier than parsing ps output



 $ echo $$     # show our process id
 12833
 $ /bin/bash   # create new process
 $ echo $$     # show new process id
 12902
 $ kill -0 12902
 $ echo $?     # exists, exit code is 0
 0
 $ exit        # return to previous shell
 $ kill -0 12902
 bash: kill: (12902) - No such process
 $ echo $?     # doesn't exist, exit code is 1
 1


###############

Most Linux or UNIX users know that there is a kill(1) command to stop processes, but what are the options, what do they mean?
These options are called signals, which can be expressed in either numbers or words. Some known once are "-1" or "-HUP". Also well known is "-9" (aka "-KILL")
  • -1 or -HUP - This argument makes kill send the "Hang Up" signal to processes. This probably originates from the modem/dial-in era. Processes have to be programmed to actually listen to this process and do something with it. Most daemons are programmed to re-read their configuration when they receive such a signal. Anyway; this is very likely the safest kill signal there is, it should not obstruct anything.
  • -2 or -SIGINT - This is the same as starting some program and pressing CTRL+C during execution. Most programs will stop, you could lose data.
  • -9 or -KILL - The kernel will let go of the process without informing the process of it. An unclean kill like this could result in data loss. This is the "hardest", "roughest" and most unsafe kill signal available, and should only be used to stop something that seems unstoppable.
  • -15 or -TERM - Tell the process to stop whatever it's doing, and end itself. When you don't specify any signal, this signal is used. It should be fairly safe to perform, but better start with a "-1" or "-HUP".
To figure out how a program should respond to kill signals, check the man(1) page of the process you are trying to kill. For example the process init(8) has a man-page that explains: SIGHUP Has the same effect as telinit q. ... Q or q tell init to re-examine the /etc/inittab file.
By the way, there are many signals: :) [robertdb@node1 ~]$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1

secure vsftpd ssl tls

configure vsftpd to use TLS/SSL

root@vm1:~# cat /etc/vsftpd.conf | grep -v "^#"
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
ssl_enable=YES  #
allow_anon_ssl=NO #
force_local_data_ssl=YES #
force_local_logins_ssl=YES #
ssl_tlsv1=YES #
ssl_sslv2=NO #
ssl_sslv3=NO #
listen=YES#
anonymous_enable=NO  #
local_enable=YES #
write_enable=YES  #
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
ftpd_banner=Warning !!! All activities are logged.
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
allow_writeable_chroot=YES
pasv_enable=Yes
pasv_min_port=40000
pasv_max_port=40100
require_ssl_reuse=NO
ssl_ciphers=HIGH

##GEnerate ssl certificate
sudo openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem


# service vsftpd restart
vsftpd stop/waiting
vsftpd start/running, process 3096

###### FTP client connection

open filezilla
File - > site manager ->
host:  ip or hostname
protocol: FTP
Encryption: Require explicit FTP over TLS
Logontype: Normal
User:  terminator1
Password: ***********

OK <finish>

Now connect