FOG image sync with mysql replication - 2 Servers



  • Hi guys,

    I Wanted to share how I use FOG with image sync and mysql replication between 2 different FOG servers.

    Version: 1.5.7 running on Ubuntu 18.04 LTS
    Setup: 2 FOG servers with local storage at 2 different locations (NJ and NC) connected via site to site VPN
    Function: Simple capture and deploy, no management, addons, snapins, groups or hosts.

    I’ve setup MariaDB master master replication and this sync’s: Images, Hosts, Groups, Users, Snapins, Printers and probably more between the 2 FOG servers. I’m sure anything that is stored in mysql will sync.

    I use rsync scheduled via cron to push and pull new image files from the main server. I had problems with the built in replication, so this was the work around.

    Just thought I’d share as this was my way to replicate site to site.

    Rocky



  • @george1421
    No problem, anything to help the community.


  • Moderator

    @roc1479 Very nice, well done. We’ll have to go over it and test it in the lab, but the configuration is pretty straight forward. Thank you.



  • @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       
    

  • Moderator

    If you had time, it would be interesting if you could document the way you setup db replication between the two fog servers. It could be a great addition to the wiki pages.


Log in to reply
 

387
Online

7.5k
Users

14.6k
Topics

137.4k
Posts