Friday, March 22, 2013

Installing mysql in RHEL/Centos


Step 1) Adding user and group for mysql

groupadd mysql; useradd -r -g mysql mysql

step 2) download and untar mysql

cd /usr/local/
tar zxvf /usr/local/mysql-5.1.55-linux-i686-glibc23.tar.gz

step3) Creating soft link for mysql and change the permission files/directories

 ln –s /usr/local/mysql /usr/local/mysql-5.1.55-linux-i686-glibc23.tar.gz
cd mysql
chown -R mysql. *

Step4) Run mysql_install script

scripts/mysql_install_db --user=mysql

step5) copy my.cnf to /etc/my.cnf

cp support-files/my-medium.cnf /etc/my.cnf

step6) Run Mysql in safe mode

bin/mysqld_safe --user=mysql &

step 7) copy mysql init script on /etc/init.d

cp support-files/mysql.server /etc/init.d/mysql.server

Wednesday, March 20, 2013

FTPS configuration in vsftpd


We could configure ssl support in vsftpd by using below steps.

Step 1) Create ssl key and self sign certificate

openssl genrsa -out /etc/pki/tls/vsftpd.key 2048
openssl req -new -x509 -key /etc/pki/tls/vsftpd.key -out /etc/pki/tls/certs/vsftpd.crt -days 365

Step 2) Pass parameters in vsftpd.conf

==============================
ssl_enable=YES
allow_anon_ssl=YES
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_tlsv2=YES
ssl_tlsv3=YES
rsa_cert_file=/etc/pki/tls/certs/vsftpd.crt
rsa_private_key_file=/etc/pki/tls/vsftpd.key
================================

step 3) Restart vsftpd

service vsftpd restart

Note :-> As it's now supporting certificate based ftp connection, so you have to use ssl supported ftp client software (eg- ftp_ssl)

ftp_ssl 192.168.0.40

Tuesday, March 19, 2013

Chrooted VSFTPD configuration

Guys, Recently I configured vsftpd on one of my server.
So, Below I am sharing my steps to configure a FTP only account in vsftpd server.

==========================================
1) Create a ftp user

adduser -s /sbin/nologin ftpuser;passwd ftpuser

2) Create a directory for ftpuser

mkdir –p /var/test/ftpuser
chown ftpuser. /var/test/ftpuser
usermod -d /var/test/./ftpuser ftpuser

3) Change setting in vsftpd.conf

vi /etc/vsftpd/vsftpd.conf
chroot_list_enable = YES
passwd_chroot_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

4) List of such FTP Only users

vi /etc/vsftpd/chroot_list
ftpuser
======================


Friday, March 15, 2013

Nginx as a Load Balancer


Guys recently I implemented Nginx as a load balancer.
The scenario was that we have two Apache backend servers serving same webpage. We were using Amazon ELB as a front-end to balance load for those backend Apache servers. And we were paying to Amazon for their instance.
So I implemented (Replaced Nginx in place of ELB) Nginx as a load balancer.
Below is the sample configuration file of my nginx.conf
===============================================
upstream front_cluster {
        ip_hash;
        server 10.64.0.11:80    weight=1 max_fails=2 fail_timeout=20;
        server 10.64.0.10:80    weight=1 max_fails=2 fail_timeout=20;
        }
    server {
        listen       80 ; ssl off;
        listen 443   ssl;
        server_name  abc.com;
        access_log  logs/abc.com.access.log;
        error_log  logs/abc.com.error.log  info;
        ssl_certificate      /usr/local/nginx/abc.crt;
        ssl_certificate_key  /usr/local/nginx/abc.key;
        location / {
                proxy_pass http://front_cluster/;
                proxy_set_header Host $server_name;
        }
        location /lb_health_status {
                check_status;
                access_log   off;
        }
}
========================================
In this configuration we were using nginx for balancing https and https both traffic to backend servers.
Also we are checking the health status of backend servers by nginx health check module.

Thursday, March 14, 2013

Installing and configuring stunnel in Linux system



Step 1) Installing stunnel by sourcecode
tar zxf stunnel-4.XX.tar.gz
$ cd stunnel-4.XX
$ ./configure
$ make
$ make install   (as root)

Step 2) Enabling stunnel

echo "ENABLED=1" > /etc/default/stunnel

Step 3) Create a user stunnel for port redirection.
useradd  -s /sbin/nologin -M stunnel

Step 4) Creating init script for stunnel
vim /etc/init.d/stunnel
================================================
#! /bin/sh -e
### BEGIN INIT INFO
# chkconfig: 2345 54 26
# description:          stunnel
### END INIT INFO
DEFAULTPIDFILE="/var/run/stunnel.pid"
DAEMON=/usr/bin/stunnel
NAME=stunnel
DESC="SSL tunnels"
FILES="/etc/stunnel/*.conf"
OPTIONS=""
ENABLED=0

get_pids() {
   local file=$1
   if test -f $file; then
     CHROOT=`grep "^chroot" $file|sed "s;.*= *;;"`
     PIDFILE=`grep "^pid" $file|sed "s;.*= *;;"`
     if [ "$PIDFILE" = "" ]; then
       PIDFILE=$DEFAULTPIDFILE
     fi
     if test -f $CHROOT/$PIDFILE; then
       cat $CHROOT/$PIDFILE
     fi
   fi
}

startdaemons() {
  if ! [ -d /var/run/stunnel ]; then
    rm -rf /var/run/stunnel
    install -d -o stunnel -g stunnel /var/run/stunnel
  fi
  for file in $FILES; do
    if test -f $file; then
      ARGS="$file $OPTIONS"
      PROCLIST=`get_pids $file`
      if [ "$PROCLIST" ] && kill -s 0 $PROCLIST 2>/dev/null; then
        echo -n "[Already running: $file] "
      elif $DAEMON $ARGS; then
        echo -n "[Started: $file] "
      else
        echo "[Failed: $file]"
        echo "You should check that you have specified the pid= in you configuration file"
        exit 1
      fi
    fi
  done;
}

killdaemons()
{
  SIGNAL=${1:-TERM}
  for file in $FILES; do
    PROCLIST=`get_pids $file`
    if [ "$PROCLIST" ] && kill -s 0 $PROCLIST 2>/dev/null; then
       kill -s $SIGNAL $PROCLIST
       echo -n "[stopped: $file] "
    fi
  done
}

if [ "x$OPTIONS" != "x" ]; then
  OPTIONS="-- $OPTIONS"
fi

test -f /etc/default/stunnel && . /etc/default/stunnel
if [ "$ENABLED" = "0" ] ; then
  echo "$DESC disabled, see /etc/default/stunnel"
  exit 0
fi

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        startdaemons
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        killdaemons
        echo "$NAME."
        ;;
  reopen-logs)
        echo -n "Reopening log files $DESC: "
        killdaemons USR1
        echo "$NAME."
        ;;
  force-reload|reload)
        echo -n "Reloading configuration $DESC: "
        killdaemons HUP
        echo "$NAME."
        ;; 
  restart)
        echo -n "Restarting $DESC: "
        killdaemons
        sleep 5
        startdaemons
        echo "$NAME."
        ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|reload|reopen-logs|restart}" >&2
        exit 1
        ;;
esac

exit 0
===============================================
chmod +x /etc/init.d/stunnel

Step 5) Create key and certificate
openssl req -new -x509 -nodes -out cert.pem -keyout cert.key -days 365

Copy the key and certs to server

Step 6) Stunnel server configuration for accepting data on port 11612 and transferring data to port 10051 of local system(192.168.0.5)

vim /etc/stunnel/stunnel.conf
cert = /etc/stunnel/cert.pem
key = /etc/stunnel/cert.key
#Debug - emerg (0), alert (1), crit (2), err (3), warning (4), notice (5), info (6), or debug (7)
debug=1
output=/var/log/stunnel.log
[ZAB_Server]
accept=11612
connect=127.0.0.1:10051
===========================
chown -R stunnel:stunnel /etc/stunnel
service stunnel restart

Note: You could directly use command for this setup as written below

stunnel -P/tmp/ -p /etc/stunnel/cert.pem -d 11612 -r localhost: 10051

Step7)  Stunnel configuration for client for accepting data on port 10052 and transferring data to port 10051 of stunnel server (192.168.0.5)

================================
#cert = /etc/stunnel/cert.pem
client = yes
output = /var/log/stunnel.log
[ZAB]
accept = 10052
connect =192.168.0.5:11612
==================================
chown -R stunnel:stunnel /etc/stunnel
service stunnel restart

Note: You could directly use command for this setup as written below

stunnel -P/tmp/ -c -d 10052 -r 192.168.0.5:11612

Saturday, March 9, 2013

Webmin, A GUI tool to manage Linux system


Hi friends,
Recently I tried Webmin for graphical access of my Linux machine.
It’s a great tool to manage your complete system through web browser.
Installing Webmin is quite simple.
Just uncompress the webmin-x.x.x.tar and run ./setup.sh






















Below is the graphical interface for webmin














I hope you would enjoy GUI management in Linux. (Who said Linux guys are boring and working in black & white screen only?)  J

Friday, March 8, 2013

Backup of Route53 zones using Command Line tool (cli53)

This is my First Blog & hope to publish many more like these in the times to come.....!!!!!

As most of you might be aware about Route53 (one of the key AWS Product)

For those being an alien to the Amazon world here is a short brief on Route 53

Amazon Route 53 is a highly available and scalable Domain Name System (DNS) web service. It is designed to give developers and businesses an extremely reliable and cost effective way to route end users to Internet applications by translating human readable names like www.example.com into the numeric IP addresses like 192.0.2.1 that computers use to connect to each other.
Without wasting any more time I would be directly jumping to the Configuration Part.

# yum -y install python-pip*

pip (Python Package Index) is a tool for installing and managing Python packages.
# yum -y install python-boto

boto: A Python interface to Amazon Web Services

# pip install cli53

cli53 - Command line script to administer the Amazon Route 53 dns service
Create a boto file e.g /root/.boto with following entries.
[Credentials]

aws_access_key_id = Access key for cloud account instance

aws_secret_access_key = Secret key for cloud account instance

[Boto]

debug = 0

num_retries = 10

Here, I have set debug value to 0 (disabled) in case you want enable debugging for boto set debug = 1
num_retries refers the number of times the Python interface will try to connect or access Amazon Web Service (AWS) 

Synchronization of Time is one of the key parameters for the interaction of cli53 to AWS in order to establish a connectivity to AWS account zone


# yum install ntpdate -y

# ntpdate pool.ntp.org

Now we are all set & ready to go......

The cli python script would get created in /usr/bin
To get the list of Hosted Domains on Route53 write command.

# cli53 list                            (
lists all the hosted domains on your AWS account)

For more help on cli53 commands

# cli53 --help                          (shows below mentioned arguments)

    list                list hosted zones
    info                get details of a hosted zone
    export              export dns in bind format
    import              import dns in bind format
    create              create a hosted zone
    delete              delete a hosted zone
    rrcreate            create a resource record
    rrdelete            delete a resource record
    rrpurge             purge all resource records
    rrlist              list all resource records

# cli53 info domain_name            (gives info about the domain)
 
For example, # cli53 info ankush.com 
# cli53 rrlist ankush.com             (list all resource records for ankush.com)


I hope this blog is LIKED by All.......Keep Smiling

 


Renew k8s certificates

Check If certificate expires: amikum@~:03:06:54(⎈ |local-cluster:default):sudo kubeadm certs check-expiration CERTIFICATE                EXP...