Wednesday, May 16, 2012

Configure the network card in Linux


Red hat Linux provides following tools to make changes to Network configuration such as add new card, assign IP address, change DNS server etc.
[a] GUI tool (X Windows required) - system-config-network
[b] Command line text based GUI tool (No X Windows required) - system-config-network
[c] Edit configuration files stored in /etc/sysconfig/network-scripts/ directory.
Following instructions are compatible with
(1) Cent OS Linux
(2) Fedora Core Linux
(3) Red Hat Enterprise Linux (RHEL) 3/4/5
Method # 1: GUI tool system-config-network
Type the following command at shell prompt (open x terminal):
$ system-config-network &
Red hat enterprise Linux 5 configure the network card - system-config-network
You will see Window as above. Now select your Ethernet card (eth0 or eth1) and click on Editbutton. You can now setup IP address, netmask, default gateway and other properties.
setup IP address, netmask, default gateway and other properties
You can obtain IP address using DHCP or setup manually. Once IP address assigned, click onOk button to save the changes. You can activate card by clicking on Activate button.

Method # 2: Command line tool system-config-network-tui

If you don’t have X windows GUI installed type the following command at shell prompt:
# system-config-network-tui &
Command line tool system-config-network-tui
(click to enlarge image)
You will see text based GUI as above. Select your Ethernet card (eth0 or eth1) and hit [Enter] or [F12] special key.
Cent OS, Fedora Core, RHEL configure the network card - system-config-network-tui
(click to enlarge image)
You can obtain IP address using DHCP or setup manually. Once IP address assigned, click onOk button to save the changes

Method #3: Edit configuration files stored in /etc/sysconfig/network-scripts/

You can configure network card by editing text files stored in /etc/sysconfig/network-scripts/directory. First change directory to /etc/sysconfig/network-scripts/:
# cd /etc/sysconfig/network-scripts/
You need to edit / create files as follows:
  • /etc/sysconfig/network-scripts/ifcfg-eth0 : First Ethernet card configuration file
  • /etc/sysconfig/network-scripts/ifcfg-eth1 : Second Ethernet card configuration file
To edit/create first NIC file, type command:
# vi ifcfg-eth0
Append/modify as follows:

# Intel Corporation 82573E Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:30:48:56:A6:2E
IPADDR=10.10.29.66
NETMASK=255.255.255.192
ONBOOT=yes
Save and close the file. Define default gateway (router IP) and hostname in /etc/sysconfig//network file:
# vi /etc/sysconfig/network
Append/modify configuration as follows:
NETWORKING=yes
HOSTNAME=www1.nixcraft.in
GATEWAY=10.10.29.65
Save and close the file. Restart networking:
# /etc/init.d/network restart
Make sure you have correct DNS server defined in /etc/resolv.conf file:
# vi /etc/resolv.conf
Setup DNS Server as follows:
nameserver 10.0.80.11
nameserver 10.0.80.12
nameserver 202.67.222.222
Save and close the file. Now you can ping the gateway/other hosts:
$ ping 10.0.80.12
Output:
PING 10.0.80.12 (10.0.80.12) 56(84) bytes of data.
64 bytes from 10.0.80.12: icmp_seq=1 ttl=251 time=0.972 ms
64 bytes from 10.0.80.12: icmp_seq=2 ttl=251 time=1.11 ms
You can also check for Internet connectivity with nslookup or host command:
$ nslookup cyberciti.biz
Output:
Server:         10.0.80.11
Address:        10.0.80.11#53
Non-authoritative answer:
Name:   cyberciti.biz
Address: 75.126.43.232
You can also use host command:
$ host nixcraft.in
Output:
nixcraft.in has address 75.126.43.232
nixcraft.in mail is handled by 10 mail.nixcraft.in.

Thursday, May 10, 2012

Mysql Crash Recovery

Possible solution to mailbox stopped mysql.server not running

From Zimbra :: Wiki

Jump to: navigation, search

Contents

[hide]

Mysql Crash Recovery

In the event of database corruption it may be necessary to manually perform database recovery. See Bug 15797 for an example of an issue with mysql that will require database recovery. In that example, a warning message like the following appeared in the mysql error log:
InnoDB: Serious error! InnoDB is trying to free page 716
InnoDB: though it is already marked as free in the tablespace!
InnoDB: The tablespace free space info is corrupt.
InnoDB: You may need to dump your InnoDB tables and recreate the whole
InnoDB: database!
Before beginning a full database recovery, check to see if the corruption may be limited to a single mboxgroup or a single user within an mboxgroup. This type of corruption frequently lets the server run normally for extended periods of time, with crashes occurring only when an affected user attempts to access certain mailbox items. If this is the case, it may be possible to dump, drop and recover only the affected entries without disrupting the database as a whole. Please see the instructions in the Mysql Crash Recovery (alternate method) article.

Overview of Recovery Process

  1. Configure mysql to start in recovery mode
  2. Generate SQL dumps of all relevant databases
  3. Remove all existing (and possibly corrupt) databases
  4. Re-create all databases
  5. Repopulate the databases with the data from the SQL dumps
  6. Test databases and start all ZCS services

Details of Recovery Process

1. Configure mysql to start in recovery mode

  1. Edit the file /opt/zimbra/conf/my.cnf and add a line like innodb_force_recovery = 1 under the [mysqld] section (Note that it may be necessary to increase the recovery level depending on the extent of the database corruption, as shown at the end of the database dump step)
  2. Save the file and start mysqld
mysql.server start

2. Generate SQL dumps of all databases

  1. Load some mysql configuration into shell variables (i.e. $mysql_socket and $mysql_root_password; note that you will use these again in step 3)
  2. Make a list of the existing databases
  3. Create a directory to hold the SQL dumps
  4. Generate the SQL dumps from the database list
source ~/bin/zmshutil ; zmsetvars
mysql --batch --skip-column-names -e "show databases" | grep -e mbox -e zimbra > /tmp/mysql.db.list
mkdir /tmp/mysql.sql 
for db in `cat /tmp/mysql.db.list`; do
 ~/mysql/bin/mysqldump $db -S $mysql_socket -u root --password=$mysql_root_password > /tmp/mysql.sql/$db.sql
     echo "Dumped $db"
 done
Note: If you encounter any mysql errors while dumping the databases, start over by re-editing /opt/zimbra/conf/my.cnf, incrementing the value for innodb_force_recovery by one, and restarting mysqld. The maximum recovery level is 6. Please see MySQL's Forcing InnoDB Recovery guide for more information.
Note: An error of "bash: /tmp/mysql.sql/$db.sql: ambiguous redirect" probably indicates your using an apostrophe or single quote ' rather than a tick ` -- which is one the same key as the tilde ~ .
Note: Do not reboot the machine, as some Operating Systems will remove all contents in the /tmp directory during the reboot sequence, i.e. your /tmp/mysql.sql will be removed.

3. Remove all existing (and possibly corrupt) databases

Note that we drop the zimbra database last because the mboxgroup* databases depend on it
for db in `cat /tmp/mysql.db.list |grep mbox`
do
    mysql -u root --password=$mysql_root_password -e "drop database $db"
    echo -e "Dropped $db"
done
mysql -u root --password=$mysql_root_password -e "drop database zimbra"
Remove existing InnoDB tablespace and log files
rm -rf /opt/zimbra/db/data/ib*
Note: First, use with caution - this shouldn't need to be used often. Issue came about because of some rsync issues. Can't dump db's because of 'connection' issues at this point? One could move the /opt/zimbra/db/data directory - mv /opt/zimbra/db/data /opt/zimbra/db/data-old and then make the db - mkdir /opt/zimbra/db/data w/ ownership of zimbra:zimbra . Remove the innodb_force_recovery line from /opt/zimbra/conf/my.cnf . Then recreate a default mysql db by running /opt/zimbra/libexec/zmmyinit --sql_root_pw $mysql_root_password and then attempt this steps over again to confirm you can drop them. Also note that you may have to reset the zimbra password manually in mysql, then set it again in Zimbra with the instructions from this page: http://wiki.zimbra.com/wiki/Resetting_LDAP_%26_MySQL_Passwords

4. Re-create all databases

  1. Run mysql in non-recovery mode
    1. Remove the innodb_force_recovery line from /opt/zimbra/conf/my.cnf
    2. Save the file and restart mysqld
  2. Re-create the databases from the database list
mysql.server restart
for db in `cat /tmp/mysql.db.list`
do
    mysql -e "create database $db character set utf8"
    echo "Created $db"
done

5. Repopulate the databases with the data from the SQL dumps

Import the data from the SQL dumps. Note that we import the zimbra database first because the mboxgroup databases depend on it
mysql zimbra < /tmp/mysql.sql/zimbra.sql
for sql in /tmp/mysql.sql/mbox*
do
    mysql `basename $sql .sql` < $sql
    echo -e "Updated `basename $sql .sql` \n"
done

6. Test databases and start all ZCS services

Note that this is an example query. If you know of any particular databases that were corrupt, you may want to construct other queries to verify normal access to the data.
mysql zimbra -e "select * from mailbox order by id desc limit 1"
Once you are satisfied that the databases are restored intact, start the rest of the zimbra services.
zmcontrol start
Check /opt/zimbra/log/mysql_error.log and /opt/zimbra/log/mailbox.log for database errors.