Gentoo Archives: gentoo-user

From: kashani <kashani-list@××××××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Master - Slave MySQL Database Server
Date: Mon, 07 Apr 2008 21:54:49
Message-Id: 47FA9825.60103@badapple.net
In Reply to: [gentoo-user] Master - Slave MySQL Database Server by Kaushal Shriyan
1 Kaushal Shriyan wrote:
2 > hi
3 >
4 > is this a correct documentation
5 > *http://howtoforge.com/mysql_master_master_replication* for Master Slave
6 > Replication and is there a test case to test this setup
7 >
8 > Thanks and Regards
9 >
10 > Kaushal
11
12 That how-to is passable, but leaves out a number is considerations.
13
14 1. Install Mysql on the master and slave. Make sure the slave version is
15 the same or NEWER than the master. Master/Slave will break if the master
16 is running a later version than the slave. In the future you will always
17 update you slave first.
18
19 2. Get your master running and get your my.cnf setup. If you using
20 innodb you'll need to increase memory settings for it and possible tweak
21 your ibdata log file sizes. Do this first before even thinking about the
22 slave.
23
24 3. add replication user to master.
25 GRANT REPLICATION SLAVE ON *.* TO 'repl'@'db02.yourdomain.com'
26 IDENTIFIED BY 'slavepass';
27
28 4. Make your slave config exactly the same as the master with two
29 exceptions. You can use smaller memory if you must, but do not change
30 the ibdata and iblog file sizes unless you're going to import from a
31 mysqldump.
32
33 master
34 # REPLICATION ===================================================
35 log-bin = /var/lib/mysql/db01-bin
36 expire_logs_days = 7
37 server-id = 101
38
39 slave
40 # REPLICATION ===================================================
41 log-bin = /var/lib/mysql/db02-bin
42 expire_logs_days = 7
43 server-id = 201
44 skip-slave-start
45 read-only
46
47 5. Now shutdown your master cleanly and delete the logs. You should
48 really, really be sure you shut down cleanly before deleting your bin-logs.
49 sudo /etc/init.d/mysql stop
50 cd /var/lib/mysql/
51 sudo rm -rf db01-bin.*
52 cd ../
53 sudo rsync -av mysql/ mysql-slave/
54 sudo /etc/init.d/mysql start
55
56 6. Copy your slave mysql dir over to the slave. Mysql should be down on
57 the slave before doing this.
58 rsync -av /var/lib/mysql-slave/ user@db02:/var/lib/mysql-slave/
59 ssh db02
60 cd /var/lib/
61 sudo chown -R mysql: mysql-slave/
62 sudo rsync -av mysql-slave/ mysql/
63
64 This way you don't have to start from scratch you screw it up. Any you
65 will screw it up at least once.
66
67 7. Start up the slave and tell it where to start.
68 sudo /etc/init.d/mysql start
69 mysql -u root -p
70 CHANGE MASTER TO MASTER_HOST='db01.yourdomain.com', MASTER_USER='repl',
71 MASTER_PASSWORD='slavepass', MASTER_LOG_FILE='db01-bin.000001',
72 MASTER_LOG_POS=4;
73 start slave;
74 show slave status;
75
76 The starting log position is always 4 when Mysql starts up fresh with no
77 logs, which is why we deleted them. Plus why copy around a lot of 1GB
78 log files when you rsync. If you have the option to shut your master
79 down, it's a nice short cut to avoid looking up the log position when
80 you dump and what not. Also rsync is much faster than doing a
81 master-dump mysqldump in most cases which makes for less production
82 downtime.
83
84 kashani
85 --
86 gentoo-user@l.g.o mailing list