Category: Linux


It’s simple trick, some time it may helps lot,

Please note down

create a news called test

# cp test test_`date +%d%m%y`

Then filename will be test_290512.

Kickstart With PXEboot

I have used Centos 5.5, please read the below steps (I have used)
Requirements

Centos 5.5 Media
Creating Kickstart file(ks.cfg)
Setup NFS server
Installing PXE boot loader
Setup TFTp Server
Setup DHCP server

1. Copy the Centos DVD media files to my NFS server.

#cp -fr /mnt/media /share/centos5.5
#mkisofs –J –r –T –o RHEL-disc1.iso /share/centos5.5

Create a customized kickstart configuration file by using “ Applications -> Systems Tools -> Kickstart”. Save this file to /share/centos5.5 directory.

#vi /share/centos5.5/ks.cfg

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth –useshadow –enablemd5
key –skip
# System bootloader configuration
bootloader –location=mbr
# Partition clearing information
clearpart –all –initlabel
# Use graphical install
graphical
# Firewall configuration
firewall –disabled
# Run the Setup Agent on first boot
firstboot –disable
# System keyboard
keyboard us
# System language
lang en_US
# Installation logging level
logging –level=info
# Use NFS installation media
nfs –server=151.8.99.21 –dir=/data/install/ISO
# Network information
network –bootproto=dhcp –device=eth0 –onboot=on
#Root password
rootpw admin123

# SELinux configuration
selinux –disabled
# System timezone
timezone Asia/Calcutta
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig –defaultdesktop=GNOME –depth=8 –resolution=800×600
# Disk partitioning information
part /boot –bytes-per-inode=4096 –fstype=”ext3″ –size=100
part / –bytes-per-inode=4096 –fstype=”ext3″ –size=10000
part swap –bytes-per-inode=4096 –fstype=”swap” –size=512
%packages
@GNOME Desktop Environment
@editors
@graphics
@Text-based Internet
@Development Tools
@FTP Server
@Administration Tools
@base
@java

3. Setup the NFS server
vim /etc/exports
/share/centos5.5 *(ro)

#/etc/init.d/nfs restart
#/etc/init.d/portmap restart


4. TFTP Configuration

yum install syslinux
cp /usr/lib/syslinux/pxelinux.0 /tftpboot

Create the pxelinux.cfg directory in /tftpboot and edit the default file:

# You can have multiple Kickstart file having multiple versions
default linux
label linux
kernel vmlinuz
append ksdevice=eth0 load_ramdisk=1 initrd=initrd.img network ks=nfs:192.168.1.100:/share/kickstart/test64-ks

Configure the TFTP server by editing /etc/xinetd.conf/tftp file:

#service xinetd restart

5. DHCP Configuration

/etc/dhcpd.conf

i added the following block

host mysys {
hardware ethernet 00:ab:cd:df:11:12;
fixed-address 192.168.1.123;
next-server 192.168.1.100;
filename “pxelinux.0″;
}
#service dhcpd restart

6. Client Side

Please boot via network card (it should support network booting), It will fetch the IP from my DHCP server, start the installation.. :-)

Disable directory browsing using .htaccess:-
Open your .htacces file

Look for Options Indexes
If Options Indexes exists modify it to Options -Indexes or else add Options -Indexes as a new line
The directory browsing feature should be disable by now

Disable directory browsing using httpd.conf:-

Open your httpd.conf, normally it’s located at /usr/local/apache/conf or /etc/httpd.conf
Go to your own Virtual Host settings and look for “Options Indexes”
Change the Indexes to -Indexes if Option Indexes exists or else add the Options -Indexes line
Restart your apache web server.

The directory browsing feature should be disable by now

Disable directory browsing in CPanel Share Hosting enviroment:-

Login to your CPanel
Click on Index Manager
Directory will be list down. Click on the directory name which you want to disable the directory browsing
Select No Index and click Save

The directory browsing feature should be disable by now
Once you disable directory browsing, visitor will not able to browse your directory by accessing the directory directly (if there is no index.html file).
This will protect your files from exposing to the public.

Finally today I had implemented NIC bounding (bind both NIC so that it works as a single device). We have two Dell servers that need setup with Intel Dual Gig NIC. My idea is to improve performance by pumping out more data from both NIC without using any other method.

This box act as heavy duty ftp server. Each night I need to transfer over 200GB data from this box to another box. Therefore, the network would be setup is two servers on a switch using dual network cards. I am using Red Hat enterprise Linux version 4.0.

Linux allows binding multiple network interfaces into a single channel/NIC using special kernel module called bonding. According to official bonding documentation, “The Linux bonding driver provides a method for aggregating multiple network interfaces into a single logical “bonded” interface. The behavior of the bonded interfaces depends upon the mode; generally speaking, modes provide either hot standby or load balancing services. Additionally, link integrity monitoring may be performed.”

Setting up bounding is easy with RHEL v4.0.

Step #1: Create a bond0 configuration file

Red Hat Linux stores network configuration in /etc/sysconfig/network-scripts/ directory. First, you need to create bond0 config file:

# vi /etc/sysconfig/network-scripts/ifcfg-bond0
Append following lines to it:
DEVICE=bond0
IPADDR=192.168.1.20
NETWORK=192.168.1.0
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
Replace above IP address with your actual IP address. Save file and exit to shell prompt.

Step #2: Modify eth0 and eth1 config files:

Open both configuration using vi text editor and make sure file read as follows for eth0 interface
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Modify/append directive as follows:
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

Open eth1 configuration file using vi text editor:

# vi /etc/sysconfig/network-scripts/ifcfg-eth1
Make sure file read as follows for eth1 interface:
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
Save file and exit to shell prompt.

Step # 3: Load bond driver/module

Make sure bonding module is loaded when the channel-bonding interface (bond0) is brought up. You need to modify kernel modules configuration file:
# vi /etc/modprobe.conf
Append following two lines:
alias bond0 bonding
options bond0 mode=balance-alb miimon=100
Save file and exit to shell prompt. You can learn more about all bounding options in kernel source documentation file (click here to read file online).

Step # 4: Test configuration

First, load the bonding module:

# modprobe bonding
Restart networking service in order to bring up bond0 interface:
# service network restart

Verify everything is working:
# less /proc/net/bonding/bond0
Output:

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c6:be:59

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c6:be:63

List all interfaces:

# ifconfig
Output:
bond0 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:2804 errors:0 dropped:0 overruns:0 frame:0
TX packets:1879 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:250825 (244.9 KiB) TX bytes:244683 (238.9 KiB)

eth0 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec6:be59/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:2809 errors:0 dropped:0 overruns:0 frame:0
TX packets:1390 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:251161 (245.2 KiB) TX bytes:180289 (176.0 KiB)
Interrupt:11 Base address:0×1400

eth1 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec6:be59/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:502 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:258 (258.0 b) TX bytes:66516 (64.9 KiB)
Interrupt:10 Base address:0×1480

Now you have bond multiple network interfaces into a single channel (NIC).

Courtesy : http://www.cyberciti.biz

It is important to know traffic usage of your client if you’re a Linux network administrator. You can monitor your client in text mode, graphic mode or html exported like mrtg, cacti or bandwidthd and one of my favorite bandwidth monitor is Bandwidthd.


You don’t need any database or snmp connection to monitor all of your client on bandwidthd, all you need just libcaplibpnglibgd and apache installed on your Linux system. And other good news is bandwidthd monitor all of your connected client per IP and per connection protocol.

Installing Bandwidthd

Prepare your Linux and download bandwidthd for Linux here. Next extract bandwidth using tar -zxvf command.


Goto extracted directory and type ./configure && make install to install bandwidth to your system.

Configuring Bandwidthd

By default all installed bandwidthd files placed on /usr/local/bandwidthd/folder. Now goto bandwidthd installed directory and CD to etc, you’ll find bandwidthd config file there. Open bandwidthd.conf using your favorite text editor like vi or nano and start edit bandwidthd config file suit your network.


Save your config and start bandwidthd using/usr/local/bandwidthd/bandwidthd. Put that command to your /etc/rc.localfile so bandwidthd can start on every time Linux boot.

Configuring Apache

You will can’t see your graphic report until you set/usr/local/bandwidthd/htdocs/ folder to set as apache virtual directory. Add below line to your apache config file.

Alias /bandwidthd “/usr/local/bandwidthd/htdocs”
<Directory “/usr/local/bandwidthd/htdocs”>
Order Allow,Deny
Allow from All
</Directory>
Save your work and restart apache. Next open your browser and point to http://yourlinuxserver/bandwidth.

Happy trying and good luck.

Courtesy:  http://infodotnet.blogspot.com


If you want to deploy many machines, then it is a pain to go from machine to machine with 4 CDs. Like RIS (Remote Installation Service) in Windows, Fedora also offers you a similar remote installation facility via PXE LAN booting. For this, you will require a DHCP server, Apache and TFTP server running on Fedora.

Firstly, install Fedora completely. Then, on that machine, make a folder named  /Fedora on root and copy all the contents of the Fedora CDs in this folder. Remember that you are mounting the CDs and copying the contents and not just copying the ISOs. While copying the files from the CDs, you will be asked for permission to overwrite few files and folders.

Once you have created a copy of the CDs on the machine, you have to create a kick start file, which has answers to the questions asked during the installation process.

To make this file, launch ‘kickstart’ from Start>Systems, this will open a GUI Kickstart configuration interface.

Here, you can set pre-installation settings such as keyboard type, language, time zone, mouse, display, root password, etc. Fill all the entries according to your setup requirements and save the file. It saves a file with name ks.cfg.

Copy this file to the location where you have copied the Fedora2006 files from the CD.

Host installer
In order to remotely install Fedora via HTTP, you have to configure apache server to host the installer. To do this, launch Start>system>HTTP. This will open an interface to configure the apache web server. Here, select the main tab and give the IP address of the same machine, where you are hosting the apache server. Next, select the ‘virtual host’ tab and select add new host and double click the new virtual host you have created. This will open its properties dialog. Here, under basic setup set the ‘document root directory’ to the location where you copied the Fedora CDs.

In our case it is /fedora. Now, from the same properties window, click on the performance tab and add the directory of your Fedora installer that you have copied above. Once you are through with this, save the settings by clicking the Ok button. After this, start apache server by issuing this command.

#service httpd start

Now, open a web browser and check that the web server is working properly. Make sure it displays the directory structure of the Fedora installer folder on the web page.

Configuring TFTP Server
TFTP stands for Trivial File Transfer Protocol, a simpler form of the File Transfer Protocol (FTP).

The next step is to configure TFTP server on your installer server in such a way that it can remotely boot another PC over a network. In order to do this, open a terminal and issue the following commands.

# cp /pcqlinux/isolinux/* /tftpboot/linux-install/
# cp /tftpboot/linux-install/isolinux.cfg /tftpboot/linux-install/pxelinux.cfg/default

The above commands will copy all the boot files from the folder where you have dumped the entire Fedora CDs to the TFTP server.

Now open /tftpboot/ linux-install/pxelinux.cfg /default file in a text editor and change the following entries as follows

label linux
kernel vmlinuz
append initrd=initrd.img ramdisk_size=8192 s=http://192.168.3.1/pcqlinux/ks.cfg
label text
kernel vmlinuz
append initrd=initrd.img text ramdisk_size=8192 ks=http://192.168.3.1/pcqlinux/ks.cfg

(Here 192.168.3.1 is the IP address of the hosting server, where you have hosted the Fedora installer, you should change it according to your settings).

After this you have to enable the TFTP server so that the TFTP server

automatically gets started on booting the Fedora server. For doing this, run ‘setup’ command from the terminal. It will open a CLI interface, here select ‘Services’ and from the list select ‘tftp’ by pressing space bar key and click the Ok button to save the settings .

Configure DHCP server

Now, you have to configure the DHCP server on your installation server, so that the diskless clients can get IP addresses from the RIS server and remotely boot and start the Fedora installer. To do this open the /etc/dhcpd.conf file and add the following lines as shown below.

ddns-update-style
none;
default-lease-time
21600;
max-lease-time
21600;
option subnet-mask
255.255.255.0;
option broadcast-address
192.168.3.255;
option domain-name-servers
192.168.3.78; #<– RIS Server IP
option domain-name
“ris.pcquest.local”;
# <–domain name
option option-128 code 128 = string;
option option-129 code 129 = text;
subnet  192.168.3.0 netmask 255.255.255.0 {
range dynamic-bootp
192.168.3.10 192.168.3.253; # <– DHCP IP Ranage
filename
“/linux-install/pxelinux.0″;  #<- Boot image File

}
Restart the DHCP server.
# Service dhcpd restart

With this your Remote Installation server is ready.

Boot the client machines from the Remote Installation Server and you will get the Installer booting screen. Thereafter, and you can start the installation process on it.

Troubleshooting – Client not booting?

If your PC is not booting off the remote boot server, then two things could be wrong. Firstly, its network card may not be PXE boot enabled. If it is PXE enabled, check the BIOS to see whether the boot from network option is enabled

 

Recently I got very interesting issue and it took very long time to figure our. The problem was I was able to send/receive email to other accounts but not able to send/receive to my own account means test@test.com to test@test.com. Here is what I was getting in error logs (Cpanel server).

gin:test@test.com S=789 id=63311.122.252.239.20.1239477600.squirrel@test.com
2009-04-11 14:20:00 1LsikC-00037z-NP => /dev/null
R=central_filter T=**bypassed**

Then here is what I found in cpanel forums:

central_filter refers to the email filters you’ve set up in cPanel – stored in /etc/vfilters/. Looks like you’ve got a filter set up to drop certain emails.

Then I renamed my domain name files in /etc/vfilters/ and I got this fixed, hope this will help you

LVM stands for Logical Volume Manager.

With LVM, we can create logical partitions that can span across one or more physical hard drives. First, the hard drives are divided into physical volumes, then those physical volumes are combined together to create the volume group and finally the logical volumes are created from volume group.

Before we start, install the lvm2 package as shown below.

$ yum intall lvm2

To create a LVM, we need to run through the following steps.

  • Select the physical storage devices for LVM
  • Create the Volume Group from Physical Volumes
  • Create Logical Volumes from Volume Group

Select the Physical Storage Devices for LVM – Use pvcreate, pvscan, pvdisplay Commands

In this step, we need to choose the physical volumes that will be used to create the LVM. We can create the physical volumes using pvcreate command as shown below.

$ pvcreate /dev/sda6 /dev/sda7
Physical volume "/dev/sda6" successfully created
Physical volume "/dev/sda7" successfully created

As shown above two physical volumes are created – /dev/sda6 and /dev/sda7.

If the physical volumes are already created, you can view them using the pvscan command as shown below.

$ pvscan
  PV /dev/sda6                      lvm2 [1.86 GB]
  PV /dev/sda7                      lvm2 [1.86 GB]
  Total: 2 [3.72 GB] / in use: 0 [0   ] / in no VG: 2 [3.72 GB]

You can view the list of physical volumes with attributes like size, physical extent size, total physical extent size, the free space, etc., using pvdisplay command as shown below.

$ pvdisplay
--- Physical volume ---
  PV Name             /dev/sda6
  VG Name
  PV Size               1.86 GB / not usable 2.12 MB
  Allocatable           yes
  PE Size (KByte)    4096
  Total PE              476
  Free PE               456
  Allocated PE          20
  PV UUID               m67TXf-EY6w-6LuX-NNB6-kU4L-wnk8-NjjZfv 

  --- Physical volume ---
  PV Name             /dev/sda7
  VG Name
  PV Size               1.86 GB / not usable 2.12 MB
  Allocatable           yes
  PE Size (KByte)    4096
  Total PE              476
  Free PE               476
  Allocated PE          0
  PV UUID               b031x0-6rej-BcBu-bE2C-eCXG-jObu-0Boo0x

Note : PE – Physical Extents are nothing but equal-sized chunks. The default size of extent is 4MB.

Create the Volume Group – Use vgcreate, vgdisplay Commands

Volume groups are nothing but a pool of storage that consists of one or more physical volumes. Once you create the physical volume, you can create the volume group (VG) from these physical volumes (PV).

In this example, the volume group vol_grp1 is created from the two physical volumes as shown below.

$ vgcreate vol_grp1 /dev/sda6 /dev/sda7
  Volume  group "vol_grp1" successfully created

LVM processes the storage in terms of extents. We can also change the extent size (from the default size 4MB) using -s flag.

vgdisplay command lists the created volume groups.

$ vgdisplay
  --- Volume group ---
  VG Name                     vol_grp1
  System ID
  Format                        lvm2
  Metadata Areas            2
  Metadata Sequence No  1
  VG Access                   read/write
  VG Status                    resizable
  MAX LV                       0
  Cur LV                        0
  Open LV                      0
  Max PV                       0
  Cur PV                        2
  Act PV                       2
  VG Size                      3.72 GB
  PE Size                      4.00 MB
  Total PE                     952
  Alloc PE / Size             0 / 0
  Free  PE / Size            952 / 3.72 GB
  VG UUID                     Kk1ufB-rT15-bSWe-5270-KDfZ-shUX-FUYBvR

LVM Create: Create Logical Volumes – Use lvcreate, lvdisplay command

Now, everything is ready to create the logical volumes from the volume groups. lvcreate command creates the logical volume with the size of 80MB.

$ lvcreate -l 20 -n logical_vol1 vol_grp1
  Logical volume "logical_vol1" created

Use lvdisplay command as shown below, to view the available logical volumes with its attributes.

$ lvdisplay
  --- Logical volume ---
  LV Name                /dev/vol_grp1/logical_vol1
  VG Name                vol_grp1
  LV UUID                 ap8sZ2-WqE1-6401-Kupm-DbnO-2P7g-x1HwtQ
  LV Write Access      read/write
  LV Status              available
  # open                  0
  LV Size                  80.00 MB
  Current LE              20
  Segments               1
  Allocation               inherit
  Read ahead sectors  auto
  - currently set to     256
  Block device            252:0

After creating the appropriate filesystem on the logical volumes, it becomes ready to use for the storage purpose.

$ mkfs.ext3 /dev/vol_grp1/logical_vol1

LVM resize: Change the size of the logical volumes – Use lvextend Command

We can extend the size of the logical volumes after creating it by using lvextend utility as shown below. The changes the size of the logical volume from 80MB to 100MB.

$ lvextend -L100 /dev/vol_grp1/logical_vol1
  Extending logical volume logical_vol1 to 100.00 MB
  Logical volume logical_vol1 successfully resized

We can also add additional size to a specific logical volume as shown below.

$ lvextend -L+100 /dev/vol_grp1/logical_vol1
  Extending logical volume logical_vol1 to 200.00 MB
  Logical volume logical_vol1 successfully resized

MySQL command – sum up the data_length + index_length is equal to the total table size.
data_length – store the real data.
index_length – store the table index.

List out all the databases size

SELECT table_schema "Data Base Name", sum( data_length + index_length) / 1024 / 1024 
"Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;

Thanks.

Installation Instructions:

Required software:

  1. Perl
  2. http server (Apache, lighthttpd, etc)
  3. Squid
  4. Cron

or equivalent

in example i use Apache

1. Extract lightsquid.tgz into any folder

cd /var/www/htdocs/
mkdir lightsquid
cd lightsquid
tar -xzf lightsquid.tgz

set ‘executable’ flag for scrip

chmod +x *.cgi
chmod +x *.pl

change owner

chown -R apache:apache *
(where apache = httpd user)

2. Configure your Apache server

.cgi files must execute as CGI scrip

<Directory "/var/www/html/lightsquid">
   AddHandler cgi-script .cgi
   AllowOverride All
</Directory>

Restart apache

3. Edit lightsquid.cfg

4. If you want GROUP reports – edit group.cfg

format:

esl           01            SysAdmin
karlos       01            SysAdmin
thy           01            SysAdmin
Ivanov     02            Developer
Ivanov2    02            Developer
Petrov      03            Commerial
Petrova    03            Commerial
vasyav     04            room 312
petyava    04            room 312

5. If you want use REALNAME – edit realname.cfg

format:

esl           Sergey Erokhin
karlos       Super User1
thy           Tech Good
Ivanov     Developer numer one
Ivanov2    Developer numbe two
Petrov      Good Commerial
Petrova    Bad Commerial
vasyav     Some User1
petyava    Some User2

6. if you want graphics report

check graph report

7. run check-setup.pl

if all done try next step
else check config file.

8. Try run lightparser.pl

if everything is ok no messages will be produced

parse old statistic
./lightparser.pl access.log.1.{gz|bz2}
./lightparser.pl access.log.2.{gz|bz2}
./lightparser.pl access.log.3.{gz|bz2}

9. Try to use lightsquid

Using your favorite browser enter http://<host where we live>/lightsquid/

10. Setup crontab to run lightparser once per hour

crontab -e
This example will execute parser every 20 minutes

*/20 * * * * /var/www/htdocs/lightsquid/lightparser.pl today

if you have small log and fast machine, you may run lightparser with smaller delay
warning not set interval less 10 min

11. All done!

You Can Access Via :

http://Youripaddresshere/lightsquid

Follow

Get every new post delivered to your Inbox.