Archive for the ‘ How-To ’ Category

Here is a script i use to optimize MySQL Database. This is a small bash script that you can use if you want to optimize or repair the whole database. Feel free to give comments if the script works or not.

#!/bin/sh

# @usage “mysql_tables.sh –optimize MyDatabaseABC”

DBNAME=$2

printUsage() {

echo “Usage: $0″

echo ” –optimize ”

echo ” –repair ”

return

}

doAllTables() {

# get the table names, you need to provide the root user’s password

TABLENAMES=`mysql -uroot -ptest123 -D $DBNAME -e “SHOW TABLES\G;”|grep ‘Tables_in_’|sed -n ’s/.*Tables_in_.*: \([_0-9A-Za-z]*\).*/\1/p’`

# loop through the tables and optimize them

for TABLENAME in $TABLENAMES

do

mysql -uroot -ptest123 -D $DBNAME -e “$DBCMD TABLE $TABLENAME;”

done

}

if [ $# -eq 0 ] ; then

printUsage

exit 1

fi

case $1 in

–optimize) DBCMD=OPTIMIZE; doAllTables;;

–repair) DBCMD=REPAIR; doAllTables;;

–help) printUsage; exit 1;;

*) printUsage; exit 1;;

esac

But if you want to do the hard way, here is a one line mysql script that you can use to optimize your database.

mysql -uroot -ptest123 -e"show tables" database |grep -v "Tables_in_database" |xargs -i mysql -ptest123 -e"optimize table {}" database

Like this blog? Why not buy me a cup of coffee?

This How-to is all about setting up a personal DNS server. This is also my documentation on how i install and configure DNS server on Centos 5.2, i hope it will help also other people specially those who are still studying Linux as their primary OS. I install bind in a chroot environment.

For this How to i use the following.
1. Domain: raxso.net
2. IP Address: 192.168.1.1
3. Forwarders: 208.67.222.222, 208.67.220.220 (Open DNS servers)

1. Install the following packages.

yum -y install bind bind-chroot bind-libs bind-utils caching-nameserver

2. Configure rndc:

BIND includes a utility called rndc that allows you to administer the named daemon, locally or remotely, with command line statements. The rndc program uses the /etc/rndc.conf file for its configuration options, which can be overridden with command line options.

In order to prevent unauthorized users on other systems from controlling BIND on your server, a shared secret key method is used to explicitly grant privileges to particular hosts. In order for rndc to issue commands to any named, even on a local machine, the keys used in /etc/named.conf and /etc/rndc.conf must match.

cd /var/named/chroot/etc
rndc-confgen > rndc.key
chown root:named rndc.key

Edit rndc.key so it looks like this :

key "rndckey" {
algorithm hmac-md5;
secret "L1NnF/pGne66OevgVrgzSA==";
};

You must remove some option lines. You DON’T NEED anything else in the file.

A symlink in /etc exists and points to the rndc.key file we’ve just created, named expects that file there in order to be able to authenticate against rndc.
3. Configure /var/named/chroot/etc/named.conf

// we include the rndckey (copy-paste from rndc.key created earlier)
key "rndckey" {
algorithm hmac-md5;
secret "L1NnF/pGne66OevgVrgzSA==";
};

// we assume our server has the IP 192.168.1.1serving the 192.168.1.0/24 subnet
controls {
inet 127.0.0.1 allow { 127.0.0.1; } keys { "rndckey"; };
inet 192.168.1.1 allow { 192.168.1.0/24; } keys { "rndckey"; };
};

options {
directory "/var/named";
pid-file "/var/run/named/named.pid";

recursion yes;

allow-recursion {
127.0.0.1;
192.168.1.0/24;
};

// these are the opendns servers (optional)
forwarders {
208.67.222.222;
208.67.220.220;
};

listen-on {
127.0.0.1;
192.168.1.1;
};

/*
* If your nameservers is behind firewall you might need to uncomment the query-source
* directive below.
*/
query-source address * port 53;

// for security people can't try to guess what version you're running
version "REFUSED";

allow-query {
127.0.0.1;
192.168.1.0/24;
};
};

server 192.168.1.1 {
keys { rndckey; };
};

zone "." IN {
type hint;
file "named.ca";
};

zone "raxso.net" IN {
type master;
file "data/raxso.net.zone";
allow-update { none; };

};

4. Lets create our first zone:

#vi /var/named/chroot/var/named/data/raxso.net.zone
$TTL 38400
raxso.net. IN SOA ns.raxso.net admin.raxso.net (
2008090335 ; Serial
10800 ; Refresh after 3 hours
3600 ; Retry after 1 hour
604800 ; Expire after 1 week
86400) ; Minimum TTL 1 day

raxso.net. IN NS ns.raxso.net.
raxso.net. IN MX 1 mx.raxso.net.
raxso.net. IN MX 5 mx2.raxso.net.
ns.raxso.net. IN A 192.168.1.1
cacti.raxso.net. IN A 192.168.1.1
desktop.raxso.net. IN A 192.168.1.10
mail.raxso.net. IN CNAME mx.raxso.net.
mx.raxso.net. IN A 192.168.1.2
mx2.raxso.net. IN A 192.168.1.1

Don’t forget the “.” it is very important.

5. Make sure that the service starts even if it is rebooted

chkconfig --levels 235 named on
service named start

make sure the service is running

# rndc status
number of zones: 1
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/1000
tcp clients: 0/100
server is up and running

6. Lets query:

# nslookup mx.raxso.net 127.0.0.1
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: mx.raxso.net
Address: 192.168.1.1
# nslookup www.google.com 127.0.0.1
Server: 127.0.0.1
Address: 127.0.0.1#53

Non-authoritative answer:
www.google.com canonical name = google.navigation.opendns.com.
Name: google.navigation.opendns.com
Address: 208.67.219.230
Name: google.navigation.opendns.com
Address: 208.67.219.231

7. If all went well and query is working fine you can now setup the /etc/resolv.conf on the server.
It should look like this.

# vi /etc/resolv.conf

search raxso.net
nameserver 127.0.0.1

Setup the clients and and point them to use the new DNS servers.

# vi /etc/resolv.conf

search raxso.net
nameserver 192.168.1.1

That’s all folks hope you learn something today……

Like this blog? Why not buy me a cup of coffee?

The Ramlog project lets you keep your system logs in RAM while your machine is running and copies them to disk when you shut down. If you are running a laptop or mobile device with syslog enabled, Ramlog might help you increase your battery life or the life of the flash drive on your mobile device. As a side effect of using Ramlog, you will be less likely to be caught out by a daemon that suddenly starts sending a message to syslog every 30 seconds and saps your battery keeping the hard disk spinning.

Ben Martin Wrote a How-to in using this great opensource project. Read his article.

Like this blog? Why not buy me a cup of coffee?

Connecting your Cable modem to the Router

1. First connect directly to your Cable modem without the router and verify that you can get on line.

2. Once you’ve verified that you can get onto the internet without the router please proceed. If you can not please contact your ISP for further assistance.

3. Now unplug the Ethernet cable that connects to your DSL modem from the back of your computer.

4. Take the connection that you just unplugged from the back of your computer and connect it to the WAN port of the router.

5. Take a different Ethernet cable and plug it into port closest to the WAN port, or into the LAN port.

6. Look on the front of the router. The following lights should be illuminated:

- Power

- WAN Link

- Link/Act (On the port that you connected your computer to)

- Note If other lights other than Link/Act are illuminated on this port, that is normal

- You may have a few other lights illuminated depending on the model number router you have, but the 3 above must be illuminated for proper connection.

7. Hold the Reset button on the router for 30 seconds or more

8. Restart your computer

Read the rest of this entry »

Like this blog? Why not buy me a cup of coffee?