Monday, February 21, 2011

Master-Master Replication

Master-Master Replication
Master1 - 1.1.1.1
Master3 - 2.2.2.2


Master1
Edit /etc/my.cnf

#Primary Master server
server-id=1
auto_increment_offset=1
# total number of master servers
auto_increment_increment=2
# local slave replication options
# remote master replication options
master-host=2.2.2.2
master-port=3306
master-user=repl
master-password=replpass
master-connect-retry=10

Master3
#Secondry Master server
server-id=3
auto_increment_offset=1
# total number of master servers
auto_increment_increment=2
# local slave replication options
# remote master replication options
master-host=2.2.2.2
master-port=3306
master-user=repl
master-password=replpass
master-connect-retry=10


Loggin to Master1:

GRANT ALL ON *.* TO  root@'2.2.2.2' IDENTIFIED BY 'email#secure';
GRANT ALL ON *.* TO  repl@'2.2.2.2' IDENTIFIED BY 'replpass';
GRANT ALL ON *.* TO  repl@'%' IDENTIFIED BY 'replpass';

mysql> SHOW MASTER STATUS\G
mysql> FLUSH TABLES WITH READ LOCK;

[root@localhost]mysqldump -A -uroot -p password > master1.sql


On Master3

[root@localhost]mysql -uroot -ppassword  < master1.sql

CHANGE MASTER TO MASTER_HOST='1.1.1.1',MASTER_PORT=3666, MASTER_USER='repl', MASTER_PASSWORD='replpass',  MASTER_LOG_FILE='mysql-bin.000015', MASTER_LOG_POS=1190;

mysql> START SLAVE;
mysql> SHOW MASTER STATUS\G


On Master1

CHANGE MASTER TO MASTER_HOST='2.2.2.2',MASTER_PORT=3666, MASTER_USER='repl', MASTER_PASSWORD='replpass', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=220776001;
mysql> START SLAVE;

Master-Master Replication done.

Do add slave for master, use same post from this blog.
"http://shriikant.blogspot.com/2009/10/mysql-master-slave-replication.html"

Tuesday, February 15, 2011

Production Server/Mailserver Maintanace.

At first, allocate enough space for log partition. Linux system having default log rotation if you want to change you can do customize log rotation automatically.







See here maillog in GB, if no need just clear old log.
Log rotate.

drwxr-xr-x 2 root  root  4.0K Dec  8  2009 mail
-rw------- 1 root  root  504M Feb 15 00:49 maillog
-rw------- 1 root  root  1.1G Feb 10 02:37 maillog.1
-rw------- 1 root  root  469M Jan 31 22:23 maillog.2
-rw------- 1 root  root  1.9G Jan 30 04:17 maillog.3
-rw------- 1 root  root  1.9G Jan 23 04:17 maillog.4

Some of log rotating example:
Create the script name of /usr/bin/rotateapplog:
vi /usr/bin/rotateapplog

#! /bin/bash

TIMESTAMP=$(date +%Y-%m-%d)
cd /home/app/

cp log/production.log log/production.$TIMESTAMP.log

echo "$TIMESTAMP" > log/production.log

echo "done"

Add script as cron:

1 00 * * * /usr/bin/rotateapplog
--------------------------------------------------------------------------------------

Tuesday, February 1, 2011

Mysql Won't start (two instance on same server)

A Solution:

Install mysql db again at new location,use following command:
 
/usr/bin/mysqld_safe --defaults-file /etc/my.cnf

Restart Mysql:
     /etc/init.d/mysqld restart

/usr/local/bin/mysqld_safe --defaults-file /usr/local/etc/my.cnf
 
mysql_install_db --user=mysql --ldata=/new-data-location
mysqld_safe --datadir=/new-data-location --user=mysql &

/usr/local/mysql/share/mysql/mysql.server start