Bash Script - Whitelist an account in Mod Security

The following script disable Mod Security for an account.


#!/bin/bash
mkdir -p /usr/local/apache/conf/userdata/std/2/$1/$2

echo -e " \nSecRuleEngine Off \n" > /usr/local/apache/conf/userdata/std/2/$1/$2/mod_security2.conf

/scripts/ensure_vhost_includes --user=$1

echo "Mod security disable for the account:$1 successfully"



Note:- Copy the above commands in a .sh file. Here let it be mod_sec.sh then,

# chmod 755 mod_sec.sh
    -To give execute permission to the script.
# ./mod_sec.sh <user_name>  <domain_name>
    -Execute the command as shown above.

How to change main domain name of KLOXO?



There is no direct option to change main domain in KLOXO.

But you can change main domain, if you can add more than one domain (not parked domain) in a user account. ie,the quota limit of domain in the user account must be more than one.

Let, you have to change your main domain from 'maindomain.com' to 'newmaindomain.com'

1.Login to the user account, then select
   >>Home>>Resources>>Add Domain 

2. Add the domain 'newmaindomain.com'
    You can't add a new domain if the domain quota of the user is 1.

3.Goto,
   >>Home>Resources>> Default Domain
    You can change your default domain from maindomain.com to newmaindomain.com

4.Now you have to login to backend of the server and copy all the contents of  maindomain.com directory to newmaindomain.com directory. Don't forget to check the domain's document root before copying files. If the document root is pointing to the same directory, no need to copy the files.

OpenVZ - Change Disk Quota

To check if your VE ran out of its disk quota, use the following commands (inside a VPS).

# df
   -To show disk space usage

# df -i
   -To show the inodes usage

If one of the commands give you usage of 100%, that means you hit one of the disk quota limit. You can increase the limit from the host system (Hardware Node) only.

To change the current Disk Quota,

1.Login to Hardware Node,

# vzquota stat <VPSID>
   -To  get the current values for disk quota. The result will be as shown in the figure.


2. To increase the disk space quota, use vzctl set --diskspace

# vzctl set <VPSID> --diskspace  $(( 1048576*3 )):$(( 1153434*3 )) --save
   -To increase quota by a factor 3

3. To increase the disk inodes quota, use vzctl set --diskinodes.


# vzctl set <VPSID> --diskinodes $(( 200000*4 )):$(( 220000*4 )) --save 
   -To increase quota by a factor 4

# vzctl exec <VPSID> df -i
   -To check whether the changes affected or not.

OpenVZ- UBC Parameters

UBC Parameters:

                     UBC, or User BeanCounters is a set of limits and guarantees controlled per Virtual Environment. UBC is the major component of OpenVZ resource management.


 The figure shows the UBC parameters of a VPS.
Enter in to VPS and run the following command.

# cat /proc/user_beancounters
   -To show the UBC parameters of a VPS.

                   You can see if you hit the limits for some UBC parameters by analyzing the last column (named failcnt). It shows a number of fails for this counter, i.e. a number of times a parameter hit the limit. Usually what you need to do is to increase the parameter. But you need to do it carefully.


If you want to increase kmemsize,

1. Get the current values for the parameter's barrier and limit
    Let, kmemsize barrier is 'x', and its limit is 'y'.

2. Increase the values. Say, we want to increase kmemsize by 2 times.

   # vzctl set <VPSID> --kmemsize $((x*2)):$((y*2)) --save 
    The above command doubled the parameter using bash arithmetic.

By using --save flag, we denote we want to both apply the new settings to the running VE, and save them in the configuration file (from which they will be taken during next VE start).

3. Check the new configuration.

# vzcfgvalidate /etc/vz/conf/<VPSID>.conf 


Note:-You can change the other parameters as like 'kmemsize'.
 

How to remove IP block?

IP Block can be of 2 kinds..,temporary block and permanent block.

# cat /etc/csf/csf.deny | grep <IP>

# iptables -nL | grep <IP>

If the IP is blocked in server, the above commands will list the IP block rules of that particular IP.


**If the block is temporary, do the following to remove block.

# csf -tr <IP>

**If the block is permanent, do the following to remove block.

 # csf -dr <IP>


Note1:- If the command csf is not working, you have to search for the command using whereis command.
# whereis csf
The above command will list the csf executable file.
eg:-
# /usr/sbin/csf -dr <IP>

Note2:- You can check the reason of IP block in /var/log/lfd.log. Use the following command
# cat /var/log/lfd.log | grep <IP>



cPanel - install Softaculous


1. Login to the server WHM as root user.

2. First check if ioncube loader is installed, if not, install it.

Sometime it is not enabled, so enable the ioncube loader from WHM.
 Main >> Server Configuration >> Tweak setting  >> php --> mark the ioncube.

3. Login to server via SSH.



cd /usr/local/src
wget -N http://files.softaculous.com/install.sh
chmod 755 install.sh
./install.sh

4. Restart cpanel (/etc/init.d/cpanel restart).

5. Now go to : WHM >> Plugins >> Softaculous - Instant Installs
Reference:-
http://www.softaculous.com/docs/Installing_Softaculous_in_cPanel

OpenVZ - Frequently used Commands

# vzctl start <VPSID>

   -To start a vps

# vzctl stop <VPSID>

   -To stop a vps

# vzctl restart <VPSID>

   -To restart a vps

# vzctl status <VPSID>

  -To check the status of vps

vzctl destroy <VPSID>

   -To To Delete a VPS. All the data will be deleted, no confirmation, so be careful when using this command.

# vzlist -a

   -To list all vps in the Hardware Node

# vzlist

  -To list running vps in the Hardware Node

vzcalc -v <VPSID>

    -To calculate the vps resources usage.

vzctl exec <VPSID> <Command>

    -To execute a command inside the container. Command can be df, ls etc.

# vzctl enter <VPSID>

    -To enter into vps

vzyum <VPSID> install package_name

    -To install any package/Software on a VPS from Node

vzctl set <VPSID>  --hostname  vps.domain.com  --save

    -To set the Hostname of a VPS

vzctl set  <VPSID>  --ipadd 1.2.3.4 --save

    -To add a new IP to the VPS

vzctl set  <VPSID> --ipdel  1.2.3.4  --save

    -To delete the IP from VPS

vzctl set  <VPSID>  --userpasswd  root:new_password  --save

    -To reset root password of a VPS

vzctl set  <VPSID>  --nameserver 1.2.3.4  --save

    -To add the nameserver IP's to the VPS

vzcpucheck -v

    -To check current CPU usage/vps. It'll list all vps.

cPanel - Migrate a domain from one server to another

Backend

1. Login to the source server using ssh
2. cat /etc/userdomains | grep <domain-name>
   -To display the acccount name curresponding to the domain
3. run /scripts/pkgacct <accountname>
   -To create backup. Backup file cpmove-<account-name>.tar.gz will create in /home directory.

4. Login to the destination server using ssh
5. cd /home
6. copy the cpmove-<account-name>.tar.gz from the source server to destination server using scp.
7. run /scripts/restorepkg <account-name>

Get the name server of the destination server,
 Main >> Server Configuration >> Basic cPanel & WHM Setup
You can find the name server in the above option.

Inform the domain's owner to update his name server given to registrar with the new one.

OpenVZ- Create a Container

To create a container, you have to
-Choose the container ID
-Choose the OS template to use for the Container

Choose a container id greater than 100. CTID 0-100 are reserver.

# vzlist -a
    -To list all the containers in the Hardware Node. You can choose a ID other than in the list.

# ls /vz/template/cache/
   centos-5-x86_64.tar.gz
   fedora-7-x86_64.tar.gz
   suse-10.3-x86_64.tar.gz
  
   -To list all the OS templates in the Hardware Node.

               After the Container ID and the installed OS template have been chosen, you can create the Container private area with the vzctl create command. The private area is the directory containing the actual files of the given Container; it is usually residing in /vz/private/CTID/. The private area is mounted to the /vz/root/CTID directory on the Hardware Node and provides Container users with a complete Linux file system tree.

              The vzctl create command requires only the Container ID and the name of the OS template as arguments; however, in order to avoid setting all the Container resource control parameters after creating the private area, you can specify a sample configuration to be used for your new Container. The sample configuration files are residing in the /etc/vz/conf directory and have names with the following mask: ve-configname.conf-sample. The most commonly used sample is the ve-basic.conf-sample file; this sample file has resource control parameters suitable for most Containers.


# vzctl create <CTID>  --ostemplate centos-5-x86 -–config basic

            If you specify neither an OS template nor a sample configuration, vzctl will try to take the corresponding values from the global OpenVZ configuration file (/etc/vz/vz.conf).

Now the VPS is created. We can now configure the VPS with the start-up and network parameters.

OpenVZ- Concept of Container, Hardware Node and CT0

Container:-

    A container (otherwise known as CT, Virtual Environment (VE), Virtual Private Server (VPS) etc.) is one of the main concepts of OpenVZ.
    Container is an isolated entity which performs and executes exactly like a stand-alone server. Container can be rebooted independently and have root access, users/groups, IP address(es), memory, processes, files, applications, system libraries and configuration files.

    OpenVZ allows to have multiple CTs on a single Hardware Node. Every container has a ConTainer's IDentifer (CTID) which is used to manage the container.
     The OpenVZ software reserves the IDs ranging from 0 to 100. Though OpenVZ uses only ID 0, future versions might use additional Container IDs for internal needs. Do not create Containers with IDs below 101.

Hardware Node:-

    Hardware Node (otherwise known as host system) is a term used in OpenVZ. Basically it means the physical server on which OpenVZ is installed and running. Sometimes Hardware Node is abbreviated as HW or HN.

CT0:-

    In OpenVZ, you have multiple CTs, as well as the host system  itself, which is otherwise known as CT0 or VE0. In other words, CT0 means the server itself. From CT0, we can use vzctl and other tools to manage containers. From CT0, all the containers' processes, files, etc. are accessible. From CT0, we manage the hardware, install a new kernel, etc.
CT0 - Container Zero
Container ID Zero is given to the Hardware Node itself.

Bash Script - Convert / Change string from Lower Case to Upper Case

Copy any of the following code in a .sh file and Execute the script.


1.echo $1 | awk '{print toupper($1)}'

2.echo $1 | tr "[:lower:]" "[:upper:]"

3.echo $1 | sed y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/

4.echo $1 | tr '[a-z]' '[A-Z]'

5.echo "${1^^}"



Let the code in test.sh

#./test.sh testing
TESTING

o/p as shown....

Note:-It's easy to change the above codes to change Uppercase to Lowercase. Just test it...

cPanel - Error in adding Addon Domains



If you are facing the following problem in adding addon Domain in cPanel

Error:

Using nameservers with the following IPs: XXX.XXX.XXX.XXX , YYY.YYY.YYY.YYY Sorry, the domain is already pointed to an IP address that does not appear to use DNS servers associated with this server. Please transfer the domain to this servers nameservers or have your administrator add one of its nameservers to /etc/ips.remotedns and make the proper A entries on that remote nameserver

Solution:

Login to WHM then,

Add the IPs  XXX.XXX.XXX.XXX , YYY.YYY.YYY.YYY  in

 "WHM >> IP Functions >> Configure Remote Service IPs>>Remote Name Server IPs"

What is OpenVZ?

OpenVZ
     
     OpenVZ (Open VirtualiZation) is an operating system-level virtualization technology based on the Linux kernel and operating system. OpenVZ allows a physical server to run multiple isolated operating system instances, known as containers, Virtual Private Servers (VPSs).OpenVZ is limited in that it requires both the host and guest OS to be Linux.

    OpenVZ is a virtualisation technology that was developed by Parallels, and is the basis for their Virtuozzo platform. OpenVZ consists of the open sourced parts of Virtuozzo.

    OpenVZ works somewhat like Solaris Zones or FreeBSD jails, in the aspect that it utilizes a single operating system kernel and creates various user-environments within the single operating system space. The various user-environments are called Virtual Environments, of VE.

    Users in a VE will have their own view on the available resources in the system. They are only able to see and interact with processes running in the same VE, they only have access to files and diskspace assigned to the VE and can only see network-traffic destined to the IP address assigned to the VE.

Advantages
    Due to the fact that OpenVZ uses a single operating system kernel to provide various Virtual Environments the overhead of OpenVZ is very low. No memory is wasted by loading copies of the kernel for every VE, no translation is needed for I/O going to the storage or network.This allows for very lightweight VE’s, with some environments taking less then 8MB of memory and only a few megabytes of diskspace.

    Another advantage of OpenVZ is that it doesn’t require any hardware-assisted virtualisation on the system and it doesn’t need to ‘emulate’ any cpu or I/O instructions, which would put a large strain on the resources.
     Your files and processes are visible on the host-system, but hidden from other users of the system. Only the root-user on the host can access your resources. This access is also used to make backups of all your files, so System Administers can help you with a restore in case you accidentally erase some files.

     It is possible to mount iso images and use sshfs systems using fuse, but kernel-mode mounting is not available.

DisAdvantages
    A disadvantage of the OpenVZ VE’s is that only Linux environments are possible, since the kernel is shared between all environments it’s not possible for a VE to make modifications to the kernel. It’s also not allowed for the VE’s to change their IP-configuration, to act as NFS servers or to mount filesystems, as this would have an impact on the host’s security system.

Note:- You can refer the following links to know more about OpenVZ
http://sudosu.in/search?q=openvz#!/2012/07/openvz-concept-of-container-hardware.html
http://sudosu.in/search?q=openvz#!/2012/07/openvz-create-container.html
http://sudosu.in/search?q=openvz#!/2012/07/openvz-frequently-used-commands.html
http://sudosu.in/search?q=openvz#!/2012/07/openvz-ubc.html
http://sudosu.in/search?q=openvz#!/2012/07/openvz-change-disk-quota.html

How to Backup an account in cPanel???

Backup of a particular account/domain through front end:

1. Enter cpanel with the login user name and password of the account

2. Select the Backups

3. Click the option "Download & generate backup of full website"

Backup through back end:

1. Enter the Remote server using the command ssh

2.cat /etc/userdomains | grep <domain-name>
   -To display the acccount name curresponding to the domain

 3.run /scripts/pkgacct <accountname>
   -To create backup. Backup file cpmove-<account-name>.tar.gz will create in /home directory.



**Note- All the cPanel Scripts are in  /scripts  directory of that server.
             # /scripts/restorepkg <accountname>
                -To restore account,if the backup of the corresponding user is present in /home

PHP: Relocation error



Error

***All Wordpress pages are seems to be dislocated.

# cat /usr/local/apache/logs/error_logs  showing the following error.

php: symbol zlibVersion , version libmysqlclient_16 not defined in in file libmysqlclient.so.16 with link time reference. Instead php: relocation error: php: symbol zlibVersion the error could be php: relocation error: php: symbol crc32.


# php index.php
 
php: relocation error: php: symbol deflateInit2_, version libmysqlclient_16 not defined in file libmysqlclient.so.16 with link time reference

This is an example and the issue could happen with any shared library not only with libmysqlclient.so .               

                                  As per the error message the library version is not matching so we have to check the shared library dependencies. This can be done with tool called ‘ldd’ which prints the shared library dependencies. In this case we will check PHP for “libmysqlclient” so the command should be like this:


# ldd /usr/bin/php | grep libmysqlclient

 The output should be similar to this one:

 libmysqlclient.so.16 =&gt; /usr/lib64/mysql/libmysqlclient.so.16 (0x00000034c6000000)


Let’s check the file:  


# ls -la /usr/lib64/mysql/libmysqlclient.so.16

 In my case this is a symbolic link to the library in the same folder:

 lrwxrwxrwx 1 root root 28 Sep 29 17:09 /usr/lib64/mysql/libmysqlclient.so.16 -> libmysqlclient.so.16.0.0*

 Now let’s check if this file exist in another place.

 # locate libmysqlclient.so.16.0.0

My output is as follows:

/usr/lib64/libmysqlclient.so.16.0.0
/usr/lib64/mysql/libmysqlclient.so.16.0.0

So there are two libraries, and now we have to check where is the missing symbol – for example zlibVersion. For that will use ‘nm’ command lists symbols from object files. Let’s try the current linked file:
   
# nm /usr/lib64/mysql/libmysqlclient.so.16.0.0 | grep zlibVersion

The output is:

 nm: libmysqlclient.so.16.0.0: no symbols

So it seams there are no symbols in this library.
With the other file:  

# nm /usr/lib64/libmysqlclient.so.16.0.0 | grep zlibVersion

The output is:

 00000034c60d64b0 T zlibVersion

Which seams better.

Now I will just remote the current link: 

# rm -f /usr/lib64/mysql/libmysqlclient.so.16


And will create a new one with the library that contains the symbol: 

# ln -s /usr/lib64/libmysqlclient.so.16.0.0 /usr/lib64/mysql/libmysqlclient.so.16



This should resolve the case, and the php: symbol zlibVersion , version libmysqlclient_16 not defined in in file libmysqlclient.so.16 with link time reference error was solved.

Important files of CSF

csf.conf    - the main configuration file, it has helpful comments explaining
          what each option does
csf.allow    - a list of IP's and CIDR addresses that should always be allowed
          through the firewall
csf.deny    - a list of IP's and CIDR addresses that should never be allowed
          through the firewall
csf.ignore    - a list of IP's and CIDR addresses that lfd should ignore and not
          not block if detected
csf.*ignore    - various ignore files that list files, users, IP's that lfd
          should ignore. See each file for their specific purpose and
         tax


'csf' commands are actually operating on these files...

cPanel - How to reset cPanel account password???

1. Login to WHM. http://<server ip address>:2086/
   username: root
   password: <root password of the server>

2. Home >> Account Information >> List Accounts

3. Click on “+” sign near the domain for which you want to change the cPanel   password. You can see an option there to change the password.


or

Login to cPanel

 Main >> Account Functions >> Password Modification

you can select the account to modify the password

What is LFD?




Short for Login Failure Daemon, LFD is a process that is part of the ConfigServer Security & Firewall (CSF) that periodically checks for potential threats to a server such as brute-force login attempts and if found blocks the IP address attempting to attack that server.

The log file of lfd is /var/log/lfd.log
You can grep the ip address from the lfd.log file and can easily understand that whether the block is permanent or temporary.

# csf -dr < ip>    Unblock an IP and remove from /etc/csf.deny
# csf -tr <ip>    Remove an IPs from the temp IP ban and allow list


Once the IP address removed one need to restart the Firewall…
To Restart Firewall one need to execute below mentioned command:

# csf -r
 

How to switch to a different PHP version?

create a new file (or edit the existing one) called .htaccess and add the following line:

To switch to PHP 4.4:
AddHandler application/x-httpd-php4 .php .php4 .php3

To switch to PHP 5.0:
AddHandler application/x-httpd-php5 .php .php5 .php4 .php3

To switch to PHP 5.1:
AddHandler application/x-httpd-php51 .php .php5 .php4 .php3

To switch to PHP 5.2:
AddHandler application/x-httpd-php52 .php .php5 .php4 .php3

To switch to PHP 5.3:
AddHandler application/x-httpd-php53 .php .php5 .php4 .php3

Awk substr function


Let's look at the substr function of awk.
This function has the form substr(s, a, b) and returns b number of chars from string s, starting at position a.  The parameter b is optional.

Example- Let you have a file 'test' with the following test in it.

ABCDE FGHIJK LMNOPQ RST UVWX

awk '{print substr($1,1,1)}' test
awk '{print substr($1,3)}' test
awk '{print substr($3,3)}' test
awk '{print substr($4,3)}' test
awk '{print substr($0,5,2)}' test


Run these commands and understand how this works....

'sed' command samples

Let you have the following lines in a file 'test'

<element name="select">
<choice>
<value type="token">A</value>
<value type="token">B</value>
<value type="token">C</value>
</choice>
</element>
 
 
***Note- If you want to modify those patterns in the file containing the patterns itself use -i as argument with 'sed' command. 
 
#sed 's/token/PATTERN/' test
will replace all 'token' in the file with  'PATTERN'
Just check it out....
 
 
#sed '/token/d' test
will delete all lines which contain the 'token'
Just check it out...
 
 
#sed 's/token//' test
will remove all 'token' from the file. It just remove those pattern not the lines containing pattern.
 
 
#sed '3 a\HAI ' test
 will add 'HAI' in the 3rd line. We can give line number and the new line content as you wish...
Just replace 3 with new line number and 'HAI' with new line content....

Bash Script-Pattern Printing Scripts

If you give the following pattern in a file  'test'

A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y 
 
Pattern 1:
A B C D E
F G H I
K L M
P Q
U
code
file=$1
awk 'BEGIN { a=0;}
{for(i=1;i<=NF-a;i++){printf("%s ",$i);if(i==NF-a)printf("\n")}a+=1;}
END {print "Check the pattern"}' $file
copy the above code in file pattern1.sh  then,
 
# chmod 755 pattern2.sh
# ./pattern1.sh test 
 
 
Pattern 2:
 A
  G
    M
      S
        Y
 
 code
file=$1
awk 'BEGIN { c=1;}
{ for (i=1; i<=c; i++) printf(" "); printf("%c\n",$c); c++; }
END {print "Check the pattern"}' $file
copy the above code in file pattern2.sh  then,
 
# chmod 755 pattern2.sh
# ./pattern1.sh test 
 
 
Pattern 3: 
          E
I
M
Q
U
code
file=$1
awk 'BEGIN { a=0;}
{for(i=1;i<=NF-a;i++){printf("  ");if(i==NF-a)printf("%c\n",$i)}a+=1;}
END {print "Check the pattern"}' $file

copy the above code in file pattern1.sh  then,
 
# chmod 755 pattern3.sh
# ./pattern3.sh test 
 
                      or
 
file=$1
awk 'BEGIN { a=0;}
{for(i=NF;i>=1+a;i--) printf(" "); print substr($(NF-a),1,1); a++;}
END {print "Check the pattern"}' $file
 

copy the above code in file pattern1.sh then,

# chmod 755 pattern3.sh

# ./pattern3.sh test
 
 
 
 

Bash Script-Print the arguments in Reverse order

bash$ ./reverse a b c d
d
c
b
a
bash$


x=$*                #To set all the arguments in a variable 'x'
c=$#            #To set the total number of arguments in variable 'c'

while [ 1 -le $c ]
do
c=`expr $c - 1`     #To decrement the variable 'c' by 1
shift $c        #To shift the total arguments by count 'c'
echo $1           
set $x            #To reset the arguments by the previous arguments
done

Install PHPMyAdmin to administer MySQL database server

phpMyAdmin


# cd
# lynx http://www.phpmyadmin.net/home_page/downloads.php
-Download phpMyAdmin-3.5.1-all-languages.tar.gz from the above mirror.
# gunzip phpMyAdmin-3.5.1-all-languages.tar.gz
# tar -xvf phpMyAdmin-3.5.1-all-languages.tar
-Extract to the home directory



# cp phpMyAdmin-3.5.1-all-languages /usr/local/apache2/htdocs/arun/phpmyadmin
# elinks 192.168.1.193/phpmyadmin/index.php
-To check whether the phpMyAdmin is working.

Configure-BIND DNS server

 
                               DNS


Introduction on BIND
BINDor named is the most widely used DNS software on the Internet. The name originates as an acronym from Berkeley Internet Name Domain. The Internet Domain Name System (DNS) consists of the syntax to specify the names of entities in the Internet in a hierarchical manner, the rules used for delegating authority over names, and the system implementation that actually maps names to Internet addresses. DNS data is maintained in a group of distributed hierarchical databases.
It stores information for mapping Internet host names to IP addresses and vice versa, mail routing information, and other data used by Internet applications.

Installation and Configuration of BIND
#cd
# unzip bind-9.3.2.tar.gz
# tar -xvf bind-9.3.2.tar
-To Download and extract

# cd bind-9.3.2/
# ./configure --prefix=/usr/local --disable-ipv6
# make && make install
-To configure and install BIND

# mkdir -p /chroot/named
# groupadd named
# useradd -g named -d /chroot/named -s /bin/true named
# passwd -l named
-To create a user 'named' with home directory '/chroot/named'

# cd /chroot/named
# mkdir dev etc logs conf
# mkdir -p var/run
# mknod dev/null c 1 3
# mknod dev/zero c 1 5
# mknod dev/random c 1 8
# cp /etc/localtime etc
-To create directories and device files for the working of bind.

# ln -s /chroot/named/etc/named.conf /etc/named.conf
-To create the named.conf file which the main configuration file of BIND

Add the following contents in the /etc/named.conf file

options {
directory "/conf";
pid-file "/var/run/named.pid";
statistics-file "/var/run/named.stats";
dump-file "/var/run/named.db";
recursion yes;
version "Just bad luck";
};

# onedomain.com
zone "onedomain.com" in {
type master;
file "onedomain.for";
notify no;
};

#twodomain.com
zone "twodomain.com" in {
type master;
file "twodomain.for";
notify no;
};


Create a file 'onedomain.for' in '/chroot/named/conf' with the following contents in it. It is the zone file for onedomain.com

;onedomain.for
;
$TTL 86400

@ IN SOA ns.onedomain.com. mail.onedomain.com (
450 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum

@ IN NS ns.onedomain.com.
ns IN A 192.168.1.193
@ IN A 192.168.1.193
www IN CNAME onedomain.com.

Create a file 'twodomain.for' in '/chroot/named/conf' with the following contents in it. It is the zone file for twodomain.com

;twodomain.for
;
$TTL 86400

@ IN SOA ns.twodomain.com. mail.twodomain.com (
451 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum

@ IN NS ns.twodomain.com
ns IN A 192.168.1.194
@ IN A 192.168.1.194
www IN CNAME twodomain.com.


# chown named:named /chroot/named
# chown -R named:named /chroot/named/var
# chmod 700 /chroot/named


# named-checkzone onedomain.for /chroot/named/conf/onedomain.for
zone onedomain.for/IN: loaded serial 450
OK
# named-checkzone twodomain.for /chroot/named/conf/twodomain.for
zone twodomain.for/IN: loaded serial 451
OK



# named-checkconf /etc/named.conf
-To check the configuration file
# /usr/local/sbin/named -t /chroot/named -u named -c /etc/named.conf
-To start named service.

# ps -fCnamed
UID PID PPID C STIME TTY TIME CMD
named 17611 1 0 11:34 ? 00:00:00 /usr/local/sbin/named -t /chroot/named -u named -c /etc/named.conf
-To check whether the named service is started or not.



# nslookup www.onedomain.com
Server: 127.0.0.1
Address: 127.0.0.1#53

www.onedomain.com canonical name = onedomain.com.
Name: onedomain.com
Address: 192.168.1.193


# nslookup www.twodomain.com
Server: 127.0.0.1
Address: 127.0.0.1#53

www.twodomain.com canonical name = twodomain.com.
Name: twodomain.com
Address: 192.168.1.194

# dig +short @192.168.1.193 -c CH -t txt version.bind
"Just bad luck"




A shell script that receives even number of filenames as its arguments and copies the contents of the files at the odd-numbered positions to the files at the immedietly following even number postions .

This script will give you a brief idea on 'set' and 'shift' command... If you have any doubt on the working,you can use echo command to print the instance values. It will help you to debug problems when you write new scripts....





x=$*              #To set all the arguments in a variable 'x'
c=$#        #To set the total number of arguments in variable 'c'

rem=$(( $c % 2 ))

if [ $rem -ne 0 ]
then
    echo Error...!!!
    echo Please give even number of arguments..
    exit
fi


while [ 1 -le $c ]
do
c=`expr $c - 2`     #To decrement the variable 'c' by 1
shift $c        #To shift the total arguments by count 'c'    
cat $1 >>$2 
set $x            #To reset the arguments by the previous arguments
done


Script to check the diskusage of the server and send email to root@hostname when the usage exceeded 95%

                  Save the following code in a file and execute. I hope this script will give you an idea on some tricks with the 'grep' , 'cut' and 'awk'.
Just know that  We'll use only on the print function of awk.





hname=$HOSTNAME
ADMIN="root@$hname"
# set alert level 90% is default
ALERT=95
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
used=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
    if [ $used -ge $ALERT ]; then
         echo "Running out of space \"$partition ($used%)\" on $hname as on $date" |
         mail -s "Alert: Almost out of disk space $used" $ADMIN;
    fi
done




Complile and install Mysql server from source



Complile and install MYSQL


Preliminary installations

[root@vps ~]# yum -y install ncurses-devel


Complile and install Mysql

[root@vps ~]# groupadd mysql
[root@vps ~]# useradd -r -g mysql mysql
[root@vps ~]# cd /usr/local/src/
[root@vps src]# wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.0-m2.tar.gz
[root@vps src]# tar -xzf mysql-5.5.0-m2.tar.gz
[root@vps src]# cd mysql-5.5.0-m2

[root@vps mysql-5.5.0-m2]# ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --disable-maintainer-mode --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --without-comment --without-debug --without-bench

[root@vps mysql-5.5.0-m2]# make && make install

[root@vps mysql-5.5.0-m2]# ./scripts/mysql_install_db

[root@vps mysql-5.5.0-m2]# chown -R root:mysql /usr/local/mysql
[root@vps mysql-5.5.0-m2]# chown -R mysql:mysql /usr/local/mysql/data
  -To set the proper ownership for the MySQL directories and data files, so that only   MySQL (and root) can do anything with them.



***Default options are read from the following files in the given order:
/etc/my.cnf  /etc/mysql/my.cnf  /usr/local/mysql/etc/my.cnf  ~/.my.cnf


[root@vps mysql-5.5.0-m2]# cp support-files/my-medium.cnf /etc/my.cnf
[root@vps mysql-5.5.0-m2]# chown root:sys /etc/my.cnf
[root@vps mysql-5.5.0-m2]# chmod 644 /etc/my.cnf


[root@vps ~]# cd /usr/local/mysql/bin
[root@vps ~]# for file in *; do ln -s /usr/local/mysql/bin/$file /usr/bin/$file; done
  -To set up symlinks for all the MySQL binaries, so they can be run from anyplace without having to include/specify long paths.


Create Startup service for mysql


[root@vps ~]# echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
***Do not issue the above command more than once.

[root@vps ~]# ldconfig
[root@vps ~]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
[root@vps ~]# chmod +x /etc/rc.d/init.d/mysql
[root@vps ~]# chkconfig mysql on

You can now start/stop mysql using the following commands.

[root@vps ~]# /etc/rc.d/init.d/mysql start
[root@vps ~]# /etc/rc.d/init.d/mysql stop


***If you are encounter any problems in start and stop mysql, you can find the reason from the error log of mysql. Error log name is in the <hostname>.err format.
Here my server hostname is vps.arun.com and therefore the error log name og mysql is vps.arun.com.err . You can use find the error log in the var directory of mysql installation. Here in my case it is /usr/local/mysql/var/vps.arun.com.err.


You can set new mysql root password using the followiing command.
[root@vps ~]# mysqladmin -u root password <newpassword>



Notes:-

Error:
Configure: error: No curses termcap library found
Fix:
[root@vps mysql]# yum install ncurses-devel -y


Error:
Error in /usr/local/mysql/var/vps.arun.com.err
/usr/local/mysql/libexec/mysqld: File './mysql-bin.index' not found (Errcode: 13)
fix:
Change the ownership of var directory in mysql's installation directory, as like follows.
chown -R mysql:mysql /usr/local/mysql/var



That's it...