How to add a Swap file

Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system. It might be advantageous to increase the amount of swap space if you perform memory-intense operations or run applications that require a large amount of memory.
You have two options: add a swap partition or add a swap file. It is recommended that you add a swap partition, but sometimes that is not easy if you do not have any free space available.

At a shell prompt as root, type the following command with count being equal to the desired block size:

# dd if=/dev/zero of=/swapfile bs=1024 count=1024000

in the count type the amount of space you wont for your swap file. For example, 1024000=1GB

Setup the swap file with the command:
# mkswap /swapfile

To enable the swap file immediately but not automatically at boot
# swapon /swapfile
Or use # swapoff /swapfile to disable the mount.

To enable it at boot time, edit /etc/fstab to include:
# vi /etc/fstab
/swapfile               swap                    swap    defaults        0 0

The next time the system boots, it will enable the new swap file.
After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command
# cat /proc/swaps
or
# free
Read more >>

How To Replicate MySQL Database - Step 2

Go Back Step 1

Getting the data to the Slave.


On the Master Server
I'm assuming you have a live Master server, and an as yet empty Slave server. This stage depends on whether data is constantly being added to the Master. If so, we will have to prevent all database access on the Master so nothing can be added. This means your server will hang during the next step. If no data is being added to the server, you can skip this step. On the Master server, log into MySQL and do the following:
# mysql -u root -p
   Enter password:
   FLUSH TABLES WITH READ LOCK;
   exit;

Now we will use mysqldump to get the data out. So, still on the Master server:


# mysqldump my_database -u root -p > /tmp/database.sql;
# gzip /tmp/database.sql;

Make sure you change my_database to your database name. You will now have a file called database.sql.gz in your temp directory. This is a gziped copy of your database.

On the Slave Server
Now we need to copy over the gzipped file. On the Slave run the following:
# scp root@192.168.1.100:/tmp/database.sql.gz /tmp/



Make sure 192.168.1.100 is the IP of the Master. This will copy the file from the Master and put it in your temp directory on the Slave. Now we just need to import into MySQL:
# mysql -u root -p
   Enter password:
   CREATE DATABASE `my_database`;
   exit;
# gunzip /tmp/database.sql.gz
# mysql -u root -p
my_database  


Finishing

On the Master Server
 Now we need to find the position the Master is at in the logs. So, log into MySQL and run the following:
# mysql -u root -p
   Enter password:
   SHOW MASTER STATUS;

This should give you an output along these lines:


+--------------------------+-------------+---------------------------+------------------+
| File                     | Position    | Binlog_Do_DB              | Binlog_Ignore_DB |
+--------------------------+-------------+---------------------------+------------------+
| mysql-bin.000001         | 21197930    | my_database,my_database   |                  |
+--------------------------+-------------+---------------------------+------------------+
Keep that on-screen.

On the Slave Server
Log into MySQL and do the following:
# mysql -u root -p

   Enter password:
   slave stop;
   CHANGE MASTER TO MASTER_HOST='
192.168.1.100', MASTER_USER='slave_user',  
   MASTER_PASSWORD='your_password', MASTER_LOG_FILE='mysql-bin.000001',   
   MASTER_LOG_POS=21197930;
   slave start;
   exit;

The Slave will now be waiting. So all that's left is to...

Back to the Master Server
To release the tables from lock, Note you only have to do this if you previously run

   FLUSH TABLES WITH READ LOCK;

We shoud already be logged into MySQL, so all you have to do is:
   unlock tables;
   exit;


Read more >>

How To Replicate MySQL Database - Step 1

Configure the Master Serve

First we have to edit /etc/my.cnf, comment out these lines:
#skip-networking
#bind-address            = 127.0.0.1

Now we need to tell MySql to write a bin-log (these logs are used by the slave to see what has changed on the master)
add these lines to /etc/my.cnf in [mysqld] section:
log-bin = /var/log/mysql/mysql-bin.log
server-id=1

If you want to replicate just one database you may add this line also:
binlog-do-db=my_database

Then restart MySql
/etc/init.d/mysqld restart

Then we log into the MySQL database as root and create a user with replication privileges
# mysql -u root -p
Enter password:
GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
exit;

Configure the Slave Server

Again, we have to edit /etc/my.cnf file for the salve server,
add these lines to /etc/my.cnf in [mysqld] section:
server-id=2
master-host=192.168.1.100
master-connect-retry=60
master-user=slave_user
master-password=your_password
#replicate-do-db= my_database
relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index

Master-host – can be IP or host name of the Master Server
Replicate-do-db – add this just if you want replicate one database.
You should also make sure skip-networking has not been enabled.

Then restart MySql:
# /etc/init.d/mysqld restart 


Read more >>