Showing posts with label Centos. Show all posts
Showing posts with label Centos. Show all posts

Monday, March 25, 2013

CentOs - make time zone chagne permanent

— SkyHi @ Monday, March 25, 2013



 1.  Edit /etc/sysconfig/clock
          * ZONE="US/Central" <-this br="" change="" is="" the="" to="" value="">          * UTC=false
          * ARC=false 
   2. run tzdata-update
   3. run /etc/init.d/ntpd restart 


REFERENCES

Wednesday, August 15, 2012

CentOS Change Timezone

— SkyHi @ Wednesday, August 15, 2012

#cp /usr/share/zoneinfo/America/Vancouver /etc/localtime
or
#ln -sf /usr/share/zoneinfo/ America/Vancouver  /etc/localtime
One more point you need to add in post is:
if  copy or create symlink but zone change not reflecting than
#yum search tzdata
#yum update tzdata
than execute date command.
you get the correct time zone.

REFERENCES

Monday, January 16, 2012

Rebooting When Filesystem Fails

— SkyHi @ Monday, January 16, 2012
Recently I found myself stuck with a system that allowed me to ssh into it but the root filesystem was read-only and all the binaries in /sbin, /bin, or /usr/bin were simply not accessible.
I attempted to run shutdown -r now and reboot without any success. I was really stuck as I did not have physical or KVM access to the server which was located in our office and no one were going to be there until 9 AM. Needless to say, I was also trying to avoid going to the office in the middle of the night as I had a early morning drive to the airport to drop off my business partner.
So I decided to explore how I could reboot the system while the disk subsystem was not responding well. I wondered if I could somehow reboot the system by setting some values in the kernel memory via /proc filesystem. My research led me to the following commands:

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

The system rebooted immediately and after automatically running a fsck check on the filesystems, it came back as if nothing had happened, which was a very very lucky thing. It reminded myself that every now and then a little bit of good luck can be great blessing.

REFERENCES

Wednesday, June 29, 2011

CentOS 5.6 unexpected inconsistency how to repair?

— SkyHi @ Wednesday, June 29, 2011
This morning I found that my server was not responding and wasn't able to connect to it in anyway to do a safe reboot. I had to do pull the plug to reboot. Upon rebooting everything appeared to be normal up till booting CentOS. Below is a screenshot of what I have.
CentOS file system error
The HDD's are not reporting any errors so this appears to me that something has corrupted. I haven't a clue what to do next. How can I get this system back up and running?
The server is only used as an rsync offsite backup drive. Reinstalling is an option but only as a last resort as the server is holding 1TB of backup data and to re-sync that it would take a month to do over our office connection.

You've experienced some filesystem corruption. From where you are, you can probably run fsck -y / to kick off the process of filesystem repair, based on the image you attached. The -y answers yes to the questions the fsck command will probably output. Try this first.

REFERENCES
http://serverfault.com/questions/285397/centos-5-6-unexpected-inconsistency-how-to-repair

Tuesday, April 12, 2011

Force yum update Command To Exclude Certain Packages

— SkyHi @ Tuesday, April 12, 2011
Q. How can I exclude selected packages when I rum yum update command under CentOS Linux server?

A. Yum uses a configuration file at /etc/yum/yum.conf or /etc/yum.conf. You need to place exclude directive to define list of packages to exclude from updates or installs. This should be a space separated list. Shell globs using wildcards * and ?) are allowed.
How do I exclude php and kernel packages when I use "yum update"?

Open /etc/yum.conf file:
# vi /etc/yum.conf
Append following line under [main] section, enter:
exclude=php* kernel*
At the end, it should look like as follows:

[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
exclude=php* kernel*

# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=1h

# Default.
# installonly_limit = 3

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

yum --exclude command line option

Finally, you can skip yum command updates on command line itself using following syntax:
# yum --exclude=package* update
# yum --exclude=php* update
# yum --exclude=kernel* update


REFERENCES
http://www.cyberciti.biz/faq/redhat-centos-linux-yum-update-exclude-packages/

Getting yum updates by E-mail

— SkyHi @ Tuesday, April 12, 2011
I run several CentOS 4.0 servers, and having to manually check each server for new updates is tedious. To simplify my life, I decided to write a shell script (yumnotifier) to E-mail me when new updates are available. The script (yumnotifier) analyzes the output from ‘yum check-update,’ and generates an E-mail similar to the following if updates are available:

From root@localhost.localdomain Sat Jul 15 19:24:59 2006
Date: Sat, 15 Jul 2006 19:24:59 -0400
From: root
To: matty@localhost.localdomain
Subject: Updates available for biscuit

==== The following updates are available for biscuit ===

comps.i386 2:4.3CENTOS-0.20060314 base
gtk2.i386 2.4.13-18 base
kernel.i686 2.6.9-34.0.2.EL update
libtiff.i386 3.6.1-10 update
mysql.i386 4.1.20-1.RHEL4.1 update
mysql-devel.i386 4.1.20-1.RHEL4.1 update

If you manage systems that use yum, you might be interested in this script.

#!/bin/sh 
#
# Program: E-mail available yum updates <yumnotifier>
#
# Author: Matty < matty91 at gmail dot com >
#
# Current Version: 1.2
#
# Revision History:
#
#  Version 1.2
#    - Removed ! from if statement - John Beaman
#    - Changed comments to reference "yumnotifier", not
#      "yumupdate" -- John Beaman
#
#  Version 1.1
#    - Switched test statement to use "-s" - Luca Rozza
#
#  Version 1.0
#    Initial Release
#
# Last Updated: 10-24-2007
#
# Purpose:
#   yumnotifier checks for updated software package, and E-mails the
#   address defined in the ${ADMIN} variable if updates are available.
#
# License:
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Installation:
#   Copy the shell script to a suitable location
#
# Usage:
#   To check for new updates each day at midnight, a cron job similar to the
#   following can be used:
#
#   $ crontab -l | grep yumnotifier
#   0 0 * * * /etc/scripts/yumnotifier
#
# Sample output
#   An E-mail similar to the following is sent if updates are available:
#
#   From root@localhost.localdomain  Sat Jul 15 19:24:59 2006
#   Date: Sat, 15 Jul 2006 19:24:59 -0400
#   From: root <root@localhost.localdomain>
#   To: matty@localhost.localdomain
#   Subject: Updates available for biscuit
#  
#   ==== The following updates are available for biscuit ===
#  
#   comps.i386                               2:4.3CENTOS-0.20060314 base            
#   gtk2.i386                                2.4.13-18              base            
#   kernel.i686                              2.6.9-34.0.2.EL        update          
#   libtiff.i386                             3.6.1-10               update          
#   mysql.i386                               4.1.20-1.RHEL4.1       update          
#   mysql-devel.i386                         4.1.20-1.RHEL4.1       update          
#   newt.i386                                0.51.6-7.rhel4         base            
#   php.i386                                 4.3.9-3.15             update          
#   php-ldap.i386                            4.3.9-3.15             update          
#   php-pear.i386                            4.3.9-3.15             update          
#   postgresql-libs.i386                     7.4.13-2.RHEL4.1       update          
#   rpmdb-CentOS.i386                        2:4.3-0.20060314       base            
#   sendmail.i386                            8.13.1-3.RHEL4.5       update          
#   sendmail-cf.i386                         8.13.1-3.RHEL4.5       update          
#   spamassassin.i386                        3.0.6-1.el4            update          
#   vixie-cron.i386                          4:4.1-44.EL4           update          
#   xorg-x11-Mesa-libGL.i386                 6.8.2-1.EL.13.25.1     update          
#   xorg-x11-font-utils.i386                 6.8.2-1.EL.13.25.1     update          
#   xorg-x11-libs.i386                       6.8.2-1.EL.13.25.1     update          
#   xorg-x11-xauth.i386                      6.8.2-1.EL.13.25.1     update          
#   xorg-x11-xfs.i386                        6.8.2-1.EL.13.25.1     update        

PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH

# Locations of binaries
GREP="/bin/grep"
HOST=`hostname`
MAIL="/bin/mail"
MKTEMP="/bin/mktemp"
YUM="/usr/bin/yum"

# Who to E-mail with new updates
ADMIN="matty"

if [ ! -f ${YUM} ]
then
        echo "Cannot find ${YUM}"
        exit 1
fi

if [ ! -f ${MKTEMP} ]
then
        echo "Cannot find ${MKTEMP}"
        exit 1
fi

if [ ! -f ${MAIL} ]
then
        echo "Cannot find ${MAIL}"
        exit 1
fi

if [ ! -f ${GREP} ]
then
        echo "Cannot find ${GREP}"
        exit 1
fi

# Dump the yum results to a safe working file
WORK=`${MKTEMP} /tmp/yum.results.XXXXXX`

${YUM} -e0 -d0 check-update > ${WORK}

# If there are updates available, E-mail them
if [ -s ${WORK} ]
then
        REPORT=`${MKTEMP} /tmp/yum.report.XXXXXX`
        echo "==== The following updates are available for ${HOST} ===" > ${REPORT}
        cat ${WORK} >> ${REPORT}
        cat ${REPORT} | ${MAIL} -s "Updates available for ${HOST}" ${ADMIN}
fi

# Cleanup temporary files
rm ${REPORT} ${WORK}



Great script – much better than my last attempt to do this. I made a small change to ignore kernel updates and only send an email if the return code for yum check-update is not zero:

${YUM} -e0 -d0 check-update –exclude=kernel* > ${WORK}

# If there are updates available, E-mail them
if [ $? -ne "0" ]
then
REPORT=`${MKTEMP} /tmp/yum.report.XXXXXX`
echo “==== The following updates are available for ${HOST} ===” > ${REPORT}
cat ${WORK} >> ${REPORT}
cat ${REPORT} | ${MAIL} -s “Updates available for ${HOST}” ${ADMIN}

REFERENCES
http://prefetch.net/blog/index.php/2006/07/16/getting-yum-updates-by-e-mail/
http://prefetch.net/code/yumnotifier

Wednesday, April 6, 2011

Linux Determine which Services are Enabled at Boot

— SkyHi @ Wednesday, April 06, 2011
The best protection against vulnerable software is running less software. How do I find out which services are enabled at Boot under CentOS / RHEL / Fedora Linux? How do I disable software which is not needed?

Open terminal and login as root user.
Type the following command to list all services which are enabled at boot:


#chkconfig --list | grep $(runlevel  | awk '{ print $2}'):on


Sample output:


acpid           0:off 1:off 2:off 3:on 4:on 5:on 6:off
anacron         0:off 1:off 2:on 3:on 4:on 5:on 6:off
atd             0:off 1:off 2:off 3:on 4:on 5:on 6:off
auditd          0:off 1:off 2:on 3:on 4:on 5:on 6:off
cpuspeed        0:off 1:on 2:on 3:on 4:on 5:on 6:off
crond           0:off 1:off 2:on 3:on 4:on 5:on 6:off
dkms_autoinstaller 0:off 1:off 2:on 3:on 4:on 5:on 6:off
haldaemon       0:off 1:off 2:off 3:on 4:on 5:on 6:off
hidd            0:off 1:off 2:on 3:on 4:on 5:on 6:off
irqbalance      0:off 1:off 2:on 3:on 4:on 5:on 6:off
kudzu           0:off 1:off 2:off 3:on 4:on 5:on 6:off
lighttpd        0:off 1:off 2:on 3:on 4:on 5:on 6:off
lm_sensors      0:off 1:off 2:on 3:on 4:on 5:on 6:off
lvm2-monitor    0:off 1:on 2:on 3:on 4:on 5:on 6:off
mcstrans        0:off 1:off 2:on 3:on 4:on 5:on 6:off
mdmonitor       0:off 1:off 2:on 3:on 4:on 5:on 6:off
messagebus      0:off 1:off 2:off 3:on 4:on 5:on 6:off
microcode_ctl   0:off 1:off 2:on 3:on 4:on 5:on 6:off
mysqld          0:off 1:off 2:on 3:on 4:on 5:on 6:off
named           0:off 1:off 2:on 3:on 4:on 5:on 6:off
netfs           0:off 1:off 2:off 3:on 4:on 5:on 6:off
network         0:off 1:off 2:on 3:on 4:on 5:on 6:off
ntpd            0:off 1:off 2:on 3:on 4:on 5:on 6:off
pcscd           0:off 1:off 2:on 3:on 4:on 5:on 6:off
psacct          0:off 1:off 2:on 3:on 4:on 5:on 6:off
readahead_early 0:off 1:off 2:on 3:on 4:on 5:on 6:off
restorecond     0:off 1:off 2:on 3:on 4:on 5:on 6:off
rhnsd           0:off 1:off 2:on 3:on 4:on 5:on 6:off
rpcgssd         0:off 1:off 2:off 3:on 4:on 5:on 6:off
rpcidmapd       0:off 1:off 2:off 3:on 4:on 5:on 6:off
sendmail        0:off 1:off 2:on 3:on 4:on 5:on 6:off
setroubleshoot  0:off 1:off 2:off 3:on 4:on 5:on 6:off
smartd          0:off 1:off 2:on 3:on 4:on 5:on 6:off
snmpd           0:off 1:off 2:on 3:on 4:on 5:on 6:off
sshd            0:off 1:off 2:on 3:on 4:on 5:on 6:off
stor_agent      0:off 1:off 2:off 3:on 4:off 5:on 6:off
syslog          0:off 1:off 2:on 3:on 4:on 5:on 6:off
sysstat         0:off 1:off 2:on 3:on 4:off 5:on 6:off
vmware          0:off 1:off 2:on 3:on 4:off 5:on 6:off
xfs             0:off 1:off 2:on 3:on 4:on 5:on 6:off
xinetd          0:off 1:off 2:off 3:on 4:on 5:on 6:off
yum-updatesd    0:off 1:off 2:on 3:on 4:on 5:on 6:off



The first column of above output is the name of a service which is currently enabled at boot. You need to review each service.

Task: Disable service

To stop service, enter:
# service {service-name} stop
# service vmware stop

To disable service, enter:
# chkconfig {service-name} off
# chkconfig vmware off

You can also use ntsysv command to manage all services.

A note about outdated insecure service

All of the following services must be disabled to improve server security:
  1. Inetd and Xinetd (inetd xinetd) - Use direct services configured via SysV and daemons.
  2. Telnet (telnet-server) - Use ssh
  3. Rlogin, Rsh, and Rcp ( rsh-server ) - Use ssh and scp.
  4. NIS (ypserv) : Use OpenLDAP or Fedora directory server.
  5. TFTP (tftp-server) : Use SFTP or SSH.
To delete all of the service enter:
# yum erase inetd xinetd ypserv tftp-server telnet-server rsh-serve

A note about Debian / Ubuntu Linux

Please see my comment below, to find out which services are enabled at boot under Debian / Ubuntu Linux and disable software which is not needed.

To list all boot time enabled services use the following costume shell code (type at command prompt):


R=$(runlevel  | awk '{ print $2}')
for s in /etc/rc${R}.d/*; do  basename $s | grep '^S' | sed 's/S[0-9].//g' ;done



Sample output:

policykit
vbesave
acpid
powernowd.early
sysklogd
xserver-xorg-input-wacom
klogd
dbus
avahi-daemon
dnsmasq
mysql-ndb-mgm
mysql-ndb
mysql
acct
apmd
apport
argus-server
dkms_autoinstaller
fancontrol
festival
hddtemp
ipmievd
nscd
scanlogd
sysstat
tcpspy
varnish
vboxdrv
vsftpd
winbind
aumix
dhcdbd
hal
pulseaudio
gdm
squid
system-tools-backends
radvd
anacron
atd
cron
binfmt-support
tomcat5.5
apache2
usplash
acpi-support
laptop-mode
rc.local
rmnologin
stop-readahead


 To turn off service use T-GUI tools like rcconf or simply type:

update-rc.d -f {service-name} remove

 update-rc.d {service-name} stop 20 2 3 4 5 .


For example, remove apache2, enter:


update-rc.d -f apache2 remove
update-rc.d apache2 stop 20 2 3 4 5 .


Use rcconf tool to view enabled services. See the following posts for more info about Debian / Ubuntu services:
REFERENCES
http://www.cyberciti.biz/faq/linux-determine-which-services-are-enabled-at-boot/#comment-41093

Saturday, November 13, 2010

Postfix records in maillog have time stamps from different time zones

— SkyHi @ Saturday, November 13, 2010

Symptoms

If you look at /usr/local/psa/var/log/maillog, you may find your postfix/smtpd time stamp is switched by several hours:

Feb 15 05:24:33 server postfix/smtpd[11984]
Feb 15 14:24:44 server postfix/smtpd[12001]
Feb 15 05:24:44 server postfix/smtpd[11984]
Feb 15 05:24:44 server postfix/smtpd[12001]
Feb 15 14:24:45 server before-remote[12000]

Resolution

It is compounded by the fact that a part of Postfix processes, for security reasons, runs in chrooted environment and /etc/localtime is not accessible for them, so that records are written into maillog with UTC time zone.

To resolve the issue create directory /var/spool/postfix/etc :
# mkdir /var/spool/postfix/etc

and copy file /etc/localtime to that directory:
# cp /etc/localtime /var/spool/postfix/etc/

Then restart mail service.

Additional information

This issue affects only Postfix on RPM-based systems. Script /etc/init.d/postfix on Debian GNU/Linux copies necessary files on start. 
 
REFERENCES
http://kb.parallels.com/8082

CentOS: Install Packages Via yum Command Using DVD / CD as Repo

— SkyHi @ Saturday, November 13, 2010
How do I install packages via DVD / CD using yum command under CentOS Community Enterprise Linux version 5.x?

CentOS Linux comes with CentOS-Media.repo which is used to mount the default locations for a CDROM / DVD on CentOS-5. You can use this repo and yum to install items directly off the DVD ISO that we release. Open /etc/yum.repos.d/CentOS-Media.repo file, enter:
# vi /etc/yum.repos.d/CentOS-Media.repo
Make sure enabled is set to 1:
enabled=1
Save and close the file. To use repo put your DVD and along with the other repos, enter:
# yum --enablerepo=c5-media install pacakge-name
To only use the DVDmedia repo, do this:
# yum --disablerepo=\* --enablerepo=c5-media install pacakge-name
OR use groupinstall command
# yum --disablerepo=\* --enablerepo=c5-media groupinstall 'Virtualization'

See Also:

RHEL 5.x user can use the following tutorial to install files from DVD / CD using yum:
  1. Howto Setup yum repositories to update or install package from ISO CDROM Image



Howto Setup yum repositories to update or install package from ISO CDROM Image

by Vivek Gite · 24 comments
yum (Yellow dog Updater Modified) is a package manager for RPM compatible Linux systems such as CentOS, Fedora core and latest Redhat Enterprise Linux.
So how do you use yum to update / install packages from an ISO of CentOS / FC / RHEL CD?
Creation of yum repositories is handled by a separate tool called createrepo, which generates the necessary XML metadata. If you have a slow internet connection or collection of all downloaded ISO images, use this hack to install rpms from iso images.

Step # 1: Mount an ISO file

Type the following command (replace iso file name with the actual iso file):
# yum install createrepo
# mkdir -p /mnt/iso/{1,2,3}
# mount -o loop /path/to/centos1.iso /mnt/iso/1

Step # 2: Create a repository

Use createrepo to generate the necessary XML metadata. Type the following commands:
# cd /mnt/iso
# createrepo .

Clean repo, enter:
# yum clean all

Step # 3: Create config file

You need to create a repo config file in /etc/yum.repos.d/ directory.
# vi /etc/yum.repos.d/iso.repo
Append following text:
[My ISO Repository]
baseurl=file:///mnt/iso
enabled=1

Save and close the changes.
Now use yum command to install packages from ISO images:
# yum install package-name


REFERENCES
http://www.cyberciti.biz/faq/centos-linux-install-packages-from-dvd-using-yum/
http://www.cyberciti.biz/tips/redhat-centos-fedora-linux-setup-repo.html

Friday, November 5, 2010

Howto: Linux server change or setup the timezone

— SkyHi @ Friday, November 05, 2010
Q. My timezone is pointing to wrong timezone. How do I setup or change the timezone under Linux operating systems?

A. Unix time, or POSIX time, is a system for describing points in time: it is the number of seconds elapsed since midnight UTC on the morning of January 1, 1970, not counting leap seconds.
The definition for time zones can be written in short form as UTC±n (or GMT±n), where n is the offset in hours.

Change Linux timezone

Select the method as per your Linux distribution:

If you are using Fedora / RHEL / Cent OS Linux

Type the redhat-config-date command at the command line to start the time and date properties tool.
# redhat-config-date
OR type setup and select time zone configuration (good for remote ssh text based Linux server sessiob)
# setup
Select timezone configuration


Fig.01: Redhat / CentOS Server Setting Up Timezone
Now, just follow on screen instructions to change timezone.

Set timezone using /etc/localtime configuration file [any Linux distro]

Often /etc/localtime is a symlink to the file localtime or to the correct time zone file in the system time zone directory.

Generic procedure to change timezone

Change directory to /etc
# cd /etc
Create a symlink to file localtime:
# ln -sf /usr/share/zoneinfo/EST localtime
OR some distro use /usr/share/zoneinfo/dirname/zonefile format (Red hat and friends)
# ln -sf /usr/share/zoneinfo/EST localtime
OR if you want to set up it to IST (Asia/Calcutta):
# ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime
Please mote that in above example you need to use directory structure i.e. if you want to set the timezone to Calcutta (India) which is located in the Asia directory you will then have to setup using as above.
Use date command to verify that your timezone is changed:
$ date
Output:
Tue Aug 27 14:46:08 EST 2006

Use of environment variable

You can use TZ environment variable to display date and time according to your timezone:
$ export TZ=America/Los_Angeles
$ date

Sample Output:
Thu Aug 27 11:10:08 PST 2006
 


[root@home ~]# date 110509572010
Fri Nov  5 09:57:00 PST 2010
[root@home ~]# date
Fri Nov  5 09:57:01 PST 2010

REFERENCES
http://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/

Thursday, October 21, 2010

CentOS change hostname without reboot

— SkyHi @ Thursday, October 21, 2010
Step 1:
You may also need to add/change the hostname in the /etc/hosts file. By default this would look something like this, using our www.example.com example again:

127.0.0.1 www.example.com localhost localhost.localdomain


Step 2:
The file /etc/sysconfig/network contains the hostname and will look something like this:

NETWORKING="yes"
GATEWAY="10.1.1.1"
HOSTNAME="www.example.com"

Step 3:
This change won't take affect until the next reboot, but you can make the change happen immediately using the hostname command like so:

$ hostname ftp.example.com

Step 4:
service syslog restart


========================================================================
Change your Hostname without Rebooting in RedHat Linux
Written by Tony Bhimani
September 8, 2005
Requirements
RedHat Linux (should apply to 7.x and up)
This tutorial covers changing your hostname in RedHat Linux without having to do a reboot for the changes to take effect. I've tested this on RedHat 7.3, 9, Fedora Core 3, and CentOS 4.1. It should work for all the versions in between since they all closely follow the same RedHat configuration. What's the point of this tutorial? Never reboot if you don't have to and keep your uptime intact.
Make sure you are logged in as root and move to /etc/sysconfig and open the network file in vi.
cd /etc/sysconfig
vi network


Look for the HOSTNAME line and replace it with the new hostname you want to use. In this example I want to replace localhost with redhat9.
HOSTNAME=redhat9

When you are done, save your changes and exit vi. Next we will edit the /etc/hosts file and set the new hostname.
vi /etc/hosts

In hosts, edit the line that has the old hostname and replace it with your new one.
192.168.1.110  redhat9

Save your changes and exit vi. The changes to /etc/hosts and /etc/sysconfig/network are necessary to make your changes persistent (in the event of an unscheduled reboot).
Now we use the hostname program to change the hostname that is currently set.
hostname redhat9
And run it again without any parameters to see if the hostname changed.
hostname

Finally we will restart the network to apply the changes we made to /etc/hosts and /etc/sysconfig/network.
service network restart

To verify the hostname has been fully changed, logout of your system and you should see your new hostname being used at the login prompt and after you've logged back in.

Quick, painless, and you won't lose your server's uptime.



REFERENCES

 

Wednesday, September 22, 2010

How to install OpenVZ and Vtonf control panel in centos

— SkyHi @ Wednesday, September 22, 2010
OpenVZ 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 systemopenvz instances, known as containers, Virtual Private Servers (VPSs), or Virtual Environments (VEs). It is similar to FreeBSD Jails and Solaris Zones.
As compared to virtual machines such as VMware and paravirtualization technologies like Xen, OpenVZ is limited in that it requires both the host and guest OS to be Linux (although Linux distributions can be different in different containers). However, OpenVZ claims a performance advantage; according to its website, there is only a 1–3% performance penalty for OpenVZ
as compared to using a standalone server. One independent performance evaluation confirms this. Another shows more significant performance penaltie s  depending on the metric used.
In this tutorial will show you how to install OpenVZ in CentOS and how to install Vtonf, another web interface for OpenVZ

I- Install OpenVZ:

1-First add openVZ repository to Centos:
Open terminal and copy the commands:
wget http://download.openvz.org/openvz.reporpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
cp openvz.repo /etc.recpo.d 

2-Install  openvz  kernel:


yum install ovzkernel

3- edit the /etc/systcl.conf

Open /etc/systcl.conf  and add these lines:
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0 

4- Disable Selinux

To disable Selinux, first open the config file
vi  /etc/selinux/config  
Then look for the line bellow and make sure that is disabled
SELINUX=disabled

5- Install openvz tools and plugins
yum install vzctl vzquota

6- Restart openv Services:
service vz restart

II - Create Virtual OS /Containers

we have Openvz installed. Now is time to create a Virtual os /containers, for that we need to download an OS template.
An OS template cache is an OS template installed into a container and then packed into a gzipped tarball. Using such a cache, a new container can be created in a matter of minutes, if not seconds.
In the example bellow we used Slackware template, for other templates please visit this link.
First cd the cache folder
cd   /vz/template/cache 

and download the template :

[root@localhost cache]# wget  http://download.openvz.org/template/precreated/contrib/slackware-13.0-i386-minimal.tar.gz
--2010-06-27 16:55:33--  http://download.openvz.org/template/precreated/contrib/slackware-13.0-i386-minimal.tar.gz
Resolving download.openvz.org... 64.131.90.11
Connecting to download.openvz.org|64.131.90.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 39641862 (38M) [application/x-gzip]
Saving to: `slackware-13.0-i386-minimal.tar.gz'

100%[===============================================================>] 39,641,862  4.48M/s   in 14s     

2010-06-27 16:55:47 (2.71 MB/s) - `slackware-13.0-i386-minimal.tar.gz' saved [39641862/39641862]

 

  • Lets create the VPS 102 now

vzctl  create     102    --ostemplate    slackware-13.0-i386-minimal     --config   basic 
Output:
Creating container private area (slackware-13.0-i386-minimal)
Performing postcreate actions
Container private area was created


  • Make this VM(virtual machine start on boot)

[root@localhost cache]# vzctl set 102  --onboot yes --saveSaved parameters for CT 102make  a  Hostname  for  The  machien:vzctl set 102 --hostname  Hackers.example.com --saveGive  Ip  adress   192.168.0.130  to  the  machine:
[root@localhost cache]#  vzctl set 102 --ipadd 192.168.0.130  --saveSaved parameters for CT 102
[root@localhost cache]#
  • Now start the VM machine 102
  vzctl start
Output
102 Starting container ...Container is mountedAdding IP address(es): 192.168.0.130Setting CPU units: 1000Set hostname: Hackers.example.comContainer start in progress...
  • Make a root password for the machine:
  vzctl exec 102 passwd 
Output:
New password: Zz123456
Re-enter new password: Zz123456
Changing password for root
Enter the new password (minimum of 5, maximum of 127 characters)Please use a combination of upper and lower case letters and numbers.Password changed


  • Enter The slackware machine 102
  vzctl enter  102 
Output:
entered into CT 102
root@Hackers:/# cat /etc/slackware-version
Slackware 13.0.0.0.0
Stop of start or Exit
More commands :
To restart  use : vzctl restart To stop  use :   vzctl stop
to destroy the   vm machine user  : vzctl destro 102
For more commands use :vzctl -help

III- Install Vtonf a web interface manager for OpenVZ

VTONF is a Virtual private server (VPS) control panel. It is designed to perform VPS operations in a GNU/Linux server having OpenVZ virtualization technology. VTONF is a Free software distributed under GPL license.
  • Install  Vtonf :
Open terminal and type the commands bellow ( Don`t forget to change the version of vtonf  vtonfinstaller.x.x-beta1.tar.gz to the current version you are trying to install)
cd /tmp
 wget  http://mesh.dl.sourceforge.net/sourceforge/vtonf/vtonfinstaller.x.x-beta1.tar.gz
 tar xvfz vtonfinstaller.1.0-beta1.tar.gz
 cd vtonfinstaller.x.x-beta1
 ./install
When Vtonf control panel installation is completed, you can login to the control panel using the following informations:
http://192.168.0.109:8001/
 Login Name : admin
 Password : admin











REFERENCES
http://www.unixmen.com/linux-tutorials/1024-how-to-install-openvz-and-vtonf-control-panel-in-centos-

Thursday, September 16, 2010

How to Compile the Linux Kernel

— SkyHi @ Thursday, September 16, 2010

Compiling the Linux kernel used to be a rite of passage, or just a necessity, for running Linux. It's not something most users need to do any more, but if you really want to compile your own kernel we'll show you how.


Even though it's not necessary, a lot of users still want to know how to compile the Linux kernel. Unfortunately, there's not just one way to do it. I'll show one way to build a kernel from source, but you may want to consult your distribution's documentation for the proper way to build from source for your distribution. Here we're going to build from source and install directly without creating an RPM or Debian package for the kernel. If there's a lot of demand, we'll do specific tutorials on creating kernels for Ubuntu and Fedora.


Word of Warning



When I first started using Linux in 1996, it was almost mandatory to compile your own kernel. Thankfully, things have change a lot since then. It's very rare that you need to compile your own kernel these days, unless you really know what you're doing (in which case, you probably don't need this tutorial), want to help with kernel testing, or run into a very unusual situation.


You may need to compile modules, which is somewhat different. Because support for devices can be compiled as modules rather than requiring a kernel rebuild, you can simply compile modules and insert them into the existing kernel.


If you want to help with kernel testing, great! If you have a few hours and can compile and boot a kernel (most problems show up right away), then you'll be doing the Linux community a favor by testing it out. If you're wanting to run a custom kernel on your desktop, laptop, or servers, that's fine — but don't expect your distribution vendor or project to support it or accept bug reports about a kernel problem unless you're running the stock builds that they provide. If you're compiling a kernel just because you can, that's great — but don't expect any technical support!


Finally, the kernel you get from your distribution and the kernel that comes from kernel.org are generally not going to be the same thing — even if they're the same version number. This is because almost every distribution ships a modified Linux kernel with their own patches and tweaks.


Getting Ready to Compile



Before compiling the kernel, you have to have the development tools and you'll need to create a configuration file that specifies what should (and shouldn't) be compiled with the kernel. Also, plan to have an hour or more for the whole exercise, depending on how fast your machine is. If you're compiling a kernel on a quad-core Core i7 with loads of RAM, it'll go much faster. If you're compiling the kernel on an Atom-based netbook with 1GB of RAM, it's probably not going to be very speedy — though probably still much faster than the Pentium 133MHz system I compiled my first kernel on.


If you're new to the whole "compiling a kernel" thing, I strongly recommend that you do not do this on a production machine. If you have VMware or VirtualBox installed, use those to compile your custom kernel a few times. If you have a spare box, use that. If you are going to compile the kernel on your production desktop, server, laptop, or netbook the first time (against my advice) make sure you have a backup and a rescue disk handy just to be on the safe side. Odds are you won't need them, but it's always better to have backups and such and not need them than the converse.


Finally, you'll also need kernel source — either the source for the kernel that ships with your distro, or one of the kernels from kernel.org. We're going to do this with a kernel.org kernel.


On CentOS 5.5, you'll need to install the ncurses-devel package, and the Development Tools group of packages, if you don't have them already. Note that I pulled some of this info from the CentOS wiki, to give credit where due. To install these packages, run:


yum groupinstall "Development Tools"

yum install ncurses-devel

yum install qt-devel

yum install unifdef


Next it's time to create the directories where you're going to compile the source. You're going to compile the kernel as a normal user, and then install the kernel as root. I keep a src directory in my home directory, you'll probably want to do the same. Download the kernel source in the src directory, and then uncompress it:


tar -jxvf linux-2.6.35.4.tar.bz2


The version number will probably differ. Now cd into the linux-2.6.35.4 directory. The kernel has a dazzling array of tools to help create your config. You can use standard make config to get a series of questions, or make menuconfig for an ncurses (text) interface to compile the kernel. Alternatively, you can use a GUI to walk through the menus, like make xconfig.


If this is the first time you've attempted a kernel compile, the menus can be a bit intimidating. It's hard to give any advice as to what options you should or shouldn't select because your reasons for compiling a kernel are going to be different than mine.


You might want to start with the config file that your distribution uses. Grab the source RPM for the kernel and install it:


rpm -i http://mirror.centos.org/centos/5/updates/SRPMS/kernel-2.6.18-194.11.3.el5.src.rpm


Now look under /usr/src/kernels, mine's located at /usr/src/kernels/2.6.18-194.11.3.el5-x86_64 but this will vary depending on architecture and version number. Under this directory there's a .config file. Copy it to the directory with your Linux source. Run make xconfig and then load the .config that you copied over. Make any changes to the configuration you wan to, and then save the configuration.


Still with me? It's time to do some compilin'! Run make, and get ready to sit back for a while. It will take a while for the kernel to compile. Really, even on a fast machine, it still will take the kernel quite some time to compile.


Once the kernel is finished compiling, you need to install the kernel and modules, and then configure grub. You'll need to switch to root or use sudo here:


make modules install

make install


Now check your grub.conf under /boot/grub/grub.conf and make sure you have the configuration for your kernel. Previously I've had to hand-edit grub or LILO, but when I was writing this up I found that the make install process had apparently done it for me. You should see some lines like this:




#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.35.4)
root (hd0,0)
kernel /vmlinuz-2.6.35.4 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.35.4.img
title CentOS (2.6.18-194.11.3.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.11.3.el5 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-194.11.3.el5.img
title CentOS (2.6.18-194.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-194.el5.img 


Note that grub counts from 0 and not 1, so you'll need to change accordingly. And, time to reboot!


Finishing Up



Assuming all went well, you're now running a custom kernel you compiled yourself. Congratulations! If not, you can reboot and choose one of the known good kernels and start again. If you need to report a bug in the kernel, refer to this note.


Compiling a kernel can be a great way to fine-tune your system or enable support for experimental features, etc. However, I can't stress enough that it's not really necessary to do so unless you want to help test the kernel or have a good reason to compile your own. The stock kernels provided by most distributions are just fine. But if you enjoy tinkering with the kernel, by all means have at it!


REFERENCES:
http://www.linux.com/learn/tutorials/362602-how-to-compile-the-linux-kernel

Tuesday, September 14, 2010

Find Command Exclude Directories From Search Pattern

— SkyHi @ Tuesday, September 14, 2010
How do I exclude certain directories while using the find command under UNIX or Linux operating systems?

You can use the find command as follows to find all directories except tmp directory:
find /path/to/dest -type d \( ! -name tmp \) -print
 
Find all directories except tmp and cache:
find /path/to/dest -type d \( ! -name tmp \) -o \( ! -name cache \) -print
 
The -prune option make sure that you do not descend into directory:
find /path/to/dest -type d \( ! -name tmp \) -o \( ! -name cache -prune \) -print
 
You can find all *.pl find except in tmp and root directory, enter:
find /  \( ! -name tmp \) -o \( ! -name root -prune \)  -name "*.pl" -print
 
Your find command may not support -delete option, so use it as follows:
# find /var/pub/ftp/incoming -type f -print0 | xargs -0 -I file rm -f file
OR
# find  /var/pub/ftp/incoming -type f -exec rm -f {} \;
 
You can also select file types. In this example, delete all *.exe files, enter:   
# find  /var/pub/ftp/incoming -type f -iname "*.exe" -exec rm -f {} \;
 
 
 
To find all symlinks to /etc/resolv.conf, use the find command as follows:
# find /path/to/dir -lname /path/to/file
# find / -lname /etc/resolv.conf
 
/path/to/file is a symbolic link whose contents match shell pattern 
pattern.  The metacharacters do not treat / or . specially. The -ilname 
FILE options is like  -lname,  but  the  match  is  case insensitive:

# find / -ilname resolv.conf  
  
 

Find Command Exclude Directories From Search Pattern

 
You can use the find command as follows to find all directories except tmp directory:
find /path/to/dest -type d \( ! -name tmp \) -print
Find all directories except tmp and cache:
find /path/to/dest -type d \( ! -name tmp \) -o \( ! -name cache \) -print

The -prune option make sure that you do not descend into directory:
find /path/to/dest -type d \( ! -name tmp \) -o \( ! -name cache -prune \) -print

You can find all *.pl find except in tmp and root directory, enter:
find / \( ! -name tmp \) -o \( ! -name root -prune \) -name "*.pl" -print
  
REFERENCES
http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories/
http://www.cyberciti.biz/faq/deleting-file-in-many-subdirectories-linux-unix-command/ 
http://www.cyberciti.biz/faq/linux-unix-osx-bsd-find-command-exclude-directories/ 

Setting Up a CentOS / Red Hat Linux DHCP Client

— SkyHi @ Tuesday, September 14, 2010
Q. How do I setup my Red Hat / CentOS / Fedora Linux system to get IP address and other information via a DHCP server for eth0 interface?

A. You can edit eth0 configuration file to switch between static and dhcp networking configuration under RHEL / Fedora or CentOS Linux. Simply edit /etc/sysconfig/network-scripts/ifcfg-eth0 file.

Backup existing static configuration

First backup existing network configuration file using cp command:
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /root/ifcfg-eth0.bak

Configuring a DHCP Client

Setting up a Linux for dhcp can be done by editing file using a text editor such as vi:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Following is sample static configuration:
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:19:D1:2A:BA:A8
IPADDR=10.10.29.66
NETMASK=255.255.255.192
ONBOOT=yes

Replace static configuration with DHCP:
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:19:D1:2A:BA:A8
ONBOOT=yes

Save and close the file. Just restart network service:
# /etc/init.d/network restart
Please note that you need a configuration file for each device that you want to configure to use DHCP.

REFERENCES
http://www.cyberciti.biz/faq/setting-up-a-linux-for-dhcp/

Friday, September 10, 2010

HowTo: Debug Crashed Linux Application Core Files Like A Pro

— SkyHi @ Friday, September 10, 2010
Core dumps are often used to diagnose or debug errors in Linux or UNIX programs. Core dumps can serve as useful debugging aids for sys admins to find out why Application like Lighttpd, Apache, PHP-CGI or any other program crashed. Many vendors and open source project author requests a core file to troubleshoot a program. A core file is generated when an application program abnormally terminates due to bug, operating system security protection schema, or program simply try to write beyond the area of memory it has allocated, and so on. This article explains how to turn on core file support and track down bugs in programs.

Turn On Core File Creation Support

By default most Linux distributions turn off core file creation (at least this is true for RHEL, CentOS, Fedora and Suse Linux). You need to use the ulimit command to configure core files.

See The Current Core File Limits

Type the following command:
# ulimit -c
Sample outputs:
0
The output 0 (zero) means core file is not created.

Change Core File Limits

In this example, set the size limit of core files to 75000 bytes:
# ulimit -c 75000

HowTo: Enable Core File Dumps For Application Crashes And Segmentation Faults

Edit /etc/profile file and find line that read as follows to make persistent configuration:
ulimit -S -c 0 > /dev/null 2>&1
Update it as follows:
ulimit -c unlimited >/dev/null 2>&1
Save and close the file. Edit /etc/sysctl.conf, enter:
# vi /etc/sysctl.conf
Append the following lines:
kernel.core_uses_pid = 1
kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t
fs.suid_dumpable = 2
Save and close the file. Where,
  1. kernel.core_uses_pid = 1 - Appends the coring processes PID to the core file name.
  2. fs.suid_dumpable = 2 - Make sure you get core dumps for setuid programs.
  3. kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t - When the application terminates abnormally, a core file should appear in the /tmp. The kernel.core_pattern sysctl controls exact location of core file. You can define the core file name with the following template whih can contain % specifiers which are substituted by the following values when a core file is created:
    • %% - A single % character
    • %p - PID of dumped process
    • %u - real UID of dumped process
    • %g - real GID of dumped process
    • %s - number of signal causing dump
    • %t - time of dump (seconds since 0:00h, 1 Jan 1970)
    • %h - hostname (same as ’nodename’ returned by uname(2))
    • %e - executable filename
Finally, enable debugging for all apps, enter (Redhat and friends specific):
# echo "DAEMON_COREFILE_LIMIT='unlimited'" >> /etc/sysconfig/init
Reload the settings in /etc/sysctl.conf by running the following command:
# sysctl -p

How Do I Enable Core Dumping For Specific Deamon?

To enable core dumping for specific deamons, add the following line in the /etc/sysconfig/daemon-file file. In this example, edit /etc/init.d/lighttped and add line as follows:
DAEMON_COREFILE_LIMIT='unlimited'
Please note that DAEMON_COREFILE_LIMIT is Redhat specific, for all other distro add configuration as follows:
ulimit -c unlimited >/dev/null 2>&1
echo /tmp/core-%e-%s-%u-%g-%p-%t > /proc/sys/kernel/core_pattern
Save and close the file. Restart / reload lighttpd:
# /etc/init.d/lighttpd restart
# su - lighttpd
$ ulimit -c

Sample outputs:
unlimited
Now, you can send core files to vendor or software writes.

How Do I Read Core Files?

You need use the gdb command as follows:
$ gdb /path/to/application /path/to/corefile
See the gdb command man page for more information.

strace command

System administrators, diagnosticians and trouble-shooters will find it invaluable for solving problems with programs for which the source is not readily available since they do not need to be recompiled in order to trace them. This is also useful to submit bug reports to open source developers. See how to use the strace command under Linux to debug the problems.

Recommended readings:

Stay tunned for gdb tutorial which will explains how to use generated core file to track down problem.

REFERENCES
http://www.cyberciti.biz/tips/linux-core-dumps.html

Thursday, September 2, 2010

HOWTO Design a fault-tolerant DHCP + DNS solution

— SkyHi @ Thursday, September 02, 2010
In this article, we will describe a design for a fault-tolerant (redundant) DHCP + DNS solution on Linux.
Design criteria:
  • Failure of one DHCP server should not prevent Clients from obtaining a valid IP address.
  • Failure of one DNS server should not prevent Clients from executing DNS queries.
  • The design should allow for Dynamic DNS updates.

Contents

[hide]

[edit] Design Overview

In the image below, you can see the design involving DNS Master / Slave as well as DHCP Primary / Secondary servers.
The sequence of events is as follows:
  1. The Client initiates a DORA (Discover, Offer, Request, Accept) communications sequence with the DHCP servers.
  2. Depending on the Client MAC address, one of the DHCP servers will respond with a DHCP_OFFER.
  3. The Client obtains an IP address as well as additional network settings.
  4. The DHCP server communicates the new lease to its partner.
  5. The DHCP server sends a DNS update to the DNS Master server.
  6. The DNS Slave server(s) are kept in sync using DNS Zone Transfers.

[edit] Fault-Tolerant DHCP Service

In this design, we will use the ISC DHCP daemon. One of the features includes a DHCP Primary / Secondary failover configuration, consisting of exactly 2 DHCP servers.
The DHCP servers share a pool of IP addresses, and keep the lease database for this pool in sync between them. If one DHCP server fails, the remaining server will continue to issue IP addresses. This guarantees uninterrupted service to the Clients.

[edit] Fault-Tolerant DNS Service

In this design, we will use the ISC DNS daemon. There are two ways to achieve fault tolerance:
  1. Master / Slave configuration
  2. Multi-Master configuration

[edit] DNS Master / Slave

DNS Master / Slave configuration is fairly straightforward. All zone data is kept on the DNS Master. The Master is configured to allow zone transfers from the DNS Slaves. Each DNS Slave performs zone transfers to obtain the most recent DNS information from the DNS Master.
Clients obtain a list of DNS servers through DHCP. If a DNS server fails, the Client will attempt to contact one of the remaining DNS servers. This guarantees uninterrupted DNS resolution service to the clients.
If the DNS Master fails, the situation becomes more severe. The DHCP servers communicate their updates only to the DNS Master server. In case of an outage, Dynamic DNS updates could be lost. One possible solution is the use of a DNS Multi-Master configuration.

[edit] DNS Multi-Master

DNS Multi-Master configuration is more complicated to configure and maintain than a Master / Slave configuration.
In case of a DNS server failure, both DNS Query and DNS Update services remain operational.

[edit] Design Decision

For our design, it is sufficient if DNS Queries from Clients remain operational. We will choose the DNS Master / Slave approach here as it is less complex, and still satisfies the design criteria.
how

[edit] Operational Issues

[edit] Managing combined Static and Dynamic DNS

Dynamic DNS is an all-or-nothing feature. If DDNS is enabled for a specific DNS zone, it should no longer be edited manually - your changes may be corrupted or overwritten. This often conflicts with existing systems management practices.
There are two approaches to avoid potential DNS corruption issues when managing a combined Static / Dynamic DNS environment:
Create a separate DNS zone for Dynamic DNS records
Static DNS records can still be managed in their own zone (example.local) as usual. Dynamic DNS records will be managed automatically in a separate DNS (sub-)domain, like "ddns.example.local".
Keep all DNS records in one Dynamic zone
All entries, both static and dynamic, are in the same DNS zone (example.local). Static entries should be managed using the "nsupdate" utility - this means that system management practices and tooling may need to be changed.
In this design, we will use a single Dynamic zone. Static entries will be managed using the "nsupdate" utility.




HOWTO Configure DHCP failover

HOWTO Configure DHCP failover

From Consultancy.EdVoncken.NET

Jump to: navigation, search
The ISC DHCP server currently supports failover using a maximum of 2 servers: primary and secondary. This is an active/active setup; a simple form of load balancing is used to spread the load across both servers.
In this example, we'll be setting up failover DHCP on two servers, 192.168.123.1 and 192.168.123.2. These servers also run DNS and NTP. Dynamic clients will get an address in the range 192.168.123.100-199. Static leases are defined for several networked devices.
Since the ISC DHCP server allows the use of "include-files" in the configuration, we will use them to help keep the configurations simple and in sync across servers.

Contents

[hide]

[edit] Installation

Install the following package, for example using yum:
dhcp
This example is based on version dhcp-3.0.5-18.el5.

[edit] Configuration

The configuration consists of several sections, each stored in a separate file to make maintenance easier.

[edit] Failover parameters

For the Primary, define the following failover parameters in /etc/dhcpd.conf_primary:
##########################
 # DHCP Failover, Primary #
 ##########################
 
 failover peer "example" {                   # Failover configuration
        primary;                             # I am the primary
        address 192.168.123.1;               # My IP address
        port 647;
        peer address 192.168.123.2;          # Peer's IP address
        peer port 647;
        max-response-delay 60;
        max-unacked-updates 10;
        mclt 3600;
        split 128;                           # Leave this at 128, only defined on Primary
        load balance max seconds 3;
 }
For the Secondary, define the following failover parameters in /etc/dhcpd.conf_secondary:
############################
 # DHCP Failover, Secondary #
 ############################
 
 failover peer "example" {                   # Fail over configuration
        secondary;                           # I am the secondary
        address 192.168.123.2;               # My ip address
        port 647;
        peer address 192.168.123.1;          # Peer's ip address
        peer port 647;
        max-response-delay 60;
        max-unacked-updates 10;
        mclt 3600;
        load balance max seconds 3;
 }

[edit] Subnet declaration

Write a subnet declaration using our failover pool in /etc/dhcpd.conf_subnet. This section is identical on Primary and Secondary:
subnet 192.168.123.0 netmask 255.255.255.0  # zone to issue addresses from
 {
       pool {
               failover peer "example";      # Pool for dhcp leases with failover bootp not allowed
               deny dynamic bootp clients;
               range 192.168.123.100 192.168.123.190;
       }
       pool {                                # Accomodate our bootp clients here; no replication and failover
               range 192.168.123.191 192.168.123.199;
       }
       allow unknown-clients;
 
       authoritative;
 
       option routers             192.168.123.254;
       option subnet-mask         255.255.255.0;
       option broadcast-address   192.168.123.255;
       option domain-name         "example.local.";
       option domain-name-servers 192.168.123.1, 192.168.123.2;
       option ntp-servers         192.168.123.1, 192.168.123.2;
       option netbios-node-type   8;
 
       default-lease-time         300;
       max-lease-time             600;
 
       filename                   "/pxelinux.0";
       next-server                192.168.123.1;
 }
Note: the manpage for dhcpd.conf(5) states that dynamic BOOTP leases are not compatible with failover.
Therefore, BOOTP should be disabled in in pools using failover.

[edit] Dynamic DNS

If you are configuring Dynamic DNS, write the settings in /etc/dhcpd.conf_subnet. This section is identical on Primary and Secondary:
ddns-update-style interim;
 ddns-updates on;
 ddns-domainname "example.local."; 
 ignore client-updates;
 
 # Forward zone for DNS updates
 zone example.local
 {
       primary 192.168.123.1;                # update the primary DNS
       key ddns-update;                      # key to use for the update
 }
 
 # Reverse zone for DNS updates
 zone 123.168.192.in-addr.arpa
 {
       primary 192.168.123.1;                # update the primary DNS
       key ddns-update;                      # key for update
 }
Note: for security reasons, DNS updates need to be "signed" using a public/private key mechanism.
The "key ddns-update" statement specifies that DHCP will use a key named "ddns-update" during update requests.
For more information on this key, please refer to HOWTO Configure Dynamic DNS.

[edit] Static leases

For more flexible IP address management, configure all devices to use DHCP and set up static leases for these devices.
In /etc/dhcpd.conf_static, create all static leases that you may need (outside of the DHCP/BOOTP range!). Again, this section is identical on Primary and Secondary:
# Axis Security Camera
 host cam-reception {
       hardware ethernet 00:40:12:c0:ff:ee;
       fixed-address 192.168.123.200;
 }
 
 # Axis Security Camera
 host cam-fireexit {
       hardware ethernet 00:40:fe:ed:fa:ce;
       fixed-address 192.168.123.201;
 }
 
 # Axis Security Camera
 host cam-frontdoor {
       hardware ethernet 00:40:de:ad:be:ef;
       fixed-address 192.168.123.202;
 }

[edit] Overall configuration

The configuration of the Primary and Secondary DHCP servers is mostly identical, except for the Failover parameters. By keeping the sub-configurations in sync across servers (perhaps using rsync), maintenance is reduced to a minimum.
The overall configuration file, /etc/dhcpd.conf, is only slightly different on Primary and Secondary.

[edit] Configuring /etc/dhcpd.conf on the Primary

# DHCP Server - Configuration file for Primary
 #
 # File $Id: dhcpd.conf,v 1.21 2009/07/09 16:26:57 root Exp root $
 
 # Global configuration
 set vendorclass = option vendor-class-identifier;
 
 # Dynamic DNS Updates
 include "/etc/ddns-update.dnskey";
 include "/etc/dhcpd.conf_ddns";
 
 # DHCP Failover, Primary
 include "/etc/dhcpd.conf_primary";
 
 # Subnet declaration
 include "/etc/dhcpd.conf_subnet";
 
 # Static IP addresses
 include "/etc/dhcpd.conf_static";
 
 # EOF

[edit] Configuring /etc/dhcpd.conf on the Secondary

# DHCP Server - Configuration file for Secondary
 #
 # File $Id: dhcpd.conf,v 1.9 2009/07/09 16:31:20 root Exp root $
 
 # Global configuration
 set vendorclass = option vendor-class-identifier;
 
 # Dynamic DNS Updates
 include "/etc/ddns-update.dnskey";
 include "/etc/dhcpd.conf_ddns";
 
 # DHCP Failover, Secondary
 include "/etc/dhcpd.conf_secondary";
 
 # Subnet declaration
 include "/etc/dhcpd.conf_subnet";
 
 # Static IP addresses
 include "/etc/dhcpd.conf_static";
 
 # EOF

[edit] Miscellaneous

[edit] SElinux considerations

By default, SELinux policy does not allow the BIND daemon (named) to write to files labeled with the name_zone_t type, which is used for master zone files. The zone files should be stored under /var/named/chroot/var/named/data or /var/named/chroot/var/named/dynamic.
# restorecon -R -v /var/named/chroot/var/named/data
 # restorecon -R -v /var/named/chroot/var/named/dynamic
This will reset the zone files to the named_cache_t type, hopefully solving the "SELinux is preventing named (named_t) "unlink"" error messages.

[edit] Firewall settings

Your firewall should allow inbound traffic on 69/UDP, 69/TCP and 647/TCP. Sample entries for /etc/sysconfig/iptables:
# DHCP server
 -A INPUT -p udp -m udp --dport 69 -j ACCEPT
 -A INPUT -p tcp -m tcp --dport 69 -j ACCEPT
 -A INPUT -m state --state NEW -m tcp -p tcp --dport 647 -j ACCEPT

[edit] Starting the service

On both DHCP Primary and Secondary, run the following commands as root:
# chkconfig dhcpd on
 # service dhcpd start

[edit] References







HOWTO Configure Dynamic DNS

HOWTO Configure Dynamic DNS

From Consultancy.EdVoncken.NET

Jump to: navigation, search
In this example, we will set up a DNS Master and DNS Slave server, on 192.168.123.1 and 192.168.123.2 respectively.
The configuration will also allow for Dynamic DNS updates from our DHCP servers.

Contents

[hide]

[edit] Installation

Install the following packages, for example using yum:
bind
 bind-chroot
 bind-utils
This example is based on bind-9.3.4-10.P1.el5_3.1.

[edit] Configuration

The configuration and data files for the chroot()-ed BIND DNS server can be found under /var/named/chroot/. Under /etc, you will find a symlink pointing to /var/named/chroot/etc/named.conf.

[edit] DNS Keys

For Dynamic DNS to work, the updates need to be "signed" using a transaction key. Since this is a symmetric key, it has to be shared between DNS and DHCP. It must be protected to prevent unauthorized changes being made to your DNS zones. The key has to be available on both DHCP servers. Generate the key as follows:
# cd /tmp
 # dnssec-keygen -a HMAC-MD5 -b 512 -n HOST ddns-update
These commands generate a set of .key and .private files in the current working directory. Move these files to a better name and location:
# mv Kddns-update.*.key /etc/ddns-update.key
 # cat /etc/ddns-update.key 
 ddns-update. IN KEY 512 3 157 K3EaOD3IysiC/D7lIXp+4hrYGDLyIq6la[...]9oE4kZ3O1ZFxKSMHfwG5YvUkYE7gxMHCmCg==
 
 # mv Kddns-update.*.private /etc/ddns-update.private
 # cat /etc/ddns-update.private 
 Private-key-format: v1.2
 Algorithm: 157 (HMAC_MD5)
 Key: K3EaOD3IysiC/D7lIXp+4hrYGDLyIq6la[...]9oE4kZ3O1ZFxKSMHfwG5YvUkYE7gxMHCmCg==
Note that the actual private and public keys are identical for HMAC-MD5. This is normal. The .key and .private files are needed by the nsupdate utility, later on.
We now need create a configuration file in a different format, for use by the DHCP and DNS servers- we will call this file /etc/ddns-update.dnskey. The syntax is identical to the /etc/rndc.key file. We need to set the key name and the key value properly:
# cat /etc/ddns-update.dnskey 
 key "ddns-update" {
       algorithm hmac-md5;
       secret "K3EaOD3IysiC/D7lIXp+4hrYGDLyIq6la[...]9oE4kZ3O1ZFxKSMHfwG5YvUkYE7gxMHCmCg==";
 };
Make sure it has the proper ownership and permissions:
# ls -l /etc/ddns-update.dnskey
 -rw-r----- 1 root named 145 Jul  9 12:25 ddns-update.dnskey
On the Primary DHCP / Master DNS server, the key needs to be available both as /etc/ddns-update.dnskey (for DHCP) and /var/named/chroot/etc/ddns-update.dnskey (for DNS). Creating a symlink will not work due to the SElinux policy; you will have to copy the file instead, so each copy has its own SElinux context:
# cp /etc/ddns-update.dnskey /var/named/chroot/etc/
 # ls -lZ /etc/ddns-update.dnskey /var/named/chroot/etc/ddns-update.dnskey 
 -rw-r-----  root root  root:object_r:etc_t              /etc/ddns-update.dnskey
 -rw-r-----  root named root:object_r:named_conf_t       /var/named/chroot/etc/ddns-update.dnskey

[edit] DNS Master configuration

On the Master, we will define all zones that we are authoritative for. We will also allow DNS updates to these zones from our DHCP servers.
# ISC BIND Configuration File
 #
 # Purpose:
 #   Configure BIND as caching/forwarding nameserver with authority
 #   for local networks as well as support for Dynamic DNS Updates
 #
 # File $Id: named.conf,v 1.4 2009/07/07 12:59:12 root Exp root $
 
 options {
       directory "/etc";
       pid-file "/var/run/named/named.pid";
       forwarders {
               // Put your ISP's DNS servers here
               66.159.123.200;
               66.159.123.201;
       };
       allow-query { localhost; localnets; };
 };
 
 # Key used by DHCP servers for Dynamic DNS Updates
 include "/etc/ddns-update.dnskey";
 
 zone "example.local" {
       type master;
       file "/var/named/data/example.local.zone";
       allow-transfer { 192.168.123.2; };
       allow-update { key "ddns-update"; };
 };
 
 zone "123.168.192.in-addr.arpa" {
       type master;
       file "/var/named/data/192.168.123.zone";
       allow-transfer { 192.168.123.2; };
       allow-update { key "ddns-update"; };
 };
 
 # EOF
SELinux Note: On the DNS Master, use the "data" sub-directory to store zone files.
Otherwise, you will see errors while trying to create journal files on the Master.

[edit] DNS Slave configuration

You can have multiple DNS Slave servers. Each will perform a zone transfer regularly, keeping the data in sync.
Dynamic DNS updates, originating from our DHCP servers are sent to the DNS Master only.
# ISC BIND Configuration File
 #
 # Purpose:
 #   Configure BIND as caching/forwarding slave nameserver
 #
 # File $Id: named.conf,v 1.4 2009/07/08 02:02:19 root Exp $
 
 options {
       directory "/etc";
       pid-file "/var/run/named/named.pid";
       forwarders {
               // Put your ISP's DNS servers here
               66.159.123.200;
               66.159.123.201;
       };
       allow-query { localhost; localnets; };
       allow-notify { 192.168.123.2; };
 };
 
 # Dynamic DNS Updates are only sent to the Primary DNS
 
 zone "example.com" {
       type slave;
       masters { 192.168.123.1; };
       file "/var/named/slaves/example.com.zone";
 };
 
 zone "123.168.192.in-addr.arpa" {
       type slave;
       masters { 192.168.123.1; };
       file "/var/named/slaves/192.168.123.zone";
 };
The "allow-notify" option prevents BIND from generating error messages as it apparently tries to notify itself of updates. Go figure ;-)
SELinux Note: On the DNS Slave, use the "slaves" sub-directory to store data from the DNS Master.
Otherwise, you will get a "permission denied" error on the Slave while trying to transfer the zones from the Master.

[edit] DNS Zone files

On the DNS Master, we create a minimal set of zone files (forward and reverse zones). Entries will be managed either by DHCP or nsupdate.
/var/named/data/example.local.zone:
 ; DO NOT EDIT MANUALLY - use the "nsupdate" utility to prevent data loss
 ;
 $ORIGIN example.local.
 $TTL 86400 ; 1 day
 @  IN SOA ns1.example.local. hostmaster.example.local. (
     2009074711 ; serial
     7200       ; refresh (2 hours)
     300        ; retry (5 minutes)
     604800     ; expire (1 week)
     60         ; minimum (1 minute)
     )
   IN NS ns1.example.local.
   IN NS ns2.example.local.
 ns1  IN A 192.168.123.1
 ns2  IN A 192.168.123.2
/var/named/data/192.168.123.zone:
 ; DO NOT EDIT MANUALLY - use the "nsupdate" utility to prevent data loss
 ;
 $ORIGIN 123.168.192.in-addr.arpa.
 $TTL 86400 ; 1 day
 @  IN SOA ns1.example.local. hostmaster.example.local. (
     2009074711 ; serial
     7200       ; refresh (2 hours)
     300        ; retry (5 minutes)
     604800     ; expire (1 week)
     60         ; minimum (1 minute)
     )
   IN NS ns1.example.local.
   IN NS ns2.example.local.
 1  IN PTR ns1.example.local.
 2  IN PTR ns2.example.local.

[edit] Miscellaneous

[edit] Client configuration

On RHEL/CentOS/Fedora clients, you should edit /etc/sysconfig/network-scripts/ifcfg-eth0 and set the DHCP_HOSTNAME variable to the short hostname of your machine. The client will now send its hostname to the DHCP server during IP address negotiation. The DHCP_HOSTNAME is used for updating Dynamic DNS. Sample:
# Sample Network Device
 DEVICE=eth0
 HWADDR=00:16:de:ad:be:ef
 ONBOOT=yes
 BOOTPROTO=dhcp
 DHCP_HOSTNAME=demo01

[edit] Using nsupdate to add or remove DNS entries

[edit] Adding a host (A and PTR records)

# nsupdate -k /etc/ddns-update.key
 > update add gateway.example.local 38400 A 192.168.123.254
 > 
 > update add 254.123.168.192.in-addr.arpa. 38400 PTR gateway.example.local.
 >
 > quit
Note: The empty line is necessary, it sends the update to DNS. Since we are adding records to two different zones, we need to send two separate updates.

[edit] Deleting a host (A and PTR records)

# nsupdate -k /etc/ddns-update.key 
 > update delete gateway.example.local IN A 192.168.123.254
 > 
 > update delete 254.123.168.192.in-addr.arpa PTR gateway.example.local.
 > 
 > quit

[edit] Adding a mail-host (MX records)

The domain "example.local" wishes to use "mail.example.local" as their primary mail host.
We first need to add the standard A and PTR records for the mailhost (TTL 86400 seconds), followed by the MX record for the domain:
# nsupdate -k /etc/ddns-update.key 
 > update add mail.example.nl 86400 IN A 192.168.123.25
 > 
 > update add 25.123.168.192.in-addr.arpa. 86400 PTR mail.example.local.
 > 
 > update add example.local 86400 MX 10 mail.example.local.
 > 
 > quit
Note: The mailhost should of course be accessible from the Internet and use a routable IP address instead of an RFC1918 address.
Verify the results using 'dig':
# dig example.local MX
 
 ; <<>> DiG 9.3.4-P1 <<>> example.local MX
 ;; global options:  printcmd
 ;; Got answer:
 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15733
 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3
 
 ;; QUESTION SECTION:
 ;example.local.   IN MX
 
 ;; ANSWER SECTION:
 example.local.  86400 IN MX 10 mail.example.local.
 
 ;; AUTHORITY SECTION:
 example.local.  86400 IN NS ns2.example.local.
 example.local.  86400 IN NS ns1.example.local.
 
 ;; ADDITIONAL SECTION:
 mail.example.local. 86400 IN A 192.168.123.25
 ns1.example.local. 86400 IN A 192.168.123.1
 ns2.example.local. 86400 IN A 192.168.123.2
 
 ;; Query time: 1 msec
 ;; SERVER: 127.0.0.1#53(127.0.0.1)
 ;; WHEN: Fri Jul 31 11:34:29 2009
 ;; MSG SIZE  rcvd: 134

[edit] Deleting a mail-host (MX records)

If we wish to remove the mail-host, just delete the MX, A and PTR records:
# nsupdate -k /etc/ddns-update.key 
 > update delete example.local MX 10 mail.example.local.
 > 
 > update delete mail.example.local IN A 192.168.123.25
 > 
 > update delete 25.123.168.192.in-addr.arpa PTR mail.example.local.
 > 
 > quit
Note: Mail may continue to be delivered to the old mailhost until the TTL expires!

[edit] Debugging

During development, you may want to enable some extra logging in /etc/named.conf:
logging {
       channel update_debug {
               file "/var/named/data/named-update.log";
               severity  debug 3;
               print-category yes;
               print-severity yes;
               print-time     yes;
       };
 
       channel security_info    {
               file "/var/named/data/named-auth.log";
               severity  debug 3;
               print-category yes;
               print-severity yes;
               print-time     yes;
       };
 
       category update { update_debug; };
       category security { security_info; };
 };

[edit] Starting the service

On both Master and Slave DNS, start the BIND nameserver:
# chkconfig named on
 # service named start
HOWTO Manage Dynamic DNS with nsupdate

HOWTO Manage Dynamic DNS with nsupdate

From Consultancy.EdVoncken.NET

Jump to: navigation, search

Contents

[hide]

[edit] A and PTR records

[edit] Adding a host (A and PTR records)

# nsupdate -k /etc/ddns-update.key > update add gateway.example.local 38400 A 192.168.123.254 > > update add 254.123.168.192.in-addr.arpa. 38400 PTR gateway.example.local. > > quit Note: The empty line is necessary, it sends the update to DNS. Since we are adding records to two different zones, we need to send two separate updates.

[edit] Deleting a host (A and PTR records)

# nsupdate -k /etc/ddns-update.key > update delete gateway.example.local IN A 192.168.123.254 > > update delete 254.123.168.192.in-addr.arpa PTR gateway.example.local. > > quit

[edit] MX records

[edit] Adding a mail-host

The domain "example.local" wishes to use "mail.example.local" as their primary mail host.
We first need to add the standard A and PTR records for the mailhost (TTL 86400 seconds), followed by the MX record for the domain:
# nsupdate -k /etc/ddns-update.key > update add mail.example.nl 86400 IN A 192.168.123.25 > > update add 25.123.168.192.in-addr.arpa. 86400 PTR mail.example.local. > > update add example.local 86400 MX 10 mail.example.local. > > quit Note: The mailhost should of course be accessible from the Internet and use a routable IP address instead of an RFC1918 address.
Verify the results using 'dig':
# dig example.local MX  ; <<>> DiG 9.3.4-P1 <<>> example.local MX  ;; global options: printcmd  ;; Got answer:  ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15733  ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3  ;; QUESTION SECTION:  ;example.local. IN MX  ;; ANSWER SECTION: example.local. 86400 IN MX 10 mail.example.local.  ;; AUTHORITY SECTION: example.local. 86400 IN NS ns2.example.local. example.local. 86400 IN NS ns1.example.local.  ;; ADDITIONAL SECTION: mail.example.local. 86400 IN A 192.168.123.25 ns1.example.local. 86400 IN A 192.168.123.1 ns2.example.local. 86400 IN A 192.168.123.2  ;; Query time: 1 msec  ;; SERVER: 127.0.0.1#53(127.0.0.1)  ;; WHEN: Fri Jul 31 11:34:29 2009  ;; MSG SIZE rcvd: 134

[edit] Deleting a mail-host

If we wish to remove the mail-host, just delete the MX, A and PTR records:
# nsupdate -k /etc/ddns-update.key > update delete example.local MX 10 mail.example.local. > > update delete mail.example.local IN A 192.168.123.25 > > update delete 25.123.168.192.in-addr.arpa PTR mail.example.local. > > quit Note: Mail may continue to be delivered to the old mailhost until the TTL expires!

[edit] Service (SRV) records

[edit] Adding SRV records for your IPA Server

After installing the IPA Server ("apollo" in this example), you should add some service-records to DNS for IPA discovery. The installer leaves a sample DNS zone file in /tmp. This is how I added the relevant records using nsupdate:
# nsupdate -k /etc/ddns-update.key > update add _ldap._tcp.example.local. 86400 IN SRV 0 100 389 apollo > > update add _kerberos._tcp.example.local. 86400 IN SRV 0 100 88 apollo > > update add _kerberos._udp.example.local. 86400 IN SRV 0 100 88 apollo > > update add _kerberos-master._tcp.example.local. 86400 IN SRV 0 100 88 apollo > > update add _kerberos-master._udp.example.local. 86400 IN SRV 0 100 88 apollo > > update add _kpasswd._tcp.example.local. 86400 IN SRV 0 100 464 apollo > > update add _kpasswd._udp.example.local. 86400 IN SRV 0 100 464 apollo > > quit

[edit] Navigation

[edit] References