Hack59.Synchronize root Environments with rsync


Hack 59. Synchronize root Environments with rsync

When you're managing multiple servers with local root logins, rsync provides an easy way to synchronize the root environments across your systems.

Synchronizing files between multiple computer systems is a classic problem. Say you've made some improvements to a file on one machine, and you would like to propagate it to others. What's the best way? Individual users often encounter this problem when trying to work on files on multiple computer systems, but it's even more common for system administrators who tend to use many different computer systems in the course of their daily activities.

rsync is a popular and well-known remote file and directory synchronization program that enables you to ensure that specified files and directories are identical on multiple systems. Some files that you may want to include for synchronization are:

  • .profile

  • .bash_profile

  • .bashrc

  • .cshrc

  • .login

  • .logout

Choose one server as your source server (referred to as srchost in the examples in this hack). This is the server where you will maintain the master copies of the files that you want to synchronize across multiple systems' root environments. After selecting this system, you'll add a stanza to the rsync configuration file (/etc/rsyncd.conf) containing, at a minimum, options for specifying the path to the directory that you want to synchronize (path), preventing remote clients from uploading files to the source server (read only), the user ID that you want synchronization to be performed as (uid), a list of files and directories that you want to exclude from synchronization (exclude), and the list of files that you want to synchronize (include). A sample stanza will look like this:

 [rootenv] path = / uid = root # default uid is nobody read only = yes exclude = * .*  include = .bashrc .bash_profile .aliases hosts allow = 192.168.1. hosts deny = * 

Then add the following command to your shell's login command file (.profile, .bash_profile, .login, etc.) on the source host:

 rsync -qa rsync://srchost/rootenv / 

Next, you'll need to manually synchronize the files for the first time. After that, they will automatically be synchronized when your shell's login command file is executed. On each server you wish to synchronize, run this rsync command on the host as root:

 rsync -qa rsync://srchost/rootenv / 

For convenience, add the following alias to your .bashrc file, or add an equivalent statement to the command file for whatever shell you're using (.cshrc, .kshrc, etc.):

 alias envsync='rsync -qa rsync::/srchost/rootenv / && source .bashrc' 

By running the envsync alias, you can immediately sync up and source your rc files.

To increase security, you can use the /etc/hosts.allow and /etc/hosts.deny files to ensure that only specified hosts can use rsync on your systems [Hack #64]

6.5.1. See Also

  • man rsync

Lance Tost



Linux Server Hacks (Vol. 2)
BSD Sockets Programming from a Multi-Language Perspective (Programming Series)
ISBN: N/A
EAN: 2147483647
Year: 2003
Pages: 162
Authors: M. Tim Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net