Posts tagged slave server
Server and Backup Layout
Dec 22nd
Both the master and slave servers reside on a host machine. Clearly the servers are virtual machines. Its strategic to use virtual machines because the host machine remains useful for a variety of other tasks. The virtual server compartmentalize the functions to a discretely backupable file. In my particular arrangement the master server is synchronized with the slave server. The slave server has the same applications installed as the master. A fully functional apache web server with php and mysql support. The mysql database is synchronized as a replicate in real time, and rsync is used to sync the apache web root. In the rsync function I skip the wordpress and wiki config files, in which I reference the mysql server on the slave machine. Doing so allows server2 to be a drop in replacement for the master just by switching the port forwarding settings in the router. I would have to reconfigure my.cnf as the master in such a transplanation. The mail server has spamassassin and clamav installed on master and slave and /var/mail are synchronized to keep a relatively real time backup.
Then once a day the slave server is backed up. Vboxtool handled this seamlessly. Vboxtool stops the virtual machine, transfers it, and automatically restarts it. The initial backup is done to backup1. Then rsync is used to backup the home folder on my host system. I also use the computer for my own personal things, which are effectively backed up to backup1. Then, subsequently, the host initiates an rsync of backup1 to backup2, then to backup3. I have a rsync duplicate of backup1 on backup2 and backup3.
The host also is a MythTV server, and backup3 is the client that is subsequently connected to the TV. I have my various hosts relatively diversified and multitasked.
Slave Server – Backup the Backup – More Uptime
Dec 21st
I’m almost at the point of having a completely duplicated slave server. Currently mysql database replication is working. I have apache php5 and mysql fully working. The server synchronizes the apache root directory, with the server, every minute. Therefore for all practical purposes any file changes on the master are propogated to the slave. The mysql database is propogated in real time. I installed dovecot, sendmail, spamassassin, and clamav therefore the email environment is setup. I’m going to sync the entire /etc directory.
I’m stuck, for a little, on the users inboxes. I’m trying to rsync /var/mail but I think some permissions are missing. After I get the /var/mail directory to synchronize, as per crontab, the systems will be fully synchronized.
Now when server2 is backed up using vboxtool the main server will remain completely online! This will save approximately 5 minutes per day, therefore I will be saving 30.42 hours of downtime per year. By backing up the server as such I will be adding 30.42 hours of uptime; a rather big number.
Get Data from Master – Not Working As Expected
Dec 21st
While doing mysql database replication, to a slave server, I gave up trying to get the data directly from the master. I just copied the master database manually and things worked out smoothly. First dump the database from the master:
mysqldump -u root -p --opt exampledb > exampledb.sql
Clearly replace exampledb with the database that you want to dump. The command will also primpt you for the root mysql password. Then scp the sql file to the slave server:
scp exampledb.sql server2:exampledb.sql
Notice that the hostname of my slave server is conveniently server2. The command will also assume that the user is the same username that you are logged in with on the master.
On the slave server create a database with the same name as the master. Login to mysql:
mysql -u root -p
Issue the command to create the database:
CREATE DATABASE exampledb;
Then dump the sql file to the slave database:
mysql -u root -p exampledb < exampledb.sql
The command will dump exampledb.sql to the newly create exampledb database. Then login to mysql on the slave:
mysql -u root -p
Issue:
STOP SLAVE;
RESET SLAVE;
QUIT;
As per notes in my previous post issue:
CHANGE MASTER TO MASTER_HOST='192.168.0.100', MASTER_USER='replicate', MASTER_PASSWORD='replicate', MASTER_LOG_FILE='mysql-bin.006', MASTER_LOG_POS=183;
As states in the previous post the log file and the master log pos are determined by running on the master mysql server in a mysql shell:
SHOW MASTER STATUS;
Now log back into the slave mysql shell. Issue:
START SLAVE;
Thats should do it.
Mysql Database Replication
Dec 20th

Howtoforge.com does it well, but it took me some time, and in particular I feel one command was left out. Start by removing the bind address in /etc/mysql/my.cnf:
#skip-networking
#bind-address = 127.0.0.1
Then add the following to /etc/mysql/my.cnf. Particularly to the mysqld section!!:
log-bin = /var/log/mysql/mysql-bin.log
binlog-do-db=exampledb
server-id=1
Exampledb is the database that you intend to replicate. Server-id should be 1 being that we are dealing with the master server. Make sure that you have the log directory /var/log/mysql. On the server login as root:
mysql -u root -p
Enter the password you configure when you setup mysql. If you don’t know the password you can reset it by skipping the grant tables:
sudo /etc/init.d/mysql stop
mysql --skip-grant-tables
Then login as root:
mysql -u root
Then change the root password:
UPDATE user SET password=PASSWORD('newpassword') WHERE user='root';
Then restart mysql:
sudo /etc/init.d/mysql restart
Then login as root:
mysql -u root -p
The latter, resetting the root password, was a slight digression that may be helpful. Now add a new user with replication privileges:
GRANT REPLICATION SLAVE ON *.* TO 'replicate'@'%' IDENTIFIED BY 'replicate';
The previous command will create a user replicate with password replicate. Your slave server will connect to the master as user replicate.
Then flush privileges:
FLUSH PRIVILEGES;
USE exampledb;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
UNLOCK TABLES;
quit;
Show master status displays information about the log file mysql generates. It will give you the log position which is necessary to synchronize the slave.
Now onto the salve. Login to the slave mysql server:
mysql -u root -p
Create a database of the same name that is on the master:
CREATE DATABASE exampledb;
quit;
Edit the slave’s /etc/mysql/my.cnf file, add:
server-id=2
master-host=192.168.0.100
master-user=replicate
master-password=replicate
master-connect-retry=60
replicate-do-db=exampledb
Set the master host ip address to that of the master; kinda logical, don’t ya think… Log back into mysql on the slave:
Login to mysql:
mysql -u root -p
Issue the following:
STOP SLAVE;
RESET SLAVE;
LOAD DATA FROM MASTER;
The following will set the slave accordingly:
CHANGE MASTER TO MASTER_HOST='192.168.0.100', MASTER_USER='replicate', MASTER_PASSWORD='replicate', MASTER_LOG_FILE='mysql-bin.006', MASTER_LOG_POS=183;
Make sure the master log file is what is printer on the slave when you issue master status. The same goes for the position of the log!!!!! If you don’t have that screen up anymore issue on the master mysql server:
SHOW MASTER STATUS;
Then on the slave issue:
START SLAVE;
Quit mysql and your good to go…. Give me an email and I’ll help you out…
Hostnames – Strategic and Secure Naming
Dec 20th
I have 4 system in my house. The primary I label serverhost. On the serverhost the /etc/hostnames file is the same as the hostnames file on the other machines. The hostnames file is formatted accordingly:
##/etc/hostnames
192.168.1.100 serverhost.bgevolution.com serverhost
192.168.1.101 server.bgevolution.com server
192.168.0.102 tv.bgevolution.com tv
192.168.0.103 server2.bgevolution.com server2
Server 2 is new. I can further cleanup the schema by changing the static address of tv to 103 and server2 to 102. But for now its ok. Now I can reference hosts, with the respective ip address, simply by hostname. This is convenient for setting permissions. Permissions can be a pain in the neck, and if you are referencing a host by ip, localhost, and or the hostname you will have to create permissions for each. For example your mysql server will need permissions for each hostname that you want to connect to it with. Connecting to the server from the serverhost I need permissions for username@serverhost.bgevolution.com. But if I am connecting to mysql through phpmyadmin I need permissions for username@server.bgevolution.com.
I have replicated the mysql server on server to server2, which I connect to with the phpmyadmin installation on server. On server2 I must give permissions to username@server.bgevolution.com to be able to connect from the server. Ultimately with no experience dealing with permissions it is a pain, but after getting everything running you will realize that it makes sense, and it does increase security.
I want the slave server to also behave as the master, and ultimately I want to experiment with setting up a round robin mysql server, meaning as http requests come in to the website, I want it to randomly access database information from either server or server2. This should prove fun.




