Upload
katrina-wilkinson
View
237
Download
2
Embed Size (px)
Citation preview
UNIX
System Administration Agenda
Day 1: Introduction to UNIX
Day 2: Introduction to Progress
Day 3: Platform Specific - half day
Introduction to UNIX
UNIX storage fundamentals
Working with Files and Directories
Editing and Scripting
Utilities and Maintenance
UNIX is a Operating Systems (OS) Developed in the late 1960’s by
AT&T BellLabs Since development gone through
many revisions Several flavors available with
advantages and disadvantages
Operating System
Operating System
Infor Supported Versions IBM - AIX RedHat - Linux Hewlett Packard - HP/UX Microsoft - Windows Server
Infor Partner Supported Versions Unixware - SCO
Operating System
Made up of several programs, processes and configuration files
KernelSystem Parameters
Device Files
System Daemons
Processes
Schedulers
Operating System Structure
HARDWARE
KERNEL
SHELL(BOURNE,KORN, C, R)
APPLICATIONS(SX.E/PROGRESS)
System Hierarchy
UNIX Operating System
Progress Database
SX.e Application
Login
getty = get tty telnetd
/etc/passwd
/etc/profile
/home/username/.profile
Environment Utilities# env List OS environment settingsLANG=en_US
LOGIN=aixuv0
NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat
PATH=./:/usr/bin:/bin:/etc:/usr/vsifax/bin:/usr/vsifax/spool:/etc/default/vsifax
:/home/aixuv0/bin:/rd/data:/usr/facetterm:/usr/bin/custom:/uniplex/UAP/bin:/us
r/bin:/usr/bin/adm:/etc:/usr/sbin:/usr/ucb:/home/tversema/bin:/usr/bin/X11:/sbin
EDITOR=vi
LOGNAME=aixuv0
MAIL=/usr/spool/mail/aixuv0
VFAXDIR=/usr/vsifax/spool
LOCPATH=/usr/lib/nls/loc
USER=aixuv0
AUTHSTATE=compat
SHELL=/usr/bin/ksh
ODMDIR=/etc/objrepos
HOME=/home/aixuv0
TERM=vt220
MAILMSG=[YOU HAVE NEW MAIL]
PWD=/home/aixuv0
Standard input
Environment Utilities# stty -a Lists tty settingsspeed 9600 baud; 0 rows; 0 columns;
eucw 1:1:0:0, scrw 1:1:0:0:
intr = <undef>; quit = ^\; erase = ^?; kill = ^K; eof = ^D; eol = ^@
eol2 = ^@; start = ^Q; stop = ^S; susp = ^Z; dsusp = ^Y; reprint = ^R
discard = ^O; werase = ^W; lnext = ^V
-parenb -parodd cs8 -cstopb hupcl cread -clocal -parext
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -iuclc
-ixon -ixany -ixoff imaxbel
isig icanon -xcase echo echoe echok -echonl -noflsh
-tostop echoctl -echoprt echoke -flusho -pending iexten
opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel tab3
# stty -a < /dev/tty???
UNIX Commands
Movement:
pwd Print Working Directory
# pwd /home
Pathing:
cd cd ~
cd .. cd ..//..
UNIX Commands
Checking File Permissions and Sizes:
ls List Directory -l -i -t -r
# ls.profile myfile junk
# ls -al List Directorydrwxr-xr-x 16 root System 3072 Jul 21 12:29 .
drwxr-xr-x 28 bin bin 15872 Jul 27 11:29 ..
-rw-rw-rw- 1 root System 0 Aug 25 1997 .facetusers
Wild Cards* All matches# ls -al b*
bob
bratt
bradt
? Specific characters must match
# ls -al bra?tbratt
bradt
/ (root)
root volume group data volume group
usr home var etc rd db bi
bob jean dan passwd trhead.db trhead.bi
bin lib tmp
spool adm tmp src opsys exec tmp
Directory Structure
/var
/var is a filesystem. A filesystem is an area
that exists on your volume group where you
can store files.
Filesystems
/var
adm spool tmp news
/var/adm, /var/spool, /var/tmp and/var/news are all directories (or betterknown as sub-directories.
Directories
/var
tmp bin
cmru.dat login
cmru.dat and login are files which exist in
/var/tmp & /var/bin directories.
Files
Disk Layout
Two ways to setup your disks:
- Full Disk
- Logical Volume Manager - LVM
Full Disk Approach
/rd
/root
/db
/usr /bi
LVM Approach
Hard Drive Hard Drive
2 GB 2 GB
4 GB
NxTrend chosen method for datastorage
Logical Volume Manager
Freedom… Ability to cross several physical volumes with a single filesystem.
Flexibility… Add additional physical volumes to the logical volume on the fly.
Terminology
Physical Volume = Hard drive that hasbeen initialized for usein LVM
Volume Groups = A named collection ofphysical volumes.
Logical Volume = Entities upon which afile system resides.
(swap)File system = Formatted area within
logical volume to holddata.
Typical Disk Layout
Disk1 root volume group
(boot disk)
Disk2 Disk3 data volume group
volume groups
Disk1 Files Systems
root volume group
(boot disk)
logical
volumes
Disk2 Disk3 Files Systems
data volume group
physical volumes
Superblock
Superblock - File system size and identification.
Journaled File System Structure
SuperblockInodes
Data Block
Superblock
Inodes
Data Blocks
Physical
Volume
2000 Files
VOLUME GROUPS
1999 Files
Logical
Volumes
Filesystems
Directories
& Files
Volume Groups
Physical
Volume
Files &
Directories
Filesystems
Logical Volumes
Filesystem Layout
* Redundancy
* Performance
* Growth
Mirroring
Production
Mirror
1 2 3 4 5
Disk 1
6 1 2 3 4 5
Disk 2
6
1 2 3 4 5
Disk 3
6 1 2 3 4 5
Disk 4
6
Striping
1 5 9 13 17
Dis k 1
2 6 10 14 18
Dis k 2
3 7 11 15 19
Dis k 3
4 8 12 16 20
Dis k 4
Striping & Mirroring
1 3 5 7 9
D i s k 1
11
2 4 6 8 10
D i s k 2
12
1 3 53
7 9
D i s k 3
1 2 4 6 8 1
D i s k 4
1
RAID - Redundant Array of Inexpensive Disks
(RAID 0) Striped Disks If you are creating filesystems that need the ability to do many I/Os simultaneously, a better strategy for creating them is to use Disk Striping.
(RAID 1) Mirrored Disk mirroring provides a level of redundancy in your disk system.
(RAID 10) Striped & Mirrored. RAID 10 is a new term describing the concept of using disk striping (RAID 0) across multiple mirrored pairs (RAID 1).
(RAID 5). RAID 5 is a popular industry buzzword that has emerged in the last few years. This technology provides disk redundancy to protect against disk failure, with a lower cost than RAID 1.
1 P3 4 P7 8
Dis k 1
P1 2 P4 5 P8
Dis k 2
P2 6 P5 9
Dis k 3
3 P6 7 P9
Dis k 4
Review 1
!!!BREAK!!!
Types of Files ASCII
text files (readable)
binary compiled programs (unreadable)
encrypted file containing special characters
(unreadable) Determining File Type
# file <filename>
File View# more Display file 1 page at a time
<enter> Moves down 1 line
space bar Move down 1 page
/ ? Forward/Backward find
n Next occurrence
q Quit
v vi editor
ASCII
$ more /etc/passwd
root:!:0:0:root:/:/bin/ksh
daemon:!:1:1::/etc:
bin:!:2:2::/bin:
sys:!:3:3::/usr/sys:
adm:!:4:4::/var/adm:
uucp:!:5:5::/usr/lib/uucp:
guest:!:100:100::/home/guest:/usr/bin/ksh
nobody:!:4294967294:4294967294::/:
kevina:!:200:1::/home/kevina:/usr/bin/ksh
Binary / Encrypted
$ more /usr/bin/awk^Aß^D2ûïXH^P^G^A^K^A^A:¬ð^Pþpê¤^P^AìM-^@^B
^B^D^C^E^C1L.text^P^A^P^A^A:¬^A
að^P^A;°@.bssð^Pð^PþpM-^@.loader>^E^B+À^PM-^PbM-^PM-^B^D|^^øM-^AB^P9 e)^D^BM-^Q*
#x|¯+xM-^Câ^TH]M-^@A^T}Äsx}å{xM-^@â^\9M-^Q^GHe`M-^@,^GAM-^@b^LH^EM-^YM-^@A^T^L @
M-^AM-^B^XM-^PA^TM-^@^LM-^@L^D| ^C¦NM-^@^D ^LM-^@¾!ÿÄ^B¦;^DM-^PM-^T!ÿM-^@:ãM-^P¡
^TM-^HãM-^B"$(^Ga8`ÿÿ8M-^Q9^AM-^@â(@±^GH^DiM-^@A^T0M-^Q^D8`^CH^DYM-^@A^TM-^A^B0M
^Aÿÿ1(ÿÿ})A^PM-^Q'H^DMM-^@A^T,^W^AM-^BÂ<M-^Câ@M-^Pv0Ñ0@M-^B08M-^@^A8 5H^DIM-^@A^
^T8`^BH^DuM-^@A^T0q^PH^DM-^MM-^@A^TM-^@âTM-^PgH^D¡`8`^A8M-^XH^R `M-^@âM-^D0±^XM-
M-^@A^T,^Cÿÿ8ÿ2q 3'@: ^AAM-^B^A,3qØM-^C¢^B\3ñM-^DM-^CÂM-^LM-^CM-^BM-^PM-^CB^A/M-
File View# pg Page a File
<enter> Moves down 1 page
+/-? Moves up/down by the number you input.
$ Last Page
q Quit
File View# head filename Display the beginning of
file
Displays the first 20 lines from a file
# head -100 /usr/tmp/rptlog
/smit.log
# tail filename Display the end of file
Displays the last 10 lines from a file
# tail -100 /usr/tmp/rptlog
/smit.log
File Manipulation
# mv filename newfileMove a File
# rm filename Remove a File
-i interactive
-r recursive
# cp filename newfileCopy a File
Directories
# mkdir Make a Directory
# mvdir Move a Directory
# rmdir Remove a Directory
File & Directory ManipulationRedirection:
> Redirect & overwrite
>> Redirect & append
| Pipe into another command
Search:
strings Search for text in binary files
grep Search for string
Permissions -r-xr-xr-x 1 bin bin 2206 Jul 05 12:08 /etc/profile
Type User Group Other
- r-x r-x r-x bin bin profile
r View content = 4
w Alter file content = 2
x Run executable file = 1 _______
rwx full Permissions = 7
Permissions
-rw-rwxr-- root bin asciifile
owner =
group =
other =
Permissions
-rw-rwxr-- root bin asciifile
owner = 6 (r+w)
group =
other =
Permissions
-rw-rwxr-- root bin asciifile
owner = 6 (r+w)
group = 7 (r+w+x)
other =
Permissions
-rw-rwxr-- root bin asciifile
owner = 6 (r+w)
group = 7 (r+w+x)
other = 4 (r)
File & Directory Manipulationchmod - Change Mode
chown - Change Owner
chgrp - Change Group
# chmod 774 asciifile
-rwx-rwx-r-- root bin asciifile
# chown paul asciifile
-rw-rwx-r-- paul bin asciifile
# chgrp other asciifile
-rw-rwx-r-- root other asciifile
File & Directory Manipulationchmod - Change Mode
# chmod 774 asciifile
-rwxrwxr-- bin bin asciifile
# chmod ug=7 asciifile
-rwxrwxr-- bin bin asciifile
# chmod +w asciifile
-rw-rwx-r-- root other asciifile
File & Directory Manipulationchmod - Change Mode
# chmod 774 asciifile
-rwxrwxr-- bin bin asciifile
# chmod ug=7 asciifile
-rwxrwxr-- bin bin asciifile
# chmod +w asciifile
-rw-rwx-r-- root other asciifile
Directory ProtectionAccess Resulting AvailabilityGranted for Normal Users - - - No activity allowed
r - - Lists files but no attributes
- - x Allows user to run programs but will not list files.
r - x Work with programs, list contents. No creates or
deletes.
r w x Work with programs, list contents & create or delete
files.
File Protection On On
Command Itself Directory
cd /home/test N/A x
ls /home/test/*.c none r
ls -s /home/test/*.cnone rx
cat runme r x
cat >> runme w x
runme (binary) x x
runme (script) rx x
rm runme none wx
Review 2
Text Editor - viCommand Mode (ESC)
i Insert Mode
r Replace Mode
o Open a New Line
y Yank a line
p Put a line
dd delete a line
x delete a character
/ find
SHELL SCRIPT PROGRAMMINGWhat is shell programming?
Submitting commands to UNIX.
What is a script?Text file that contains one or more UNIX
commands.
Why use it?Save a lot of time by preparing scripts to
handle repetitive processes.
Scripts/rd/bin - Directory where most NxTrend
scripts exist
/rd/bin/backup.data - Typically a Monday - Friday process that backs up the
databases and users home
directories
/rd/bin/backup.full - Typically a full system
backup (includes all filesystems)
LAB 1
!!B r E a K!!
Utilitiespasswd Changes password
finger Shows user informationwho Lists who is logged
in
man Operating System Manual
uname System information
hostname System Hostname
find finds files
whence location of pathed files
type file location/information
Checking Filesystem Sizes
# df Display FilesystemsFilesystem 512-blocks Free %Used Iused %Iused Mounted on/dev/hd4 98304 13360 87% 2100 9% //dev/hd2 1376256 56112 96% 27064 16% /usr/dev/hd9var 344064 54256 85% 4918 12% /var
# df -k Display Filesystems in 1024-blocks
# bdf Display Filesystems in 1024-blocks (HP)
# dfspace Display Filesystems in 1024-blocks (Unixware)
Checking Directory Sizes
# du /rd/src Disk Usage (512k blks)256 /rd/src/alpha
147008 /rd/src
# du -k /rd/src (1024k blks)
128 /rd/src/alpha
73504 /rd/src
# du -s /rd/src(summary)
147008 /rd/src
Printing Utilities# lp Print Command
# lp file prints to default
# lp -dprinter file prints to selected printerJob number is: 66
# lpstat -t Printer Statusscheduler is running
no system default destination
system for jrnl: trnd (as printer jrnl)
66-jrnl 1000 bytes 10/10/98
# cancel 66-jrnl Cancels Print Jobs
Process Utilitiesps list Processes
ps -e ps -ef
ps -fu
ps -ef | grep (tty/username/processname)
kill Kills a Process
kill -9 vs. Kill -15
Security
UNIX: Passwords / root &
super user privileges
Trend: Passwords
Room Security: keys, tapes
MaintenanceOn a regular basis:
Daily Backup & Disk space
Weekly Backup System, clean log
files
Monthly Disk space, OS backup,
Reboot
As needed:
Upgrades (OS, Progress, Trend)
Config Report
Port Maps
Backup Utilities
tar - Tape Archive
dd - data dump
cpio - copy in and out
CPIO OptionsCommonly used CPIO options
i - Read in from output o - Write to out output c - Wrote or read header information in ASCII
character form for portability. d - Make directories as needed. u - Copy unconditionally (normally, older files
do not overwrite newer files with the same name.
CPIO OptionsCommonly used CPIO options
m - Retain previous file modification time. This option does not affect directories that are being copiedhp, dg
v - Verbose. Cause a list of file names to be printed. When used with the t option, the table of contents looks like the output of an ls -l command. hp, ibm
CPIO OptionsCommonly used CPIO options
B - Block input/output at 5120 bytes to the record (does not apply to the cpio -p option. This options is meaningful only with data directed to or from devices that support variable-length records such as a magnetic tape.hp, dg
B -Block input/output at 512 bytes. Note when using -B to extract or create a tape archive, the blocking factor must be a multiple of the physical block size for the tape deivce. ibm
Common CPIO Commands
Backup to tape drive: cat file | cpio -ocuvdB > /dev/rmt/0m
Backup to file: cat file | cpio -ocuvdB > /usr/tmp/file
Read Tape Table of Contents cpio -ictuvB < /dev/rmt/0m | more
Common CPIO Commands
Restore all files from tape: Determine how files were backed up:
• # cpio -ictuvB < /dev/rmt/0m Relative path: files appear as bin/, usr/ , rd/ on
tapelist)• # cd /
• # cpio -icdumvB < /dev/rmt/0m Full path: files appear as /bin , /usr, /rd on tapelist)
• # cpio -icdumvB < /dev/rmt/0m
NxTrend CPIO
NxTrend Backup ScriptsBackup.data
Backup.full
Back Up Verificationbulog
tapelist
System Shutdown Shutdown the system at least every 30
days
Cleans-up hung (zombie) processes
Make sure you halt the system to reset internal components
shutdown [-r] [-h] [-y] [grace]
-r reboots the system after it reaches single user mode
-h halts the system after it reaches single-user mode.
-y turns off user interaction. The shutdown process is normally interactive, posing questions and requiring a ‘y’es or ‘n’o answer.
The -y option disables interaction allowing shutdown to run continuously
grace number of seconds that shutdown will wait before terminating all the processes running. Default is 60.
Reboot now (no grace)
shutdown -r now
Halt the system in 60 seconds
shutdown -h 60
Reboot in 60 seconds
shutdown
reboot
Reboot [-h|-r] [-n|-s] [-m mesg] [-t time] [q]
-h halt the system
-r reboot the system (default)
-n no sync before halt or reboot
-s sync before halt or reboot (default
-m supply message to users
-t halt at a specified time
-q quick and silent
Reboot now
reboot -r
Halt the system
reboot -h
Reboot now
reboot
shutdown vs. reboot shutdown shuts down more slowly but more
gracefully. Maintaining filesystem integrity
shutdown uses kill -15 to kill processes, reboot uses kill -9
reboot should only be used when in single mode or if system problems prevent you from running shutdown.
What are cron & at processes?
cron & at
UNIX facilities that allow you to schedule processes to run at a given time in the future in the background.
at vs cron
at
Schedule one time only
into the future
cron
Schedule for repetitive
processing in the future
at command syntax
at [c|k|s|q Queue Name ] [-m] [-f File Name]
{-t Date|Time [Day] [increment]
c Request a csh command
k Request a ksh command
s Request a bsh command
q Requests a queue
m Mail a message to user
f Use the filename that follows
standard input
{-t Date|Time [Day] [increment]
Time Date Increment
hrs month +n minutes
hrs:min day +n hours
hrmin year +n days
now day of week +n weeks
noon today +n months
midnight tomorrow +n years
next
at command syntax
How do you use the at facility?
# at command <enter> process you wish to run <enter>
<ctrl> D
Job userid.job# .a will be run at Day of week Month Day HH:MM:SS Timezone Year
#
Scheduling at Processes...
# at noon today <enter>
ps -e |sort +2 <enter>
<ctrl -d >Job root.800600.a will run at Thu June 18 12:00:00 MDT 1998
#
Run a ps -e command at 12:00 p.m. today and sort by the second column
Show who is logged in at 8 p.m. on July 4
# at 20 July 4 <enter> who > /usr/tmp/atwho.log <enter> <ctrl -d >Job root.800601.a will run at Sat July 4 20:00:00 MDT 1998
#
# at 8 pm July 4 <enter>Job root.800601.a will run at Sat July 4 20:00:00 MDT 1998
# at 20:00 July 4 1999 <enter>Job root.800601.a will run at Sat July 4 20:00:00 MDT 1999
# at 8 July 4 <enter>Job root.800601.a will run at Sat July 4 8:00:00 MDT 1998
List at Process:
# at -l <enter>
root.899600.a Thu Jun 18 12:00:00 MDT 1998
root.899601.a Sat Jul 4 20:00:00 MDT 1998
#
Remove at Process:
# at -r root.899600.a <enter>
The root.899600.a is deleted
#
Advanced Tips...
You can view all at jobs via the /usr/spool/cron/atjobs
directory. Each file exists as
username . Jobnumber . queuenumber.
You can view the job file using; more , pg , cat , etc…
The last line of the file indicates what command is to be processed.
Security
Restricting access to the at command
using /usr/lib/cron/at.allow &
/usr/lib/cron/at.deny files.
at.allow at.deny Who can use
_______ ________ superuser
exists ignored every userin at.allow
________ exists every userwho is not inat.deny
empty ignored superuser
________ empty all users
Restrict users by their UNIX login
Create the necessary files in /usr/lib/cron and add the UNIX login names to the appropriate files
/usr/lib/cron/at.allow
root
bobj
uucp
/usr/lib/cron/at.deny
cindyj
scottl
cron
facility not a command
controlled by the /etc/cron system
daemon
commands are executed through a
“cronfile”
Cronfiles...
exist in /usr/spool/cron/crontab{s}UNIX user names are used as cronfile namesmade up of six columns which determines
frequency of execution and what is to be executed
always copy existing cronfile to a save name before making changes.
Cronfiles1st column Minute 0 - 59
2nd column Hour 0 - 23
3rd column Day of Month 1 - 31
4th column Month of Year 1 - 12
5th column Day of Week 0 - 6 (0=Sunday)
6th column Command Command /Script
* Selects all values
, Separates values within each column
space/tab Separates each column
Scheduling cron Processes...
0 12 * * 1 ps -e >> /usr/tmp/process.log
Run a ps -e command every Monday at 12:00 p.m.
Minutes
Hours
Day of Month
Month
Day of Week COMMAND
Add the following entries to a cronfile:
List all users logged into the system from 4-5 a.m. every Saturday
* 4,5 * * 6 /usr/bin/who >> /usr/tmp/cronwho.log
crontab
crontab [ -e | -l | -r | -v |File ]
e Starts an editing session for your cronfile
l Lists your cronfile
r Removes your cronfile
v Lists the status of your cron jobs
File Submits a new cronfile to UNIX
crontabList the current cronfile:
# crontab -l <enter>
0 1 * * 1- 4 /usr/bin/backup.daily
#
Remove a cronfile. Use at your own risk!!!:
# crontab -r <enter>
#
Re-submit cronfile:
# crontab cronfile
#
Security
Restricting access to the cron
command using /usr/lib/cron/cron.allow &
/usr/lib/cron/cron.deny files.
cron.allow cron.deny Who can use
_______ ________ superuser
exists ignored every user incron.allow
________ exists every userwho is not incron.deny
empty ignored superuser
________ empty all users
Restrict users by their UNIX login
Create the necessary files in /usr/lib/cron and add the UNIX login names to the appropriate files
/usr/lib/cron/cron.allow
root
bobj
uucp
/usr/lib/cron/cron.deny
cindyj
scottl
LAB 2