Wednesday 12 September 2012

How to run shell commands in python

How to run shell commands in python

Inorder to run your shell commands in python script, you may need to import an module named os. Below is the simple example on how it actually works

import os
os.system('ls -l /boot/')
total 22784
-rw-r--r-- 1 root root 791023 Apr 11 05:56 abi-3.2.0-23-generic
-rw-r--r-- 1 root root 140279 Apr 11 05:56 config-3.2.0-23-generic
drwxr-xr-x 3 root root 12288 Aug 14 18:51 grub
-rw-r--r-- 1 root root 14163334 Aug 14 18:51 initrd.img-3.2.0-23-generic
-rw-r--r-- 1 root root 176764 Nov 27 2011 memtest86+.bin
-rw-r--r-- 1 root root 178944 Nov 27 2011 memtest86+_multiboot.bin
-rw------- 1 root root 2884358 Apr 11 05:56 System.map-3.2.0-23-generic
-rw-r--r-- 1 root root 4965840 Apr 25 21:41 vmlinuz-3.2.0-23-generic

Wednesday 27 June 2012

MySQL performance tuning with MySQLTuner script


MySQL database
     As we all know, MySQL is a powerful opensource database and it is one of the world’s most used Relational Database Management System. In this article, I am going to share you how to increase the performance, stability and efficiency for MySQL server along with any applications that are using it.

MySQL Tuner Script
MySQLTuner is a Perl script that analyzes your MySQL performance and, based on the statistics it gathers, gives recommendations which variables you should adjust in order to increase performance. That way, we can tune your my.cnf file to tease out the last bit of performance from our MySQL server and make it work more efficiently.

SFTP Chroot Jailing - Restricting users to their individual home directories

Secure FTP Chroot jailing 
In this article, I am going to explain you how to enable chroot jailing on sftp which means that sftp users can view and edit only within their home directories only. By default sftp users have shell access to access other users home directories and they also have access under / directories. Let us see how to restrict sftp users within their home directories.



Step 1: Creating chroot directory to secure /home



#mkdir /chroot/home

How to add new order admin email notification on Magento





Magento is a feature-rich eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce storeIn this article explains I am going to explain, how to add a NEW ORDER ADMIN EMAIL NOTIFICATION extension on Magento. Basically, there were two emails that has to be send when a new order is placed by the customer. One going to the customer and one going to the admins. This feature could be especially valuable for those of us that use a fulfillment company. They could get the ‘admin’ version of the new order email that could include all sorts of details and necessary information about the customer that you don’t necessarily want in the new order email that goes to the customer. Thus the magento version 1.7 and below, does not support for receiving admin notification emails when a new order is placed by the customer. But it is necessary to add the extension for receiving admin mail notification.

Postfix mail queue and its operations


Postfix mail queue
In this article, I am going to explain you how flush a postfix mail queue and its operation in details. Suppose if you are handling a MTA(Mail Transfer Agent) then you must have to know about these. Basically postfix consists of four different types of  queues such as


* active queue - it is limited size queue which contains mails to be sent out.
* deferred queue - mails that cannot be delivered will stored in the deferred queue.
* incoming queue - mails from network will first enter in to incoming queue and after some cleanup it will give it to active queue for mail delivery.
* maildrop queue - it consists of locally posted mails.

Saturday 2 June 2012

How to install UCARP

Common Address Redundancy Protocol(CARP)

UCARP allows multiple servers to share common virtual IP addresses in order to provide automatic failover. UCARP is a portable implementation of the CARP protocol.

Set up UCARP Installation on two hosts

Install ucarp on both nodes(nodeA and nodeB) and set one nodeA as master.

apt-get install ucarp

Configure ISCSI initiator and target


Client side iscsi initiator setup:

root@manager-desktop:~# apt-get install open-iscsi

Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libdevel-symdump-perl libipc-run-perl debootstrap libauthen-sasl-perl diffstat libio-stringy-perl patchutils libaio1 seabios
  python-cheetah libio-pty-perl openvpn-blacklist libterm-size-perl kpartx libpkcs11-helper1 vgabios devscripts libtest-pod-perl
  dctrl-tools dput libpod-coverage-perl libapt-pkg-perl lintian libparse-debcontrol-perl wdiff qemu-common

ISCSI - technical details

ISCSI:
The iSCSI protocol is a storage area network (SAN) protocol which allows iSCSI initiators to use storage devices on the (remote) iSCSI target using normal ethernet cabling. To the iSCSI initiator, the remote storage looks like a normal, locally-attached hard drive.


1. What is iSCSI?

It is a network storage protocol above TCP/IP. This protocol encapsulates SCSI data into TCP packets. iSCSI allows us to connect a host to a storage array via a simple Ethernet connection (tape drive). This solution is cheaper than the Fibre Channel SAN (Fibre channel HBAs and switches are expensive). From the host

How ISCSI works

iSCSI is Internet SCSI (Small Computer System Interface), an Internet Protocol (IP)-based storage networking standard for linking data storage facilities, developed by the Internet Engineering Task Force (IETF). By carrying SCSI commands over IP networks, iSCSI is used to facilitate data transfers over intranets and to manage storage over long distances. The iSCSI protocol is among the key technologies expected to help bring about rapid development of the storage area network (SAN) market, by increasing the capabilities and performance of storage data transmission. Because of the ubiquity of IP networks, iSCSI can be used to transmit data over local area networks (LANs), wide area networks (WANs), or the Internet and can enable location-independent data storage and retrieval.

How iSCSI works:

Fiber channel vs ISCSI

FIBER CHANNEL VS ISCSI:

Fiber Channel is not always acceptable and affordable technology because of its high price and complexity. Moreover, highly-qualified professionals are required in order to deploy, set up, and maintain the Fiber Channel SAN. 

Differences between iSCSI and Fiber Channel


Usually Storage Area Networks are presented by Fiber Channel networks. To transfer SAN data at high-speeds up to 10 Gbps and higher, Fiber Channel uses optical fiber cabling. Fiber Channel can operate in different topologies: point-to-point, switched fabric and arbitrated loop.

DRBD configuration steps


DRBD Installation

apt-get install drbd8-utils

To integrate between drbd version and userland version do the following:

apt-get install git-core git-buildpackage fakeroot debconf-utils docbook-xml docbook-xsl dpatch xsltproc autoconf flex

Build the package:

mkdir drbd
cd drbd
git clone http://git.drbd.org/drbd-8.3.git
cd drbd-8.3
git checkout drbd-8.3.10
dpkg-buildpackage -rfakeroot -b -uc
cd ..
dpkg -i drbd8-utils_8.3.10-0_amd64.deb

Nexenastor - A storage management tool

NexentaStor:
************
 NexentaStor is a fully featured NAS/SAN software platform with capabilities that meet and exceed the capabilities of legacy storage systems.
 NexentaStor continues to build on its position as the superior alternative to expensive, vertically integrated, proprietary storage technologies, saving customers 70-80%      over proprietary solutions.
 Running on any industry standard hardware, NexentaStor helps organizations implement high-performance, yet cost-effective data storage solutions with features such as
   * inline deduplication - Inline deduplication is the removal of redundancies from data before or as it is being written to a backup device.

How to install nagios on RHEL 6 / CentOS 6


                                                  How to install nagios on RHEL 6 / CentOS 6  
                        
Nagios is a powerful network monitoring tool in the opensource community. Here I  explained how to install nagios on RHEL 6/CENTOS 6. In addition to that I added how to bind nagios with NRPE plugin.

Step 1: Install the following required packages if not present

# yum install httpd php

# yum install gcc glibc glibc-common

# yum install gd gd-devel

Step 2: Create an account Information

MySQL guide for admins and beginners

MySQL
MySQL is a open source Relational Database Management System. It is very fast reliable and flexible Database Management System. It provides a very high performance and it is multi threaded and multi user Relational Database management system. MySQL is one of the most popular relational database Management System on the web. The MySQL Database has become the world’s most popular open source Database, because it is free and available on almost all the platforms. The MySQL can run on Unix , window, and Mac OS. MySQL is used for the internet applications as it provides good speed and is very secure. MySQL was developed to manage large volumes of data at very high speed to overcome the problems of existing solutions. MySQL can be used for verity of applications but it is mostly used for the web applications on the internet.

Xen commands and their utilities


      # xm list   ------: lists all running virtual machines on a physical node.

      # xm console "instance name / id " : it will connects to the shell of an instance . we can know it's id by "xm list " command.
                                                               To exit from this type " cntrl + 5"


      # xm shutdown "instance name / id " :  shut down an instance peacefully.

      # xm destroy   "instance name / id "  :  to poweroff an instance forcefully.

IPMI (Intelligent Platform Management Interface )

What is IPMI?

IPMI stands for Intelligent Platform Management Interface. It defines a standardized, message-based interface for easily management of a large number of servers. It also defines standardized records for describing platform management devices and their characteristics.

IPMI provides an intelligent means for extensive monitoring, control, and automatic recovery of servers. The standard is applicable across different server topologies and operating systems, so it doesn't matter if you are using Windows, Linux, Solaris, Mac, or a combination of these systems.

Also, because IPMI runs on different properties, it still functions properly, even if the server itself is running abnormally or out of operation for any reason.

Benefits of IPMI
In System

    Provides the foundation for intelligent platform management:
        Autonomous access, monitoring, logging and control features that function independently from the system processors.
    Provides scalable support for entry to high-end systems
    Supports multi-chassis and modular configuration

In Software

    Speeds instrumentation software porting:
        Makes platform management features "self-descriptive"(Plug 'N Play).
        Software automatically configures to platform management hardware
    Isolates management software from hardware changes
    Enables cross-platform software:
        Standardized platform hardware interface enables management software and driver to work on multiple platforms
    Can be used with any management software stack:
    Supports localization

In Hardware

    Preserves ability to innovate hardware
    Provides standardized interface for extending management features:
        IPMB: for intra-chassis extensions and standardized Emergency Management Card Access
    Facilitates "out-of-band" secondary access:
        Message based interface supports bridging to secondary management interfaces - NIC, RS-232, etc.
    Uses "off-the-shelf" components

Courtesy : http://www.aten.com/IPMI.htm

IOZONE - Benchmarking tool configuration

# wget http://www.iozone.org/src/current/iozone3_394.tar

# tar xvf iozone3_394.tar

# cd iozone3_394/src/current

# apt-get update

# apt-get install make

# apt-get install gcc

# apt-get install build-essentials

Configuring httpd on RHEL 6 / Centos 6



[root@client129 httpd-2.4.1]# ./configure --enable-ssl --enable-so
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu

Configuring Apache Portable Runtime library ...

checking for APR... no
configure: error: APR not found.  Please read the documentation.

How to configure openstack

Installing dependencies and the core code
As root on guest (you’ll have to log in as you, then sudo su -):

apt-get install python-software-properties
add-apt-repository ppa:swift-core/release
apt-get update
apt-get install curl gcc git-core memcached python-configobj python-coverage python-dev python-nose python-setuptools python-simplejson python-xattr sqlite3 xfsprogs python-webob python-eventlet python-greenlet python-pastedeploy python-netifaces
Install anything else you want, like screen, ssh, vim, etc.
On Fedora, log in as root and do:

Openstack swift

Openstack:
     OpenStack is a collection of open source software projects that enterprises/service providers can use to setup and run their cloud compute and storage infrastructure.
Rackspace and NASA are the key initial contributors to the stack. Rackspace contributed their "Cloud Files" platform (code) to power the Object Storage part of the OpenStack,
while NASA contributed their "Nebula" platform (code) to power the Compute part. OpenStack consortium has managed to have more than 150 members including Canonical,
Dell, Citrix etc.