@george1421
FOG - Image Sync with Mysql Master Master Replication
- If existing FOG servers, export all configured resources from main server (Image templates, hosts, groups, snapins etc).
- The 2nd FOG server was a new install, so didn’t have any images or data.
- Built on Ubuntu 18.04 LTS
- FOG Server 1.5.7
HOST A (Main):
sudo nano /etc/mysql/my.cnf with content:
[mysqld]
server-id=1
log-bin=mysql-bin
bind-address=IPOFHOSTA
port=3306
auto_increment_increment=2
auto_increment_offset=1
Restart Mysql
sudo systemctl restart mariadb
Create a replication user and grant replication permission
mysql -u root -p
create user 'repuser'@'%' identified by 'fogpassword';
grant replication slave on *.* to 'repuser'@'%';
flush privileges;
show master status;
*Note: Make note of BINLOG File name and POS for use setting up HOSTB
HOST B:
sudo nano /etc/mysql/my.cnf with content:
[mysqld]
server-id=2
log-bin=mysql-bin
bind-address=IPOFHOSTB
port=3306
auto_increment_increment=2
auto_increment_offset=2
Restart Mysql
sudo systemctl restart mariadb
Create a replication user and grant replication permission
mysql -u root
create user 'repuser'@'%' identified by 'fogpassword';
grant replication slave on *.* to 'repuser'@'%';
stop slave;
CHANGE MASTER TO MASTER_HOST='IPOFHOSTA', MASTER_USER='repuser', MASTER_PASSWORD='fogpassword', MASTER_LOG_FILE='BINLOGFILENAMEHOSTA', MASTER_LOG_POS=POSHOSTA;
start slave;
show master status;
*Note: Make note of BINLOG File name and POS for use setting up HOSTA
Back on HOST A:
Setup replication:
mysql -u root -p
stop slave;
CHANGE MASTER TO MASTER_HOST='IPOFHOSTB', MASTER_USER='repuser', MASTER_PASSWORD='fogpassword', MASTER_LOG_FILE ='BINLOGFILENAMEHOSTB', MASTER_LOG_POS=POSHOSTB;
start slave;
show slave status \G;
Replication should be working now.
You can now import your backups, if you had an existing server. If not, just test it by creating an image template on either FOG server. Data should replicate to the other.
Syncing Images using rsync
#Push
rsync -a --no-perms --no-owner --no-group -P --ignore-existing --exclude-from='/opt/excluded.txt' /images/ USER@HOSTBIP:/images/
#Pull
rsync -a --no-perms --no-owner --no-group -P --ignore-existing --exclude-from='/opt/excluded.txt' USER@HOSTB:/images/ /images/
Excluding files or folders
sudo nano /opt/excluded.txt
#Add any files or folder which should be excluded from replication within the images folder
dev
lost+found
postdownloadscripts
.mntcheck
I use these scripts on the main server to push and pull at schedule intervals.
contab -e
#min hour dayof month month dayof week
#Push
0 01 * * Wed /opt/rsync_push.sh
0 01 * * Sat /opt/rsync_push.sh
#Pull
0 06 * * Wed /opt/rsync_pull.sh
0 01 * * Sun /opt/rsync_pull.sh