Archive for October, 2013

RAID Configuration in RHEL/CentOS 6

Posted: October 11, 2013 in RAID
Tags: , ,

RAID, stands for Redundant Array of Inexpensive Disks. RAID is a method by which same data or information is spread across several disks, using techniques such as disk striping (RAID Level 0),disk mirroring (RAID Level 1), and disk striping with parity (RAID Level 5) to achieve redundancy, lower latency, increased bandwidth, and maximized ability to recover from hard disk crashes. In this example we are using Softwar RAID

Software RAID configuration in RHEL/CentOS

Software RAID is implemented under OS Kernel level. The Linux kernel contains an MD driver that allows the RAID solution to be completely hardware independent. The performance of a software-based array depends on the server CPU performance and load.

Features:
1. the ability to increase availability and reliability of data

Tasks:
1. create a RAID-1 Device (/dev/md0)
a.
 fdisk /dev/sdb – to create usable raw partitions
b.
 n – for new partition
c.
 p – primary or you can use e for extended
d.
 +10G – size of the partition
e.
 t – change to type ‘fd’ (RAID AUTO)
c.
 partprobe /dev/sdb – to force a kernel update of the partition layout of the disk: /dev/sdb
Note: Repeat the Steps for all other members of the Array i.e. /dev/sdb6
  d. mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sdb5 /dev/sdb6
  e. cat /proc/mdstat – lists active RAID (md) information (or)
     you can enter watch command. Ex- watch cat /proc/mdstat
  f. mkfs.ext4  /dev/md0 – overlays a file system on the RAID device
  g. Create a directory to mount. Ex- mkdir /raid1
  g. mount /dev/md0 /raid1
  h. update: vim /etc/fstab
          /dev/md0          /raid1          ext4     defaults 1 1

Reboot the machine and confirm that file system get mounted or not. We can use “mount” command to list all mounted file system

Note: use ‘mdadm –query /dev/md0’ to get information about a RAID device

Nagios CoreServer Installations

Posted: October 10, 2013 in Nagios
Tags: ,
Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes. Nagios was designed as a rock solid framework for monitoring, scheduling and alerting.
Prerequisites

 
During portions of the installation you’ll need to have root access to your machine. Make sure you’ve installed the following packages on your Centos/RHEL installation before continuing.
  • Apache
  • PHP
  • GCC compiler
  • GD development libraries
  • OpenSSL
  • OpenSSL-devel
You can use yum to install these packages by running the following commands (as root):
[root@myserver ~]# Yum install httpd php -y
[root@myserver ~]# Yum install gcc glibc glibc-common -y
[root@myserver ~]# Yum install gd gd-devel -y
[root@myserver ~]# Yum install OpenSSL OpenSSL-devel -y
  
  1. Create Account Information
 
Create a new nagios user account and give it a password.
 
[root@myserver ~]# useradd nagios
[root@myserver ~]# passwd nagios
 
Create a new nagcmd group for allowing external commands to be submitted through the web interface.
Add both the nagios user and the apache user to the group.
 
[root@myserver ~]# groupadd nagcmd
[root@myserver ~]# usermod -a -G nagcmd nagios
[root@myserver ~]# usermod -a -G nagcmd apache
  
  1.   Download Nagios and the Plugins
 
Create a directory for storing the downloads.
 
[root@myserver ~]# mkdir /downloads
[root@myserver ~]# cd /downloads
 
Download the source code tarballs of both Nagios and the Nagios plugins (visit
http://www.nagios.org/download/ for links to the latest versions). These directions were tested with
Nagios 3.1.1 and Nagios Plugins 1.4.11.
  
  1. Compile and Install Nagios
 
Extract the Nagios source code tarball.
 
[root@myserver ~]# cd /downloads
[root@myserver ~]# tar zxvf nagios-3.4.1.tar.gz
[root@myserver~]# cd nagios-3.4.1
 
Run the Nagios configure script, passing the name of the group you created earlier like so:
 
[root@myserver ~]#./configure –with-command-group=nagcmd
 
Compile the Nagios source code.
 
[root@myserver ~]# make all
 
Install binaries, init script, sample config files and set permissions on the external command directory.
 
[root@myserver ~]# make install
[root@myserver ~]# make install-init
[root@myserver ~]# make install-config
[root@myserver ~]# make install-commandmode
 
Don’t start Nagios yet – there’s still more that needs to be done…
  
  1. Customize Configuration
 
Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These samples files should work fine for getting started with Nagios. You’ll need to make just one change before you proceed…
 
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email
Address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.
 
[root@myserver ~]# vim /usr/local/nagios/etc/objects/contacts.cfg
  
  1. Configure the Web Interface
 
Install the Nagios web config file in the Apache conf.d directory.
 
[root@myserver ~]# make install-webconf
 
Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.
 
[root@myserver ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
 
Restart Apache to make the new settings take effect.
 
[root@myserver ~]# Service httpd restart
 
Note: Consider implementing the ehanced CGI security measures described here to ensure that
your web authentication credentials are not compromised.
  
  1. Compile and Install the Nagios Plugins
 
Extract the Nagios plugins source code tarball.
 
[root@myserver ~]# cd /downloads
[root@myserver ~]# tar xzf nagios-plugins-1.4.16.tar.gz
[root@myserver ~]# cd nagios-plugins-1.4.16
 
Compile and install the plugins.
 
[root@myserver ~]#./configure –with-nagios-user=nagios –with-nagios-group=nagios  –with-mysql=/usr(For MySQL )
[root@myserver ~]# make
[root@myserver ~]# make install
 
  
  1. Start Nagios
 
Add Nagios to the list of system services and have it automatically start when the system boots.
 
[root@myserver ~]# chkconfig –add nagios
[root@myserver ~]# chkconfig nagios on
 
Verify the sample Nagios configuration files.
 
[root@myserver ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
 
If there are no errors, start Nagios.
 
[root@myserver ~]# service nagios start
 
Instead of disabling SELinux or setting it to permissive mode, you can use the following command to
run the CGIs under SELinux enforcing/targeted mode:
 
[root@myserver ~]# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
[root@myserver ~]# chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
  
  1. Login to the Web Interface
 
You should now be able to access the Nagios web interface at the URL below. You’ll be prompted for the
username (nagiosadmin) and password you specified earlier.
 
 
©Document Created By Manoj

Quotas allows Administrator to specify restriction in two ways
1) Restricting a user or a group by creating files in a specific location.
2) Restricting a user or a group by the disk space in a specific location.

The idea behind quotas is that users are forced to stay under their disk consumption limit or with number of files in a particular location.




Features:
1. Limits disk usage (blocks or inodes)
2. Tied to file systems (set on a per file system basis)
3. can be configured for users and groups
Steps to enable quota support:
1. Enable quota support per file system in: /etc/fstab
a.
 defaults,usrquota,grpquota
Ex. LABEL=/home     /home    ext3 defaults,usrquota,grpquota 0 0
2. Remount the file system(s)
a.
 mount -o  remount /home
  b. use ‘mount’ to confirm that ‘usrquota,grpquota’ support are enabled
3. Create quota database files and generate disk usage table
  a. quotacheck -mcug /home – this creates /home/quota.user & /home/quota.group
b. quotacheck -mavug 
  c. quotaon /home 
where  a= Check all quota-enabled, locally-mounted file system,
           v= Display verbose status information as the quota check proceeds,
           u= Check user disk quota information,
           g= Check group disk quota information,
           m=Check Force Operation
4. Assign quota policies
  a. edquota username – set blocks/inodes soft_limits hard_limits
b. edquota manoj – sets quotas for user ‘manoj’
 c. export EDITOR=vim – to have edquota default to ‘vim’ editor
  d. edquota -g sales – sets quotas for group ‘sales’
5. Check quotas
 a. quota username

       quota manoj
Note: place ‘quotacheck -mavug’ in /etc/cron.*(hourly,daily)
 6. Report on usage
   a. repquota -a -> this reports on usage
Note: The blocks are measured in 1K increments. i.e. 20000 blocks is roughly20MB
 7. edquota -t -> this contains the time configurations:-:you can edit the grace period(i.e the amount of time a soft limit can be exceeded)
 
 
©Document Created By Manoj
How to reset the MySQL root password?
Step # 1: Stop the MySQL server process.
   # /etc/init.d/mysqld stop

Step # 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password.
     # mysqld_safe –skip-grant-tables&

Step # 3: Connect to mysql server as the root user.
 # mysql -u root

Step # 4: Setup new mysql root account password i.e. reset mysql password.
  mysql> use mysql;
mysql> update user set password=PASSWORD(“NEW-ROOT-PASSWORD”) where User=’root’;
mysql> flush privileges;
mysql> quit

Step # 5: Exit and restart the MySQL server.
   # /etc/init.d/mysql stop

Step # 6: Start MySQL server and test it

 # /etc/init.d/mysql start
# mysql -u root -p

MySQL Database Backup & Restore

Posted: October 9, 2013 in database, MySQL
Tags: , ,
 

How to Backup MySQL Database?
[root@server ~]# mysqldump -u [username] –p[password] [database_name] > [dump_file.sql]

How to Backup a Single MySQL Database?
[root@server ~]# mysqldump -u root -pcentos123 wordpress > wordpress.sql

How to Backup Multiple MySQL Databases?
[root@server ~]# mysqldump -u root -pcentos123 –databases joomla wordpress > joomla_wordpress.sql

How to Backup All MySQL Databases?
[root@server ~]# mysqldump -u root -pcentos123 –all-databases > all-databases.sql

How to Backup MySQL Database Structure Only?

If you only want the backup of database structure without data,
then use the option –no-data in the command.
The below command exports database [wordpress] Structure into a file wordpess_structure.sql.

[root@server ~]# mysqldump -u root -pcentos123 -–no-data wordpress > wordpress_structure.sql

How to Backup MySQL Database Data Only?

To backup database Data only without structure,
then use the option –no-create-info with the command.
This command takes the database [wordpress] Data  into a file wordpress_data.sql.

[root@server ~]# mysqldump -u root -pcentos123 –no-create-db –no-create-info wordpress > wordpress_data.sql

How to Backup Single Table of Database?

With the below command you can take backup of single table or certain tables of your database.
For example, the following command only take backup of wp_posts table from the database wordpress.

[root@myserver ~]# mysqldump -u root -pcentos123 wordpress wp_posts > wordpress_posts.sql

How to Backup Multiple Tables of Database?

If you want to take backup of multiple or certain tables from the database, then separate each table with space.
[root@myserver ~]# mysqldump -u root -pcentos123 wordpress wp_posts wp_comments > wordpress_posts_comments.sql

How to Backup Remote MySQL Database

The below command takes the backup of remote server [10.10.12.143] database [wordpress] into a local server.

[root@myserver ~]# mysqldump -h 10.10.12.143 -u root -pcentos123 wordpress > wordpress.sql

How to Restore MySQL Database?
[root@myserver ~] # mysql -u [username] –p[password] [database_name] < [dump_file.sql]

How to Restore Single MySQL Database

To restore a datab6ase, you must create an empty database on the target machine and
restore the database using msyql command.
For example the following command will restore the rsyslog.sql file to the rsyslog database.

[root@server ~]# mysql -u root -pcentos123 wordpress < wordpress.sql

If you want to restore a database that already exist on targeted machine,
then you will need to use the mysqlimport command.

[root@server ~]# mysqlimport -u root -pcentos123 wordpress < wordpress.sql

 
 
©Document Created By Manoj

SWAP Partion & File Createion

Posted: October 9, 2013 in SWAP
Tags: , ,
Features:
1. Extra, Virtual RAM for the OS
Steps:
1. Identify current swap space
a. swapon -s – enumurates prtitions and/or files, which constitute swap storage
b. free -m

2. select target drive and provision swap partition
a. fdisk /dev/sda
b. n – for new partition
c. P/E – [primary or extended]
d. +1G – size of the partition
e. t – change to type ’82’ (Linux Swap/Solaris)
f. w – for write to disk(save)
g. partprobe /dev/sda – to update

3. Create the Swap File System on the raw partition: /dev/sda6
a. mkswap /dev/sda6

4. Enable swapping – publish the swap space to the kernel
  a. swapon /dev/sda6 – this enables swapping on /dev/sda6

5. update the /etc/fstab
a. /dev/sda6     swap     swap     defaults     0 0

You can use swapoff /dev/sda6 – To disables swapping on /dev/sda6

Create Swap Based On File

Features:
  1. The ability to provision swap space based on a file, similar
to pagefile.sys in Windows NT, etc. , if you have no available disk
space to partition.
2. Doesn’t waste partitions

Task:
1. Create 512MB Swap File
a. dd if=/dev/zero of=/home/swapfile bs=1024 count=524288
b. mkswap /home/swapfile – overlays swap file system
c. swapon /home/swapfile – makes swap space available to the kernel
2. Update the /etc/fstab
a. /home/swapfile          swap     swap     defaults     0 0
swapon -a – it’ll automatically update swap from the fstab file
3. Create 2GB swap file
a. dd if=/dev/zero of=/home/swapfile2 count=2G

Master Hostname – master.example.com IP-10.10.12.143
Slave Hostname –  slave.example.com     IP-10.10.12.120


Configuration on master server

Step # 1: Set the host name in /etc/hosts
[root@master ~] vim /etc/hosts
     10.10.12.143     master.example.com     master

Step # 2: Set the host name in /etc/sysconfig/network
[root@master ~] vim /etc/sysconfig/network
hostname=master.example.com

Step # 3: Set the nameserver in /etc/resolve.conf
[root@master ~] vim /etc/resolve.conf
  search example.com
nameserver 10.10.12.143

Step # 4: Install the Required Packages and Configure the named server
[root@master ~] yum install bind bind-chroot caching-nameserver -y
[root@master ~] cp /var/named/chroot/etc/named.caching-nameserver.conf /var/named/chroot/etc/named.conf
[root@master ~] chgrp named /var/named/chroot/etc/named.conf
[root@master ~] vim /var/named/chroot/etc/named.conf (edit As Follws in Red Mark)

  //
// named.caching-nameserver.conf
//
// Provided by Red Hat caching-nameserver package to configure the
// ISC BIND named(8) DNS server as a caching only nameserver
// (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// DO NOT EDIT THIS FILE – use system-config-bind or an editor
// to create named.conf – edits to this file will be lost on
// caching-nameserver package upgrade.
//
options {
listen-on port 53 { 127.0.0.1;
 10.10.12.143; };
listen-on-v6 port 53 { ::1; };
directory       “/var/named”;
dump-file       “/var/named/data/cache_dump.db”;
statistics-file “/var/named/data/named_stats.txt”;
memstatistics-file “/var/named/data/named_mem_stats.txt”;

  allow-transfer  { localhost; 10.10.12.120; };

// Those options should be used carefully because they disable port
// randomization
// query-source    port 53;
// query-source-v6 port 53;

allow-query     { localhost; any; };
allow-query-cache { localhost; };
};
logging {
channel default_debug {
file “data/named.run”;
severity dynamic;
};
};
view localhost_resolver {
match-clients      { localhost;
 any; };
match-destinations { localhost; };
recursion yes;
include “/etc/named.rfc1912.zones”;
};


[root@master ~] vim /var/named/chroot/etc/named.rfc1912.zone

// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone “.” IN {
type hint;
file “named.ca”;
};

zone “localdomain” IN {
type master;
file “localdomain.zone”;
allow-update { none; };
};

 zone “example.com” IN {
type master;
file “example.com.fz”;
allow-update { none; };
allow-transfer { 10.10.12.120; };
notify yes;

 };
zone “localhost” IN {
type master;
file “localhost.zone”;
allow-update { none; };
};

zone “0.0.127.in-addr.arpa” IN {
type master;
file “named.local”;
allow-update { none; };
};

 zone “12.10.10.in-addr.arpa” IN {
type master;
file “example.com.rz”;
allow-update { none; };

         allow-transfer { 10.10.12.120; };
         notify yes;
 };
zone “0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa” IN {
type master;
file “named.ip6.local”;
allow-update { none; };
};

zone “255.in-addr.arpa” IN {
type master;
file “named.broadcast”;
allow-update { none; };
};

zone “0.in-addr.arpa” IN {
type master;
file “named.zero”;
allow-update { none; };
};

Step # 5: Then Create Zone Files in /var/named/chroot/var/named/ directory

[root@master ~] vim /var/named/chroot/var/named/example.com.fz

$TTL    86400
@               IN SOA  master.example.com. root.master.example.com. (
42              ; serial (d. adams)
3H             ; refresh
15M           ; retry
1W             ; expiry
1D )            ; minimum
@               
     IN NS                master.example.com.

  master             IN A                  10.10.12.143
  slave                IN A                  10.10.12.120
  example.com.    IN MX   10         master.example.com
 

[root@master ~] vim /var/named/chroot/var/named/example.com.rz

$TTL    86400
@       IN      SOA     master.example.com. root.master.example.com.  (
1997022700 ; Serial
28800      ; Refresh
14400      ; Retry
3600000    ; Expire
86400 )    ; Minimum
@         IN      NS      master.example.com.
143       IN      PTR     master.example.com.
120       IN      PTR     slave.example.com.

 
[root@master ~] chown root:named /var/named/chroot/var/named/example.com*
[root@master ~] service named start
[root@master ~] chkconfig named on
 

 Configuration on SLAVE Server


[root@slave ~] vim /var/named/chroot/etc/named.conf
//
// named.caching-nameserver.conf
//
// Provided by Red Hat caching-nameserver package to configure the
// ISC BIND named(8) DNS server as a caching only nameserver
// (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// DO NOT EDIT THIS FILE – use system-config-bind or an editor
// to create named.conf – edits to this file will be lost on
// caching-nameserver package upgrade.
//
options {
listen-on port 53 { 127.0.0.1;
 10.10.12.120; };
listen-on-v6 port 53 { ::1; };
directory       “/var/named”;
dump-file       “/var/named/data/cache_dump.db”;
statistics-file “/var/named/data/named_stats.txt”;
memstatistics-file “/var/named/data/named_mem_stats.txt”;

// Those options should be used carefully because they disable port
// randomization
// query-source    port 53;
// query-source-v6 port 53;

allow-query     { localhost; any; };
allow-query-cache { localhost; };
};
logging {
channel default_debug {
file “data/named.run”;
severity dynamic;
};
};
view localhost_resolver {
match-clients      { localhost;
 any; };
match-destinations { localhost; };
recursion yes;
include “/etc/named.rfc1912.zones”;
};

[root@slave ~] vim /var/named/chroot/etc/named.rfc1912.zone


// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone “.” IN {
type hint;
file “named.ca”;
};

zone “localdomain” IN {
type master;
file “localdomain.zone”;
allow-update { none; };
};

zone “example.com” IN {
type slave;
masters { 10.10.12.143; };
file “slaves/example.com.fz”;
allow-update { none; };

};
zone “localhost” IN {
type master;
file “localhost.zone”;
allow-update { none; };
};

zone “12.10.10.in-addr.arpa” IN {
type slave;
masters { 10.10.12.143; };
file “slaves/example.com.rz”;
allow-update { none; };

};
zone “0.0.127.in-addr.arpa” IN {
type master;
file “named.local”;
allow-update { none; };
};

zone “0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa” IN {
type master;
file “named.ip6.local”;
allow-update { none; };
};
zone “255.in-addr.arpa” IN {
type master;
file “named.broadcast”;
allow-update { none; };
};

zone “0.in-addr.arpa” IN {
type master;
file “named.zero”;
allow-update { none; };
};

Step # 6: Create A Directory named as slaves in /var/named/chroot/var/named/slaves

©Document Created By Manoj