Tuesday, February 9, 2010

Apache:How to install ANT tool under Linux

In this tutorial I will show you how you can install ant tool on your linux box. This installing ant in linux is based on the practical work.
Step 1:
Download ant from http://ant.apache.org/bindownload.cgi. I have downloaded apache-ant-1.7.1-bin.zip for this tutorial.

Step 2:

Login to your Linux box and create a directory "ant" under /usr/local.

[root@RoseIndiaLinux local]# mkdir ant
[root@RoseIndiaLinux local]# cd ant
[root@RoseIndiaLinux ant]# pwd
/usr/local/ant
[root@RoseIndiaLinux ant]#

Step 3:

Copy apache-ant-1.7.1-bin.zip onto your Linux box in /usr/local/ant directory.

Step 4:

Extract the zip file apache-ant-1.7.1-bin.zip) using unzip command.

[root@RoseIndiaLinux ant]# unzip apache-ant-1.7.1-bin.zip

above command will extract the content of the zip file and will create a new directory apache-ant-1.7.1

Step 5:

Set path in the .bash_profile

Open the file /root/.bash_profile and add the following codes:

export ANT_HOME=/usr/local/ant/apache-ant-1.7.1
export JAVA_HOME=/opt/java/jdk1.6.0_06
export PATH=${PATH}:${ANT_HOME}/bin

Step 6:

Logout and login again to your Linux box. Now ant available on your box.

Port Redirection: Howto?

You can easily redirect incoming traffic by inserting rules into PREROUTING chain of the nat table. You can set destination port using the REDIRECT target.
Syntax

The syntax is as follows to redirect tcp $srcPortNumber port to $dstPortNumber:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $srcPortNumber -j REDIRECT --to-port $dstPortNumbe

The syntax is as follows to redirect udp $srcPortNumber port to $dstPortNumber:

iptables -t nat -A PREROUTING -i eth0 -p udp --dport $srcPortNumber -j REDIRECT --to-port $dstPortNumbe

Replace eth0 with your actual interface name. The following syntax match for source and destination ips:

iptables -t nat -I PREROUTING --src $SRC_IP_MASK --dst $DST_IP -p tcp --dport $portNumber -j REDIRECT --to-ports $rediectPort

Examples:

The following example redirects TCP port 25 to port 2525:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 25 -j REDIRECT --to-port 2525

In this example all incoming traffic on port 80 redirect to port 8123

iptables -t nat -I PREROUTING --src 0/0 --dst 192.168.1.5 -p tcp --dport 80 -j REDIRECT --to-ports 8123

Quoting from the iptables man page:

This target is only valid in the nat table, in the PREROUTING and OUTPUT
chains, and user-defined chains which are only called from those
chains. It redirects the packet to the machine itself by changing the
destination IP to the primary address of the incoming interface
(locally-generated packets are mapped to the 127.0.0.1 address). It
takes one option:

--to-ports port[-port]
This specifies a destination port or range of ports to use:
without this, the destination port is never altered. This is
only valid if the rule also specifies -p tcp or -p udp.

The OUTPUT chain example:

iptables -t nat -I OUTPUT --src 0/0 --dst 192.168.1.5 -p tcp --dport 80 -j REDIRECT --to-ports 8123

How Do I View NAT Rules?

Type the following command:

iptables -t nat -L -n -v

How Do I Save NAT Redirect Rules?

Type the following command:

iptables-save

Connecting RHEL to Active Directory Server through Winbind

You have a RHEL system and you want to authenticate it against your active directory. The good news is that Red Hat has made it easy for you to do this. The bad news is that they only get the most basic structure working for you.

Here I will show you how to get WinBind authentication working using Authconfig, and how make it a little more seamless than this utility leaves it off.

It should be noted that while this works perfectly well, it is really not the best way to authenticate users against a UNIX host. Given the option, having your users in OpenLDAP and PAM authenticating them against that would be a much better option. However, we don’t live in a perfect world, and sometimes we just have to make things work.

Let’s start by using authconfig to join your machine to the domain. This should all be done as the root user.

# authconfig

* Select “Use Winbind” and Use “Winbind Authentication”. Remember to leave “Cache Information”, “Use MD5 Passwords” and “Use Shadow Passwords” selected.
* Select “Next”
* Under “Security Model” select “ads”
* “Domains:” examplead (substatute with the name of your Active Directory)
* “Domain Controllers:” adserver.domain.com (Again, substitute with the name of your Active Directory server)
* “ADS Realm:” ADSERVER.DOMAIN.COM
* “Template Shell:” /bin/bash
* Select “Join Domain”
* Select “OK”

Now your machine should be be on the domain. Test it to make sure you can see your AD users:

# wbinfo -u

You should see your users in the list.

The only problem is that to do anything with them, you have to express their user name in that annoying way Windows likes you to. Something like this:

“EXAMPLEAD\\username”

Not very usefull. To get around this, simply edit “/etc/samba/smb.conf” and change this line:

winbind use default domain = no

to this:

winbind use default domain = yes

You should now be able to express AD usernames without the domain nonsense before it. Try it:

# finger username
Login: username Name: Username
Directory: /home/EXAMPLEAD/username Shell: /bin/bash
Never logged in.
No mail.
No Plan.

Finally check your “/etc/nsswhich.conf” file to make sure RHEL knows to use WinBind. Authconfig should have set this up for you, and it should have lines that look like this:

passwd: files winbind
shadow: files winbind
group: files winbind

Note:Follow these instructions to have your users directories automatically created….

http://kbase.redhat.com/faq/FAQ_43_5367.shtm

Tuesday, February 2, 2010

Linux: How to create a new Partition on Linux?

Linux Partitioning follows a simple step which can be executed post installation.Below mentioned steps creates a new partition called /u02 and needed to be mounted therein.

Hope it helps understandign clear cut steps to linux partitioning:

[root@ajeet ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 11G 479M 9.1G 5% /
/dev/sda7 4.9G 139M 4.5G 3% /home
/dev/sda6 4.9G 230M 4.4G 5% /var
/dev/sda5 7.6G 2.4G 4.9G 33% /usr
/dev/sda2 11G 155M 9.4G 2% /opt
/dev/sda1 99M 24M 71M 25% /boot
tmpfs 1010M 0 1010M 0% /dev/shm
/dev/sda9 9.2G 150M 8.6G 2% /u01

[root@ajeet ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1364 10851907+ 83 Linux
/dev/sda3 1365 2715 10851907+ 83 Linux
/dev/sda4 2716 9729 56339955 5 Extended
/dev/sda5 2716 3738 8217216 83 Linux
/dev/sda6 3739 4388 5221093+ 83 Linux
/dev/sda7 4389 5038 5221093+ 83 Linux
/dev/sda8 5039 5560 4192933+ 82 Linux swap / Solaris
/dev/sda9 5561 6777 9775521 83 Linux

Command (m for help): n
First cylinder (6778-9729, default 6778):
Using default value 6778
Last cylinder or +size or +sizeM or +sizeK (6778-9729, default 9729): +10000M

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1364 10851907+ 83 Linux
/dev/sda3 1365 2715 10851907+ 83 Linux
/dev/sda4 2716 9729 56339955 5 Extended
/dev/sda5 2716 3738 8217216 83 Linux
/dev/sda6 3739 4388 5221093+ 83 Linux
/dev/sda7 4389 5038 5221093+ 83 Linux
/dev/sda8 5039 5560 4192933+ 82 Linux swap / Solaris
/dev/sda9 5561 6777 9775521 83 Linux
/dev/sda10 6778 7994 9775521 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

[root@ajeet ~]# partprobe

[root@ajeet ~]# mkfs.ext3 /dev/sda10
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1224000 inodes, 2443880 blocks
122194 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2503999488
75 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@ajeet ~]# e2label /dev/sda10 /u02

[root@ajeet ~]# vi /etc/fstab

[root@ajeet ~]# mkdir /u02

[root@ajeet ~]# mount -a

[root@ajeet ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 11G 479M 9.1G 5% /
/dev/sda7 4.9G 139M 4.5G 3% /home
/dev/sda6 4.9G 230M 4.4G 5% /var
/dev/sda5 7.6G 2.4G 4.9G 33% /usr
/dev/sda2 11G 155M 9.4G 2% /opt
/dev/sda1 99M 24M 71M 25% /boot
tmpfs 1010M 0 1010M 0% /dev/shm
/dev/sda9 9.2G 150M 8.6G 2% /u01
/dev/sda10 9.2G 150M 8.6G 2% /u02

[root@ajeet ~]# mount
/dev/sda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda7 on /home type ext3 (rw)
/dev/sda6 on /var type ext3 (rw)
/dev/sda5 on /usr type ext3 (rw)
/dev/sda2 on /opt type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sda9 on /u01 type ext3 (rw)
/dev/sda10 on /u02 type ext3 (rw)

[root@ajeet ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 11G 479M 9.1G 5% /
/dev/sda7 4.9G 139M 4.5G 3% /home
/dev/sda6 4.9G 230M 4.4G 5% /var
/dev/sda5 7.6G 2.4G 4.9G 33% /usr
/dev/sda2 11G 155M 9.4G 2% /opt
/dev/sda1 99M 24M 71M 25% /boot
tmpfs 1010M 0 1010M 0% /dev/shm
/dev/sda9 9.2G 150M 8.6G 2% /u01
/dev/sda10 9.2G 150M 8.6G 2% /u02
[root@ajeet ~]#

Saturday, January 30, 2010

RPM: Want to know the overall RPMs in your Linux Box ? Try Your Hands on !!

I was searching for a command which could provide me the overall RPMs in my CentOS 5.4 box.I did tried it several times but usually forget to collect it.
So this command is for all you guys (and me, of course) who may want to know the size of all the installed packages and sort them. Here we go:

Code:

$ rpm -qa --qf '%11{SIZE} %{NAME}\n' | sort -k1n

There you see..Sea of RPMs.

Happy LinuXing !!!

389-DS: Kickstarting CentOS with 389-DS Complete Setup

The Contents have been revised and redirected to new website.

Saturday, December 26, 2009

Apache:Start Apache as service in Linux (Fedora)

The Apache HTTP server is installed by default in all Linux distributions and it is configured to run as service. I usually prefer to install Apache from source instead of using the default one. After installing Apache I want to run that instance as service so that it can be restarted automatically whenever machine is rebooted. This can be achieved easily by modifying /etc/rc.d/init.d/httpd file, which is configured to run the Apache installed with OS.

Comment the following section, though it is not required but I prefer to keep all configuration at one place



if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
Modify the following lines-

apachectl=/usr/sbin/apachectl
httpd=${HTTPD-/usr/sbin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
to point towards your Apache installation

apachectl=/opt/apps/httpd-2.2.14/bin/apachectl
httpd=${HTTPD-/opt/apps/httpd-2.2.14/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/opt/apps/httpd-2.2.14/logs/httpd.pid}

Now your custom Apache instance will be started by OS instead of the default one.