LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-04-2014, 07:22 AM   #1
user41094
LQ Newbie
 
Registered: Mar 2014
Location: London, United Kingdom
Posts: 6

Rep: Reputation: Disabled
Master-Slave replication


I'm using Master-Slave replication mechanism. I have 2 webservers that have the exact same files. The Master accepts statements like SELECT, INSERT, UPDATE, etc.. from the user. While the Slave is 'read-only', and only accepts statements that don't change the database, such as SELECT.

When the Master goes down, the HAProxy sends the request to the next available server, in this case that server is the Slave.

As I said the slave is 'read-only', so what it should do is send the 'write' statement over to the master and the master write it to its database and only then replicate to the slave.

My problem is that the slave is writing to its database instead of sending it over to the Master.

My friends told me to change the IP address to where I'm connecting in mysql_connect and incase the Master is down the Slave echo's a message saying "Master database unavailable".

How can I do that?

Master: 192.168.20.10 Slave: 192.168.20.40

This is how I'm connecting to the database in both Master and slave:

Code:
<?php
        $conn_error = 'Could not connect.';
        $mysql_db = 'grupo5';

    //host, user, password
        if(!mysql_connect('localhost', 'vitorpnm', '') || !mysql_select_db($mysql_db)) {
        die($conn_error);
    }
?>
 
Old 07-11-2014, 02:13 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,504

Rep: Reputation: 1572Reputation: 1572Reputation: 1572Reputation: 1572Reputation: 1572Reputation: 1572Reputation: 1572Reputation: 1572Reputation: 1572Reputation: 1572Reputation: 1572
You will need to design your application to cope with a master/slave configuration.

You should define TWO database connections, one for anything that modifies the database and one for read-only.

Specify that the "write" connect always uses 192.168.20.10

Specify that the "read" connect always uses "localhost"

Alternatively you could make use of "circular replication" which would allow you to do writes on both servers.

There are also some proxies (can't remember off the top of my head which ones, but I know certain appliance load balancers like Citrix NetScaler) that can do MySQL query analysis and direct write queries to different server(s) from reads.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wordpress on master-to-slave replication pestka Linux - Server 5 11-06-2013 03:08 PM
MySQL Master-Slave Replication - How to make the slave read-only? saagar Linux - Server 1 08-31-2010 08:13 AM
LDAP in master-slave replication aravind1024004 Linux - Networking 1 04-20-2008 12:18 PM
LDAP in master-slave replication aravind1024004 Linux - Networking 1 04-09-2008 08:54 PM
ldap replication master - slave jadid Linux - Software 2 10-18-2006 11:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration