Sunday, May 15, 2016

Set up High Availability with keepalived

First install the dependency

yum install openssl openssl-devel popt popt-devel

Now install gcc to build keepalived

yum install gcc

Install kernel headers and kernel devel package

yum -y install kernel-headers kernel-devel

Download keepalived 1.2.19

wget http://www.keepalived.org/software/keepalived-1.2.19.tar.gz

tar xzvf keepalived*

cd keepalived*

./configure
make
make install

 Now create an init file and configure it to auto start after restart

vi /etc/init/keepalived.conf

description "load-balancing and high-availability service"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

exec /usr/local/sbin/keepalived --dont-fork


Now create keepalived config file

mkdir -p /etc/keepalived

vi /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 101
        unicast_src_ip primary_private_IP
        unicast_peer {
            secondary_private_IP
        }
        authentication {
            auth_type PASS
            auth_pass Add-Your-Password-Here
        }
        virtual_ipaddress {
                202.54.1.1/29 dev eth1
        }
}


Use unicast_peer and unicast_src_ip to use Unicast, otherwise by default it will use Multicast.

You can use nopreempt to prevent auto take over by Master.

You can use vrrp_script to track you own application status

vrrp_script chk_nginx {
    script "pidof nginx"
    interval 2
}


Complete config file will look like

vrrp_script chk_nginx {
    script "pidof nginx"
    interval 2
}

vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 101
        unicast_src_ip primary_private_IP
        unicast_peer {
            secondary_private_IP
        }
        authentication {
            auth_type PASS
            auth_pass Add-Your-Password-Here
        }
        virtual_ipaddress {
                202.54.1.1/29 dev eth1
        }
 
        track_script {
                chk_nginx
        }

    notify_master /etc/keepalived/master.sh

}

Monday, September 21, 2015

Force load on CPU - Linux

Today I needed to create a spike on CPU in my CentOS 7 Server.

I logged in using Putty and wrote the below command

for i in 1 2 3 4 5 6 7 8; do while : ; do : ; done & done

Then all of my 8 Cores became 100%

Sunday, September 21, 2014

Change DATA directory of PostgreSQL in CentOS

You need to stop the PostgreSQL first to change the DATA directory.

service postgresql stop

Now edit the start-up script

vi /etc/rc.d/init.d/postgresql

Change the PGDATA and PGLOG variable to wherever you want

Create the directory and set the permissions

mkdir -p /home/data/path
chown postgres:postgres /home/data/path

Initialize the database engine

su - postgres -c "initdb -D /path/to/pgdata"

Now start the PostgreSQL

service postgresql start

If you see FAILED and Permission denied message, check SELinux mode.
stop the SELinux OR change the mode enforcing to permissive.

Saturday, August 9, 2014

Install phpMyAdmin in CentOS

The easiest way to install phpMyAdmin is using EPEL Repositories.

Add EPEL repositories to your yum source by downloading a configuration file from the repository.

wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Install the package running the following command

rpm -ivh epel-release*

Then run the following command

yum install phpmyadmin

You may be asked to confirm once or twice, and then the packages will be installed.

Note: You need to have apache and MySQL installed in your system to access phpMyAdmin.

Now configure phpMyAdmin and allow IPs from where you want to access phpMyAdmin.

check the the following file to Allow/Deny Ips

/etc/httpd/conf.d/phpMyAdmin.conf

Now Access http://YOUR_IP/phpmyadmin

Monday, June 30, 2014

Install pptpd VPN server in centOS

To install PPTP in your centOS, first download the repo

rpm -i http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm

Now install PPTPD

yum -y install pptpd

Now edit /etc/pptpd.conf and add the following lines:

localip 192.168.10.1
remoteip 192.168.10.100-200

Where localip is IP address of the server and remoteip are IPs that will be assigned to clients that connect to it.

Now, you should setup authentication for PPTP by adding users and passwords.
Simply add them to /etc/ppp/chap-secrets :

user1 pptpd "password" *

Add DNS servers to /etc/ppp/pptpd-options

ms-dns 8.8.8.8
ms-dns 8.8.4.4

service pptpd restart

Verify that it is running and accepting connections:

netstat -alpn | grep :1723

Now enable forwarding. Simply edit /etc/sysctl.conf and add the following line if it doesn’t exist there already:

net.ipv4.ip_forward = 1

To make changes active, run

sysctl -p

Now create a NAT rule for iptables

iptables -t nat -A POSTROUTING -o venet0 -j MASQUERADE

If you would also like your PPTP clients to talk to each other, add the following iptables rules:

iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE
iptables -I INPUT -s 192.168.10.0/24 -i ppp0 -j ACCEPT
iptables --append FORWARD --in-interface venet0 -j ACCEPT

Now save iptables

iptables-save