• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    FOG image sync with mysql replication - 2 Servers

    Scheduled Pinned Locked Moved
    General
    2
    5
    430
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      roc1479
      last edited by

      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

      1 Reply Last reply Reply Quote 2
      • george1421G
        george1421 Moderator
        last edited by

        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.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

        1 Reply Last reply Reply Quote 0
        • R
          roc1479
          last edited by roc1479

          @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       
          
          george1421G 1 Reply Last reply Reply Quote 2
          • george1421G
            george1421 Moderator @roc1479
            last edited by

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

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

            R 1 Reply Last reply Reply Quote 0
            • R
              roc1479 @george1421
              last edited by

              @george1421
              No problem, anything to help the community.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post

              196

              Online

              12.0k

              Users

              17.3k

              Topics

              155.2k

              Posts
              Copyright © 2012-2024 FOG Project