Archive

Archive for July, 2009

How to install a Network card in linux

July 30th, 2009 Comments off

The Easy way

RedHat/Fedora distributions of linux ships with Kudzu a device detection program which runs during systems initialization (/etc/rc.d/init.d/kudzu). This can detect a newly installed NIC and load the appropriate driver. Then use the program /usr/sbin/netconfig to configure the IP address and network settings. The configuration will be stored so that it will be utilized upon system boot.

The Manual method

 Run the command

# update-pciids

By using  lshal , lsmod and lspci we get the detail property of the hardware. To find the name of the network adapter Enter:

*Note : we have to install gcc and kernel-devel pakage in RHEL 5

 lspci -v | grep Ethernet -A 1
  1. Move the base driver tar file to the directory of your choice. For example, use ‘/home/username/e1000′ or ‘/usr/local/src/e1000′.
  2.  Untar/unzip the archive, where <x.x.x> is the version number for the driver tar file: tar zxf e1000-<x.x.x>.tar.gz
  3.  Change to the driver src directory, where <x.x.x> is the version number for the driver tar: cd e1000-<x.x.x>/src/ 
  4.  Compile the driver module: make install The binary will be installed as: /lib/modules/<KERNEL VERSION>/kernel/drivers/net/e1000/e1000.[k]o The install location listed above is the default location. This may differ for various Linux distributions. 
  5.  Load the module using either the insmod or modprobe command: modprobe e1000 insmod e1000 Note that for 2.6 kernels the insmod command can be used if the full path to the driver module is specified. For example: insmod /lib/modules/<KERNEL VERSION>/kernel/drivers/net/e1000/e1000.ko With 2.6 based kernels also make sure that older e1000 drivers are removed from the kernel, before loading the new module:rmmod e1000; modprobe e1000
  6.  Assign an IP address to the interface by entering the following, where <x> is the interface number: ifconfig eth<x> <IP_address>
  7. Verify that the interface works. Enter the following, where <IP_address> is the IP address for another machine on the same subnet as the interface that is being tested: ping <IP_address>
  8. To find the driver version: Type  ethtool -i <ethx> where <ethx> is the Ethernet port . Reads the driver name and version .

Example for the first Ethernet port, eth0

# ethtool -i eth0

How To Mount USB cdrom In Linux

July 30th, 2009 Comments off

Verify with the lsmod command that the USB modules and SCSI modules are loading.A USB cdrom drive will have a device ID of /dev/scd0 assuming no other SCSI CDROM.

#mkdir /mnt/usb-cdrom
# mount /dev/scd0 /mnt/usb-cdrom

How to Back Up and Restore a MySQL Database

July 23rd, 2009 1 comment

If you’re storing anything in MySQL databases that you do not want to lose, it is very important to make regular backups of your data to protect it from loss. This tutorial will show you two easy ways to backup and restore the data in your MySQL database. You can also use this process to move your data to a new web server.

Back up From the Command Line (using mysqldump)

If you have shell or telnet access to your web server, you can backup your MySQL data by using the mysqldump command. This command connects to the MySQL server and creates an SQL dump file. The dump file contains the SQL statements necessary to re-create the database. Here is the proper syntax:

$ mysqldump –opt -u [uname] -p[pass] [dbname] > [backupfile.sql]
  • [uname] Your database username
  • [pass] The password for your database (note there is no space between -p and the password)
  • [dbname] The name of your database
  • [backupfile.sql] The filename for your database backup
  • [--opt] The mysqldump option

For example, to backup a database named ‘Tutorials’ with the username ‘root’ and with no password to a file tut_backup.sql, you should accomplish this command:

$ mysqldump -u root -p Tutorials > tut_backup.sql

This command will backup the ‘Tutorials’ database into a file called tut_backup.sql which will contain all the SQL statements needed to re-create the database.

With mysqldump command you can specify certain tables of your database you want to backup. For example, to back up only php_tutorials and asp_tutorials tables from the ‘Tutorials’ database accomplish the command below. Each table name has to be separated by space.

$ mysqldump -u root -p Tutorials php_tutorials asp_tutorials > tut_backup.sql

Sometimes it is necessary to back up more that one database at once. In this case you can use the –database option followed by the list of databases you would like to backup. Each database name has to be separated by space.

$ mysqldump -u root -p –databases Tutorials Articles Comments > content_backup.sql

If you want to back up all the databases in the server at one time you should use the –all-databases option. It tells MySQL to dump all the databases it has in storage.

$ mysqldump -u root -p –all-databases > alldb_backup.sql

The mysqldump command has also some other useful options:

–add-drop-table: Tells MySQL to add a DROP TABLE statement before each CREATE TABLE in the dump.

–no-data: Dumps only the database structure, not the contents.

–add-locks: Adds the LOCK TABLES and UNLOCK TABLES statements you can see in the dump file.

The mysqldump command has advantages and disadvantages. The advantages of using mysqldump are that it is simple to use and it takes care of table locking issues for you. The disadvantage is that the command locks tables. If the size of your tables is very big mysqldump can lock out users for a long period of time.

Back up your MySQL Database with Compress

If your mysql database is very big, you might want to compress the output of mysqldump. Just use the mysql backup command below and pipe the output to gzip, then you will get the output as gzip file.

$ mysqldump -u [uname] -p[pass] [dbname] | gzip -9 > [backupfile.sql.gz]

If you want to extract the .gz file, use the command below:

$ gunzip [backupfile.sql.gz]

Restoring your MySQL Database

Above we backup the Tutorials database into tut_backup.sql file. To re-create the Tutorials database you should follow two steps:

  • Create an appropriately named database on the target machine
  • Load the file using the mysql command:
$ mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]

Have a look how you can restore your tut_backup.sql file to the Tutorials database.

$ mysql -u root -p Tutorials < tut_backup.sql

To restore compressed backup files you can do the following:

gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]

If you need to restore a database that already exists, you’ll need to use mysqlimport command. The syntax for mysqlimport is as follows:

mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]

Enable htaccess on Apache

July 16th, 2009 Comments off

.htaccess files allows us to change configurations on our servers per directory or subdirectory. we may enable htaccess files by editing our httpd.conf rewmoving the comment on line from

#LoadModule rewrite_module modules/mod_rewrite.so

to

LoadModule rewrite_module modules/mod_rewrite.so

we need to change the AllowOverride directive also from

<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
</Directory>

to

<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>

You can also rename your .htaccess file by adding the line below on you httpd.conf file

AccessFileName [filename]

example: AccessFileName .configuration