Wednesday, May 27, 2015

Creating a VM

[root@blade30 ~]# qemu-img create -f qcow2 /tmp/comviva-spr-centos7.qcow2 10G
Formatting '/tmp/comviva-spr-centos7.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536

[root@blade30 ~]# virt-install --virt-type kvm --name comviva-spr-centos6.4 --ram 1024 --cdrom=/home/iso/CentOS-6.4-x86_64-bin-DVD1.iso --disk /tmp/comviva-spr-centos7.qcow2,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=rhel6

Starting install...
Creating domain...                                                                                                         |    0 B     00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.


<<< snapshots to be placed here >>>>

[root@blade30 ~]# ssh root@192.168.122.207
The authenticity of host '192.168.122.207 (192.168.122.207)' can't be established.
RSA key fingerprint is be:73:31:4e:f0:d4:08:6c:0d:8e:f3:a1:f6:43:0e:7c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.122.207' (RSA) to the list of known hosts.
root@192.168.122.207's password:
Last login: Wed Apr  8 19:16:38 2015
[root@spr ~]#

[root@spr ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.122.1

vi /etc/yum.repos.d/CentOS-Base.repo
[local]
name=CentOS-$releasever - Base
baseurl=http://192.168.122.1/centos6.4
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[root@spr ~]# yum -y install ca-certificates.noarch

[root@spr ~]# yum install -y http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@spr ~]# yum install -y cloud-utils cloud-init parted
[root@spr ~]# vi /etc/cloud/cloud.cfg
......
cloud_init_modules:
 - migrator
 - bootcmd
.....
 - users-groups
 - ssh
 - resolv-conf

[root@spr ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=spr.comviva.com
NOZERCONF=yes

[root@spr ~]# yum install -y openssh-clients sysstat vim
[root@spr ~]# chkconfig mysqld on
[root@spr ~]# poweroff

Broadcast message from root@spr.comviva.com
        (/dev/pts/0) at 19:53 ...

The system is going down for power off NOW!
[root@spr ~]# Connection to 192.168.122.207 closed by remote host.
Connection to 192.168.122.207 closed.

[root@blade30 ~]# cd /tmp
[root@blade30 tmp]# ls -lh *.qcow2
-rw-r--r--. 1 root root 1.2G Apr  8 19:53 comviva-spr-centos7.qcow2

[root@blade30 tmp]# virt-sysprep -d comviva-spr-centos7
libguestfs: error: no libvirt domain called 'comviva-spr-centos7': Domain not found: no domain with matching name 'comviva-spr-centos7'

[root@blade30 tmp]# virt-sysprep -d comviva-spr-centos7
libguestfs: error: no libvirt domain called 'comviva-spr-centos7': Domain not found: no domain with matching name 'comviva-spr-centos7'
[root@blade30 tmp]# virt-sparsify --compress comviva-spr-centos7.qcow2 comviva-vspr-centos7.qcow2
Create overlay file to protect source disk ...
Examine source disk ...
Fill free space in /dev/vda1 with zero ...
Fill free space in /dev/vg_spr/lv_root with zero ...
Copy to destination and make sparse ...

Sparsify operation completed with no errors.  Before deleting the old
disk, carefully check that the target disk boots and works correctly.
[root@blade30 tmp]# ls -lh *.qcow2
-rw-r--r--. 1 root root 1.2G Apr  8 19:53 comviva-spr-centos7.qcow2
-rw-r--r--. 1 root root 307M Apr  8 19:58 comviva-vspr-centos7.qcow2




Tuesday, July 29, 2014

PPT on web using Flexslider

Setting up FlexSlider on your server.
 
Step 1: Download Flexslider from its website.http://www.woothemes.com/flexslider/

Step 2: Extract the flexslider tar file (woothemes-FlexSlider-version-2.2.2-0-gce5441b.zip) on your Linux server. Prefer to keep flexslider under a common path.

$ cd /var/www/html/sen/jquery/
$ unzip woothemes-FlexSlider-version-2.2.2-0-gce5441b.zip

This would a directory name woothemes-FlexSlider-ce5441b

Step 3: Create a directory under which you would host the presentation.

$ mkdir /var/www/html/sen/training

Step 4: Create sub directories

$ mkdir /var/www/html/sen/training/{themes,lib,material}

Step 5: Change to the base directory

$ cd /var/www/html/sen/training

Step 6: Create the file slides.css under themes directory

$ cat > themes/slides.css
* {
  margin: 0;
  padding: 0;
}

html {
  background: #222 ;
}

body {
  _width: 80%;
  color: #888;
  margin: 20px auto 0;
  max-width: 60%;
  text-align: center;
  text-shadow: 0 -2px 1px #000;
  -webkit-font-smoothing: antialiased;
  }

<Ctrl-D>

Step 7: Now we setup the html page view to show the slides. Create a file  slide_container.php under the themes directory. 

$ cat > themes/slide_container.php
<!doctype html>
<html>
<head>
        <link rel="stylesheet" href="flexslider/flexslider.css">
        <link rel="stylesheet" href="themes/slides.css">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script src="flexslider/jquery.flexslider.js"></script>

        <script>
                $(window).load(function(){
                  $('#carousel').flexslider({
                        animation: "slide",
                        controlNav: false,
                        animationLoop: false,
                        slideshow: false,
                        itemWidth: 210,
                        itemMargin: 5,
                        asNavFor: '#slider'
                  });

                  $('#slider').flexslider({
                        animation: "slide",
                        controlNav: false,
                        animationLoop: false,
                        slideshow: false,
                        sync: "#carousel",
                        start: function(slider){
                          $('body').removeClass('loading');
                        }
                  });
                });
        </script>
</head>

<body>
        <div id="slider" class="flexslider">
                <ul class="slides">
                        <?php foreach ($images as $img) { ?>
                                <li><img src="<?php echo $img;?>" /></li>
                        <?php } ?>
                </ul>
        </div>
        <div id="carousel" class="flexslider">
                <ul class="slides">
                        <?php foreach ($images as $img) { ?>
                                <li><img src="<?php echo $img;?>" /></li>
                        <?php } ?>
                </ul>
        </div>
</body>

</html>

<Ctrl-D>
 
Step 8: The PPT slide image files would be placed under the "material" directory. Create the file get_img_files.php under lib directory.


$ cat > lib/get_img_files.php
<?php
$tot_digits=strlen((string) $tot_files);
$file_midix="?";
$pattern=$file_prefix . $file_midix . $file_suffix;

while (--$tot_digits > 0)
{
        $file_midix .= "?";
        $pattern .= "," . $file_prefix . $file_midix . $file_suffix;
}

// eg. $images = glob($thumbsPath.'*.{jpg,jpeg,png,gif}', GLOB_BRACE);
//
$images = glob($path . "/{" . $pattern . "}", GLOB_BRACE);

?>

<Ctrl-D>


Step 9: Create a softlink to the Flexslider directory. This would help easily change to new version of FlexSlider in future.

$ ln -s /var/www/html/sen/jquery/woothemes-FlexSlider-7ecc526/ ./flexslider
Step 10: Create a softlink to themes/slide_container.php. This would help you to try different layout for your page without disturbing your original work. Once a new container is ready you can just change the softlink to point to the new container.php.

$ ln -s themes/slide_container.php ./

With this we finish the setup of FlexSlider. The base directory shall now contain the following files and directories.

$ pwd
/var/www/html/sen/training/


$ ls -l
total 12
lrwxrwxrwx 1 root root   54 Jul 29 11:49 flexslider -> /var/www/html/sen/jquery/woothemes-FlexSlider-7ecc526/
drwxr-xr-x 2 root root 4096 Jul 29 12:07 lib
drwxr-xr-x 2 root root 4096 Jul 29 12:07 material
lrwxrwxrwx 1 root root   26 Jul 29 12:20 slide_container.php -> themes/slide_container.php
drwxr-xr-x 2 root root 4096 Jul 29 11:56 themes
 

The themes directory contain:

$ ls -l themes/*
-rw-r--r-- 1 root root 1736 Jul 29 11:56 themes/slide_container.php
-rw-r--r-- 1 root root  241 Jul 29 11:53 themes/slides.css
 

The lib directory contains:
$ ls -l lib
total 4
-rw-r--r-- 1 root root 206 Jul 29 13:29 get_img_files.php

 
Setting up a PPT slide

Step 1: Open your PPT in MS Power Point and save as JPEG format









 Step 2: Upload the folder created by Power Point to the "material" directory on your server. You may use WinSCP tool to upload the folder. If there are spaces in the folder name then delete or replace them with hypen or underscore character.
$ ls -l material/
total 4
drwxr-xr-x 2 root root 4096 Jul 29 13:37 Networking-01-Introduction

Step 3: Create a PHP script for the newly uploaded presentation slide. Let's name the file as chapter01.php. The content of this file shall be as follows:

<?php
$path="material/Networking-01-Introduction";
$file_prefix="Slide";
$file_suffix=".JPG";
$tot_files=38;

include "lib/get_img_files.php";

include "slide_container.php";

?>

The content marked in yellow needs your input. The $path should match the directory name of your slide, whereas the $tot_files need to match the number of image files present in that directory.
Now your slide is ready to be viewed using a web browser. Open the URL to the php file you created in step 3 above. The below snaps are from the URL http://172.19.1.224/sen/training/chapter01.php




Friday, May 2, 2014

L2TP

L2TP server:
http://linuxexplore.com/how-tos/l2tp-vpn-using-xl2tpd/

L2TP client:
http://www.softether.org/4-docs/2-howto/9.L2TPIPsec_Setup_Guide_for_SoftEther_VPN_Server/4.Windows_L2TP_Client_Setup
https://pandapow.co/how-to/win-l2tp-setup/

Wednesday, March 19, 2014

Authenticate Linux sshd with TACACS+ server

Step 1: Download and install the pam_tacplus module using the source code from git repository
            Go to the URL https://github.com/jeroennijhof/pam_tacplus/
            Click on the "Download ZIP" button and save the file.
            unzip pam_tacplus-master.zip;
            cd pam_tacplus-master;
            autoreconf --install
            autoconf
            automake --add-missing
            make;
            make install

Step 2: Add the following line in /etc/pam.d/sshd
            auth       include      tacacs

Step 3: Create and edit the file "/etc/pam.d/tacacs". Set the server and secret to match your TACACS+ server.
            #%PAM-1.0
            auth       sufficient   /usr/local/lib/security/pam_tacplus.so  debug   server=172.19.1.206 secret=MYKEY
            account    sufficient   /usr/local/lib/security/pam_tacplus.so  debug   server=172.19.1.206  secret=MYKEY    service=shell   protocol=ssh
session    sufficient   /usr/local/lib/security/pam_tacplus.so  debug   server=172.19.1.206 secret=MYKEY    service=shell   protocol=ssh

Step 4: Create a local users. You may set password for local login to fall back if the TACACS server is unavailable.

Reference: http://serverfault.com/questions/425020/authenticate-linux-sshd-with-tacacs-cisco-acs


Tuesday, February 18, 2014

Serial Console setup

/boot/grub/menu.lst

serial --unit=0 --speed=115200
terminal --timeout=5 serial console
title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=364ec31d-8027-4aac-ab2c-5daa9dc854b5 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD  KEYTABLE=us SYSFONT=latarcyrheb-sun16 crashkernel=auto console=ttyS0,115200n8 rd_NO_LVM rd_NO_DM
        initrd /initramfs-2.6.32-358.el6.x86_64.img

/etc/securetty
ttyS0

/etc/init/ttyS0.conf
# ttyS0 - agetty
#
# This service maintains a agetty on ttyS0.

stop on runlevel [S016]
start on runlevel [23]

respawn
exec agetty -h -L -w /dev/ttyS0 115200 vt102
 

Sunday, December 1, 2013

Linux Bridge

file: ifcfg-br0


DEVICE=br0
TYPE=Bridge
IPADDR=10.1.0.58
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
file: ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
HWADDR=00:11:25:6E:E3:43
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
file: ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
ebtables:
ebtables -t broute -A BROUTING -p 8847 -j redirect --redirect-target ACCEPT
ebtables -t broute -A BROUTING -p IPv4 --ip-protocol 6  --ip-destination-port 80 -j redirect --redirect-target ACCEPT
 sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
 

Thursday, December 6, 2012

A PHP script to send custom HTTP response

With the following php script one could request for a response with specific content-type, size and content-disposition.

Copy the below content to /var/www/html/askme.php and access http://server/askme.php?help

<?php


if(isset($_GET['help']))
{
    header("Content-type: text/html");
    echo "<h2>usage: http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"] . "?size=&lt;num>&lt;K|M|G>&type=&lt;content-type>&filename=&lt;name>" ;
    echo "<h2>example: http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"] . "?size=10K&type=image/png" ;
    exit;
}

if(isset($_GET['size'])) $size=$_GET['size']; else $size=0;
if(isset($_GET['type'])) $type=$_GET['type']; else $type="application/octet-stream";

header("Content-type: $type");
if(isset($_GET['filename']))
{
    header('Content-Disposition: attachment; filename="'. $_GET['filename'] .'"');
}

system ("dd if=/dev/zero bs=$size count=1");
?>