13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 3 ■ MONITORING AND UPDATING3-10. Synchronizing Your Root SetupIf you’re working on lots of machines, it can be enormously frustrating to realize that a shortcut or aliasthat you’re used to while working on machine A isn’t there on machine B. For your own personal setup,this is one of the reasons why centralized login and NFS-mounted directories are useful—your settings,aliases, preferences, and whatever else will follow you around from machine to machine.■ Note Puppet (see recipe 3-11) is another centralization option. If you’re centralizing a lot of files, it’s likely to bea better idea to use Puppet. However, if it’s just one or two, a method like this can be appropriate (avoiding the useof the proverbial nut-cracking sledgehammer).Unfortunately, you can’t directly do this with the root user on a machine, because you need to beable to log in as root even when something has gone wrong with the network.One possibility is to use ClusterSSH (see recipe 3-17) to copy /root/.bashrc to all the othermachines every time you change it. However, as a nonautomated solution, this is obviously suboptimal.Another option is to set up a centralized /root/.bashrc that will work almost all of the time.source /shared/config/root.bashrcMake sure this is owned by root and readable only by root!chown root:root /shared/config/root.bashrc; chmod og-rw /shared/config/root.bashrcThere will probably be a few vital aliases or settings that you can’t live without even temporarily;these will need to go in the main /root/.bashrc file on each machine.If you don’t like the possibility of being without any of your aliases, you could set up a cronjob so acentral file is copied out to the file on each machine at regular intervals.One final hack that will work either with the roll-your-own centralization or with Puppet (see thenext recipe) is automatically copying any changes you make locally to the central file for propagation.This script, run regularly on each machine as a cronjob, will back up the old file with the name of themachine from which the new file is taken and the date/time and then put the new file in its place. It’llneed to run as root for the permissions to be correct.01 #!/bin/bash02 export PATH=/usr/bin;/usr/sbin;/bin;/sbin03 hostname=`hostname`04 date=`date +%Y%m%d-%H%M`05 local="/root/.bashrc"06 central="/shared/config/root.bashrc"07 diff=`diff -q $local $central`08 if [ $diff != "" ] ; then09 cp $central $central.$date.$hostname10 cp $local $central11 fi78Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!