UNIX System Administration A Beginner’s Guide PHẦN 10 ppt

67 251 0
UNIX System Administration A Beginner’s Guide PHẦN 10 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

remote hosts that should be updated with the list of files contained within the FILES variable. In this case, the target hosts are dino and fred. The list of files defined with the FILES variable copied to the remote hosts are /etc/hosts and. /etc/resolv.conf. Naturally, these hosts must be official node names that are contained within /etc/hosts, NIS, or DNS. Also, the files must exist on the local system, which is the system where the rdist command will be executed. The way rdist variables are accessed by enclosing the variable name within brackets and adding the dollar sign in front of the name, thus ${FILES} or ${HOSTS} are both valid. Additional parentheses, such as (${FILES}) are needed around variables when they are used with certain rdist directives, as shown in the above example. We use the rdist string -> to signify that we would like to copy the contents of the FILES variable to the target machines contained with the HOSTS variable. The install keyword string indicates that the files should be installed on the remote hosts. To invoke the above configuration, assume that we have saved this information to a text file called network-dist and use the rdist command as shown here: # rdist -f network-dist updating host dino updating: /etc/hosts updating: /etc/resolv.conf updating host fred updating: /etc/hosts updating: /etc/resolv.conf The –f option informs rdist to read the accompanying configuration file from the command line. By default, rdist will search the local directory for a file called distfile and, if found, will attempt to process this file for software distribution directives. Thus, if we rename the network-dist file to distfile and run the rdist command again without any arguments, it will accomplish the same work as shown in the above example. As you can see from the output, both hosts are listed and the associated files were updated on each host. If we were to execute the command again, we would find different output: # rdist -f network-dist-3 updating host dino updating host barney 610 UNIX System Administration: A Beginner’s Guide TEAMFLY Team-Fly ® The reason for this is that rdist automatically checks to see if the local files have changed with respect to the remote copies. If no change has been made to the local files, and the command is run again, the result of the rdist command differs from the first rdist example because it hasn’t updated the remote files. Instead, it simply displays that each host has been updated, but in actuality the rdist tool found that it didn’t really need to sync up the files because they didn’t change. How does rdist determine if a file has changes? That is a very good question! By default, it uses two methods—first, if the file size has been altered since the last copy, and second, if the modification time of the file has changed with respect to the last copy. 21.2 Debug an rdist Configuration If we are having trouble getting a particular rdist configuration working, we have two ways to debug the problem. First, we can use the –n option that shows the steps rdist will take when supplied a configuration file. Second, we can use the –D option to display a verbose listing of debugging output during execution of the rdist command. If we are interested in only displaying which files would be updated on a given target versus actually doing the software syncing, we can use the –n option. This option just outputs the files that would be updated versus actually physically copying these files over. Thus, # rdist -n -f network-dist-5 updating host barney install -R /etc/hosts /etc/hosts install -R /etc/resolv.conf /etc/resolv.conf updating host fred install -R /etc/hosts /etc/hosts install -R /etc/resolv.conf /etc/resolv.conf From this example, you can see that both systems (barney and fred) would be updated with both /etc/hosts and /etc/resolv.conf files. The –D option shows much more information about the steps rdist follows when doing work. Unfortunately, some of the displayed messages can be rather cryptic, which make them hard to interpret. For example, the rdist command from the previous example is run with the debug command-line option. This Module 21: Using rdist 611 21 612 UNIX System Administration: A Beginner’s Guide command-line option is most useful in debugging rdist when more advanced or complex directives or options are used. bash-2.03# rdist -D -f network-dist-7 | cat -n 1 lookup(HOSTS, 1, 33860) 2 lookup(FILES, 1, 338a0) 3 expand(338c0, 3) 4 list = ( ${FILES} ) 5 lookup(FILES, 0, 0) 6 expanded list = ( /etc/hosts /etc/resolv.conf ) 7 expand(338d0, 7) 8 list = ( ${HOSTS} ) 9 lookup(HOSTS, 0, 0) 10 expanded list = ( dino barney ) 11 insert: files = ( /etc/hosts /etc/resolv.conf ) insert: hosts = ( dino barney ) 13 insert: cmds NULL 14 docmds: cmds c_type ARROW, c_name dino, c_label NULL, c_files ( /etc/hosts /etc/resolv.conf ) 15 sc_type INSTALL, sc_options 16<REMOVE>, sc_name NULL, sc_args ( ) 16 c_type ARROW, c_name barney, c_label NULL, c_files ( /etc/hosts /etc/resolv.conf ) 17 sc_type INSTALL, sc_options 16<REMOVE>, sc_name NULL, sc_args ( ) 18 doarrow(338e0, dino, 350d0) 19 makeconn(dino) 20 updating host dino 21 port = 514, luser = root, ruser = root 22 buf = /usr/ucb/rdist -Server 23 install -R /etc/hosts /etc/hosts 24 target = /etc/hosts, rname = hosts In this example, the rdist command is run and the output is sent to the cat command using the –n option. Recall that this option displays the associated line number within the output, which makes it easier to read. As you can see, the output is quite verbose and has been truncated to only a portion of lines that were actually displayed. However, the output can be used to get a general idea of how the rdist tool is parsing and handling the configuration file. 21.3 Investigate rdist Commands As previously mentioned, rdist supports a number of directives that control how the installation of remote files is done and helps determine whether other related tasks should be done as well. All of the supported rdist command directives are listed in Table 21-2. Module 21: Using rdist 613 21 We have seen the install directive at work in previous examples. However, this rdist command supports a few options that correspond to the regular rdist command-line options—namely, the –b, -h, -i, -R, -v, -w, and –y options, which are listed in Table 21-1 above. One of the more useful options, -R, provides the ability for rdist to maintain truly identical copies of directory structures from the local system to the remote target systems. Consider the following example configuration: HOSTS = ( dino barney ) FILES = ( /stream/bin /stream/etc /stream/movies) (${FILES}) -> (${HOSTS}) install -R ; In this case, we are syncing three different directories under the /stream directory and when we run rdist—these three directories (and their contents) will be copied to the remote systems dino and barney. Let’s display the contents of the /stream/movies directory on the system called dino: # rsh dino ls -al /stream/movies total 196604 drwxr-xr-x 2 root root 512 Nov 3 16:16 . drwxr-xr-x 5 root other 512 Nov 3 16:16 -rw-r r 1 root root 6662846 Oct 11 2000 matrix-1.mov -rw-r r 1 root root 62020733 Oct 11 2000 powers.mov -rw-r r 1 root root 91878 Oct 30 2000 rtspam.mov -rw-r r 1 root root 91878 Oct 12 2000 sample.mov Directive Meaning install [options] Copy any out-of-date files and/or directories to the target systems. notify address Send email to the specified users. except filename Exclude a file from being updated. This file is supplied with the filename argument. except_pat pattern Exclude one or more files from being updated that match a specific regular expression listed in pattern. special [commandgrep ] Invoke a shell command on the remote target machine when one or more files have been successfully copied. Table 21-2 rdist Command Directives -rw-r r 1 root root 5893937 Oct 12 2000 swtrailer-1.mov -rw-r r 1 root root 5863261 Oct 12 2000 swtrailer-2.mov -rw-r r 1 root root 19929586 Oct 12 2000 swtrailer-3.mov # Let’s now assume that we have removed some of the files stored within the /stream/moves directory on the local system and we would like to resynchronize the other target systems. When we rerun the rdist command, we get the following: # rdist -f directory-dist updating host dino removed /stream/movies/swtrailer-1.mov removed /stream/movies/swtrailer-2.mov removed /stream/movies/swtrailer-3.mov updating host barney removed /stream/movies/swtrailer-1.mov removed /stream/movies/swtrailer-2.mov removed /stream/movies/swtrailer-3.mov As you can see, rdist reported that these files were removed from the remote systems as expected. Sure enough, if we again display the contents of the /stream/movies directory on one of the target systems, we get # rsh barney ls -al /stream/movies total 134620 drwxr-xr-x 2 root root 512 Nov 4 11:37 . drwxr-xr-x 5 root other 512 Nov 3 16:13 -rw-r r 1 root root 6662846 Oct 11 2000 matrix-1.mov -rw-r r 1 root root 62020733 Oct 11 2000 powers.mov -rw-r r 1 root root 91878 Oct 30 2000 rtspam.mov -rw-r r 1 root root 91878 Oct 12 2000 sample.mov Task Notifications You can use the notify directive to send email when one or more tasks are completed. Email can be sent when a specific task is complete or a group of tasks have been done. For instance, using the example above, we can add the following directive to the end of the rdist configuration file: notify root@pebbles ; 614 UNIX System Administration: A Beginner’s Guide This instructs rdist to send email to the root user on the host pebbles. When we resynchronized the /stream/movies directory for the dino host, the following email was sent: From root Mon Nov 5 17:04:37 2001 Date: Mon, 5 Nov 2001 17:04:37 -0800 (PST) From: rdist (Remote distribution program) To: root@pebbles.home.com Subject: files updated by rdist from pebbles.home.com to dino removed /stream/movies/swtrailer-1.mov removed /stream/movies/swtrailer-2.mov removed /stream/movies/swtrailer-3.mov The output clearly shows what the rdist command has accomplished; it shows that it removed three movies files from the remote target called dino. Also, a duplicate message was sent for the other host barney. Thus, rdist is fairly verbose about what tasks it reports when sending email. If you wanted to send to several users, you can simply add the required number of notify directives, such as notify root@bedrock ; notify anitat@bedrock ; notify stevem@pebbles ; However, if you find that a larger number of users might be interested in receiving rdist-specific messages, it might be easier to use a mail alias. For instance, we might create a new alias called dist-list. In this case, we update the /etc/mail/aliases file with the following entry: dist-list:root@bedrock,anitat@bedrock,stevem@pebbles Once done, we can update the rdist configuration file with notify dist-list@mail-host, where mail-host is the name of the mail server. If a notify directive doesn’t contain a host portion of an email address, rdist uses the target system as the destination host to send the mail. Thus, HOSTS = ( peaches cream ) FILES = ( /src ) (${FILES}) -> (${HOSTS}) Module 21: Using rdist 615 21 install -R ; notify root ; notify dist-list ; will send mail to the accounts of root and dist-list on both systems called peaches and cream. 1-Minute Drill ● Why is using rdist preferable to manually copying files when many systems are involved? ● What is the point of the notify directive? Excluding Files The rdist command is great for copying entire directories to remote systems. However, suppose you want to copy most of the files within a directory, but not all files? One approach would be to include every file you wanted. However, this might be both time-consuming and hard to maintain going forward because if files are added and/or deleted on a regular basis, this will be hard to track. Also, consider if the directory contains a larger number of files. We need a better solution, and fortunately rdist provides one! The best way to address this type of problem is to simply exclude the files you don’t want copied to the target systems. For example, consider the following: HOSTS = (peaches cream) FILES = ( /src/package /src/bin ) (${FILES}) -> (${HOSTS}) except /src/package/a.out ; install -R ; notify root@pebbles ; 616 UNIX System Administration: A Beginner’s Guide ● rdist saves time and reduces the possibility of error when more than a few files or systems are involved. The time savings are multiplied if the systems need to be synchronized repeatedly, such as a regularly scheduled nightly or weekly synchronization. ● To inform users or administrators when rdist makes changes on their systems so they aren’t surprised by the file changes. Excluded file within synchronized directory Directories to synchronize Module 21: Using rdist 617 21 On the previous page, two directories (/src/packages and /src/bin) are being synchronized on target systems peaches and cream. However, the /src/package/a.out file is exclude from the list of files that are copied to both systems. If we find that a larger number of files must be excluded from a particular directory, we can define a variable similar to the HOSTS or FILES objects. Thus, EXCLUDE_FILES = (/src/package/a.out /src/package/libc.ar /usr/package/libc_test.ar /usr/package/message.o /usr/package/message.as) Here, the variable EXCLUDE_FILES is defined with the files that should not be copied to any target systems. We can use this variable with the except rdist directive: except (${EXCLUDE_FILES}) ; You can also exclude files that match a particular pattern using the except_pat command directive. This command supports matching on shell-type regular expressions. However, the characters “\” and “$” must be escaped if they are going to be used in the rdist configuration file. Typical examples include except_pat “*.h” and except_pat “.??*”, which will not copy any files that have an .h extension and no files that begin with leading dot (.) followed by a number of characters (which is usually the case with initialization files). Invoking Commands Sometimes it might be necessary to invoke a specific UNIX command when a particular file or a group of files has been updated on a remote system. Consider an example where you synchronize a configuration file that a process requires, and once the file has been updated the process must be restarted in order to use the new configuration file. Several UNIX system programs use this model; you must inform or kill a system process before it will pick up any changes made to its configuration file. To expand on this, note the following rdist configuration file: HOSTS = ( dino wilma ) FILES = ( /etc/inet/inetd.conf ) 618 UNIX System Administration: A Beginner’s Guide (${FILES}) -> (${HOSTS}) install -R ; notify root@pebbles ; special "/usr/bin/pkill -HUP inetd" ; This configuration will push the /etc/inet/inetd.conf configuration file to both dino and wilma. Once done, it will execute the pkill command on both systems using the special rdist directive. This special command takes a single command argument and executes it on all target systems. The UNIX pkill command will send a signal to the inetd process, which causes this process to reread its configuration. Thus, any changes to the newly pushed /etc/inet/inetd.conf file will take effect immediately. As you can see, the rdist tool makes it very easy to execute a specific function as part of the overall file distribution mechanism. 21.4 Explore an rdist Example To further explain how rdist might be used in a real world and even perhaps in a product-like environment, a more elaborate example has been provided. Naturally, this configuration example file represents one possible way of addressing the requirements that a typical UNIX shop might have. Some of the requirements for this example include ● Sync a different set of files to different systems ● Provide notification when files change and when synchronization is complete To address these requirements, the following rdist configuration is supplied: 1 SERVERS = ( dino pebbles barney ) 2 WORKSTATIONS = ( pebbles1 pebbles2 pebbles3 pebbles4 ) 3 NETWORK_FILES = ( 4 /etc/foo 5 /etc/hosts 6 /etc/resolv.conf 7 /etc/defaultrouter 8 /etc/nsswitch.conf 9 /etc/inetd.conf 10 /etc/netmasks 11 /etc/networks Defining two different sets of systems for different synchronization requirements Module 21: Using rdist 619 21 12 /etc/inet/ntp.conf 13 /etc/inet/ntp.server 14 /etc/snmp 15 ) 16 GENERAL_FILES = ( 17 /bar 18 /etc/passwd 19 /etc/group 20 /etc/shadow 21 /etc/aliases 22 /etc/profile 23 /etc/projects 24 /etc/syslog.conf 25 ) 26 SECURITY_FILES = ( 27 /me 28 /etc/ftpusers 29 /etc/default/login 30 /etc/hosts.equiv 31 /.rhosts 32 ) 33 34 MEDIA_FILES = ( 35 /streams/mov 36 /streams/asf 37 38 ) 39 APPS = ( 40 /packages/vnc 41 /packages/ssh 42 /packages/mrgt 43 ) 44 45 (${NETWORK_FILES}) -> (${SERVERS}) 46 install -R ; 47 notify root@pebbles ; 48 special "/usr/bin/pkill -HUP xinetd" ; 49 (${GENERAL_FILES}) -> (${SERVERS}) 50 install -R ; 51 notify root@pebbles ; 52 (${MEDIA_FILES}) -> (${WORKSTATIONS}) 53 install -R ; 54 notify root@pebbles ; 55 ${SECURITY_FILES} :: /dist/timestamp 56 notify dist-list@pebbles ; Defining one of several sets of files for the different synchronization requirements Synchronizing the different sets of files to different sets of systems Sending a notification for each synchronization [...]... snmptable snmptest snmptranslate Look up DNS entry Show the content of file Make a file system available Make a new file system Simple command to make a new file system Change a user password Determine network node reachability Add a package on Solaris Remove a package on Solaris Query a Solaris package Display configuration information on Solaris system Show disk partition information on Solaris Show... software 4 System Library 5 D Maintains system capacities 6 System administrator Module 2: Basic UNIX Commands 1 D ps 2 cat -b 3 date 100 415302002 4 C hostname 5 find/-atime+365 6 File type is directory Permissions are read, write, and executable for owner, read and executable for group, and only executable for others 7 A Administrator 8 The ? designates that no terminal was involved when a process started... target systems and displays any discrepancies, but doesn’t update any files on the target systems or send any notification? Appendix A Answers to Mastery Checks Copyright 2002 by The McGraw-Hill Companies, Inc Click Here for Terms of Use 626 UNIX System Administration: A Beginner’s Guide Module 1: Introduction to UNIX 1 Physical hardware, operating system, and applications 2 A Kernel 3 B Proprietary... 628 UNIX System Administration: A Beginner’s Guide 8 passwd -s yourusername 9 C KpF4j7 (A is a bad choice because it doesn’t contain any numbers or special characters B is a bad choice because it is too similar to the current password D is a bad choice because it is based on the username.) Module 6: File Systems, Disks, and Tools 1 file system 2 C i-node table 3 disk partition 4 drive letter a, partition... SYSTEMTYPE1 Add as many additional lines as needed between lines 4 and 10 If you want, change the FILEGROUP1 name on line 3 to a more meaningful name 5 Repeat step 4 to define additional synchronization directory groupings on lines 12, and 22, renaming the groups on line 11 and 21 if desired and adding as many lines after lines 12 and 22 as needed for each group 21 622 UNIX System Administration: A. .. layer 7 and layer 4 Hint Definitions for layers 5 and 6 do not currently exist Functional layers used to determine sysServices are listed in Table C-2 C 644 UNIX System Administration: A Beginner’s Guide Layer Number Device Functionality 1 Physical: A device that operates on this layer is known as a network repeater Data link and/or subnetwork layer: A device that operates on this layer includes a. .. system command within an rdist configuration file? A install B command C execute D special 21 624 UNIX System Administration: A Beginner’s Guide Mastery Check 8 By default, what does rdist compare to determine if a file on a target system has changed and needs to be synchronized? A File size and modification time B Binary content C Modification time and binary contents D Owner and permissions 9 What does... Physical address 12 trap 13 B Community name 14 trap 15 GetBulkRequest 16 NoCreation A 632 UNIX System Administration: A Beginner’s Guide Module 14: Using Domain Name System 1 Hierarchical 2 False Because the companies have different domains, DNS will not have conflicts 3 Host Resolution 4 Domain: edu; organization: indiana; subdomain: athletics; host: www 5 nslookup 6 Server 192.168.1.215 7 host and... and in the example we have both servers and workstations—rdist variables SERVERS and WORKSTATIONS, respectively—which are defined on lines 1–2 Naturally, the breakdown of systems can be any arbitrary classification that you can imagine The point here is to define the classification that most suits your particular environment and that you feel most comfortable with Once the systems and files are defined,... reviewed and discussed within this book Name Description admintool arp cat control-panel date dd dhcpmgr dig dump exportfs fdisk find format fsck ftp grep groupadd groupdel groupmod grpck halt host hostname landiag lanscan ifconfig init logins ls netstat nfsstat nmap Solaris administration tool Monitors and controls ARP cache Show the content of file Linux administration tool Show system date and time Image . /etc/default/passwd 7. usermod -L wilma A Appendix A: Answers to Mastery Checks 627 628 UNIX System Administration: A Beginner’s Guide 8. passwd -s yourusername 9. C. KpF4j7. (A is a bad choice because. if all files are updated on the target systems and displays any discrepancies, but doesn’t update any files on the target systems or send any notification? Mastery Check AppendixA Answers to Mastery. execute a system command within an rdist configuration file? A. install B. command C. execute D. special 624 UNIX System Administration: A Beginner’s Guide 8. By default, what does rdist compare

Ngày đăng: 13/08/2014, 04:21

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan