1,576
edits
Changes
no edit summary
=LAB PREPARATION=
==OverviewPurpose / Objectives of Lab 5==[[Image:disk-space.png|thumb|right|150px|Monitoring disk space and taking corrective action before problems arise is a critical operation for a system administrator.]]
== Minimum Required Materials (Bring to All Labs) ==
|- valign="top" |width=Prerequisites"10%" | [[Image:harddrive.png|thumb|left|85px|<b>Removable Hard Disk Pack</b> (SATA)]] |width="10%" |[[Image:ubs-key.png|thumb|left|85px|<b>USB key</b><br>(for backups)]] |width="10%" |[[Image:log-book.png|thumb|left|70px|<b>Lab5 Log Book</b>]] |} ==My Toolkit (CLI Reference)==
{|width="50%" cellpadding="15"|- valign="top"|width="10%" |<u>LVM Information:</u>*[http://man7.org/linux/man-pages/man8/vgs.8.html vgs]<br>*[http://man7.org/linux/man-pages/man8/pvs.8.html pvs]<br>*[http://man7.org/linux/man-pages/man8/lvs.8.html lvs]<br>*[http://man7.org/linux/man-pages/man8/vgdisplay.8.html vgdisplay]<br>*[http://man7.org/linux/man-pages/man8/pvdisplay.8.html pvdisplay]<br>* Completion and Instructor [http://man7.org/linux/man-pages/man8/lvdisplay.8.html lvdisplay]<br>|width="10%"Sign|<u>LVM Management</u>*[http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-system-config-lvm.html system-config-lvm]<br>*[http://man7.org/linux/man-pages/man8/lvextend.8.html lvextend]<br>*[http://man7.org/linux/man-pages/man8/lvcreate.8.html lvcreate]<br>*[http://man7.org/linux/man-pages/man8/lvreduce.8.html lvreduce]<br>*[http://man7.org/linux/man-pages/man8/pvcreate.8.html pvcreate]<br>*[http://man7.org/linux/man-offpages/man8/vgextend.8.html vgextend]<br>|width="10%" of Lab 4|<u>Miscellaneous</u>*[http://man7.org/linux/man-pages/man8/mount.8.html mount]<br>*[http://man7.org/linux/man-pages/man8/umount.8.html umount]<br>*[http://man7.org/linux/man-pages/man1/df.1.html df]<br>*[http://man7.org/linux/man-pages/man1/du.1.html du]<br>*[http: //www.lehman.cuny.edu/cgi-bin/man-cgi?awk+1 awk]<br>*[http://tldp.org/HOWTO/Partition/fdisk_partitioning.html fdisk]<br>*[OPS235 Lab 4 http://www.cyberciti.biz/faq/howto-format-create- CentOS6linux-filesystem/ mkfs]*[http://man7.org/linux/man-pages/man5/fstab.5.html /etc/fstab]*[http://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800 Using crontab]
|}
=INVESTIGATION 1: MANAGING FILE-SYSTEMS USING LVM={| width="40%" align=Linux Command Online Reference"right" cellpadding="10"|- valign="top"Each Link below displays online manpages for each command (via [http:|{{Admon/note|VM Backups and Recovery|Most of these investigations will take place in your virtual machines. If you make a significant mistake, your virtual machine may not boot. Remember that you created backups of your virtual machines in Lab 2, and you can restore them if something goes wrong.<br /linuxmanpages.com><br / http>'''Remember://linuxmanpagesif you did not create backups for all of your VMs, then you don't have any restoration points to fall-back to!'''|}}|}Monitoring and ensuring adequate space for a Linux file-system is considered to be a critical task for any system administrator.com]):An application called '''LVM''' is a very useful tool for Linux system administrators to easily manage file systems - even when the computer system is running!
|- valign="top"
|
|
'''Answer Part 1 observations / questions in your lab log book.''' ===Part 2: Managing LVM Via Command Line & Adding Virtual Hard Drives===[[Image:add_virtual_disk.png|}thumb|400px|right|You can add virtual hard disks for a VM by changing to the '''Details''' section for the VM (as opposed to ''console''), click '''Add Hardware''', fill information in the '''Add New Virtual Hardware''' dialog box and clicking '''Finish'''.]]Let's say that you have run out of disk space on your '''centos3''' VM, and you need more space on the root file-system in order to host more web-pages, or to support a larger database. What are your options? Getting a replacement hard-drive would probably require re-installation of the operating system and/or backing up and restoring data on the old hard disk. Because we're using LVM we can avoid this problem. We can '''add a new <u>virtual</u> hard-drive''' (which will serve as a physical volume) to the volume group, and extend the root logical volume to make use of the new available space. Creating virtual hard drives is not only inexpensive, but a great way for students to learn now to simulate growing the size of the file system. '''Perform the following operations to increase the size of lv_root in centos3:'''
# Perform this Part in your '''centos3''' VM.
# Run the following commands and make note of the output:
::<b><code><span style="color:#3366CC;font-size:1.2em;">ls /dev/vd*</span></code></b>
::<b><code><span style="color:#3366CC;font-size:1.2em;">pvs</span></code></b>
::<b><code><span style="color:#3366CC;font-size:1.2em;">vgs</span></code></b>
::<b><code><span style="color:#3366CC;font-size:1.2em;">lvs</span></code></b>
::<b><code><span style="color:#3366CC;font-size:1.2em;">df -h</span></code></b>
<ol>
<li value="3">Record the size of the volume group and the amount of free space</li>
<li>At the top of your VM window (make certain <u>not</u> full screen mode) click the '''view''' menu and change view from '''Console''' to <u>Details</u>''' .</li>
<li>At the bottom left-hand corner, click '''Add Hardware''' and add a new storage device of '''2GBs''', make sure the '''Bus type''' is selected as: '''VirtIO disk'''.<br><br>'''NOTE: Make certain to click "select managed or other existing storage", and fill in the pathname circled in red as shown in the diagram on the right-hand-side.<br><br>'''</li>
<li>Go back to the '''console''' view</li>
<li>Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">ls /dev/vd*</span></code></b>, what has changed?</li>
<li>Use '''fdisk''' (''refer to how to use in Part 1'') to create a new single primary partition for '''/dev/vdb''' that fills the entire disk, save partition table (accepting defaults prompts would work), restart your '''centos3''' VM and then '''format''' that partition for file type: '''ext4'''.</li>
<li>Now we'll make the new device a '''physical volume''', add it to the '''volume group''', and extend '''lv_root''':</li>
</ol>
:: <b><code><span style="color:#3366CC;font-size:1.2em;">pvcreate /dev/vdb1</span></code></b> (enter '''y''' to proceed - ignore warning)
:: <b><code><span style==Managing Run"color:#3366CC;font-Levels and System Services==size:1.2em;">vgs</span></code></b> (to determine: ''name_of_volumegroup'')
:: <b><code><span style===Investigation 4"color:#3366CC;font-size: How do we Manage Runlevels?===1.2em;">vgextend ''name_of_volumegroup'' /dev/vdb1</span></code></b>
<ol>
</ol>
'''Answer Part 2 observations / questions in your lab log book.''' =INVESTIGATION 2: ADDITIONAL FILE-SYSTEM OPERATIONS = We take for granted that a file-system must be mounted (for example the root partition) in order for a Linux system to be usable upon system start-up. This was create automatically for the '''/archive''' mount point automatically when we used the system-config-lvm utility in the previous investigation. We need to learn now to do this manually by editing or adding an entry in the ''/etc/fstab'' file. The '''/etc/fstab''' (file system table) contains entries to mount various file systems automatically upon start-up of the Linux system. The Linux system administrator also has the ability to manually '''mount''' (connect) and '''un-mount''' (disconnect) partitions in order to perform maintenance on the file system (for example un-mounting the '''/home''' partition to install software and prevent users from logging in during that process). == Part 1: Mounting and Un-mounting Partitions == [[Image:mount.png|thumb|700px|right|Using the '''mount''' command with no arguments displays file-systems that are already mounted. The Linux system administrator can use the '''mount''' and '''umount''' commands to connect and disconnect different partitions from the file-system to perform maintenance.]]# Perform this part in your '''centos2''' VM.# As you may recall in Part 1 of Investigation 51, we created another logical volume called '''archive''' using the graphical application '''system-config-lvm'''. This logical volume should be mounted (connected) to our existing file-system (2GB).# Issue the following command: <b><code><span style="color:#3366CC;font-size: How do we Manage System Services1.2em;">mount</span></code></b># What is the purposed of issuing this command without arguments? Can you see the '''/archive''' mount point? # Confirm that the directory named '''/archive''' is mounted.# You can use the '''umount''' command to unmount a file-system (eg. for maintenance purposes). Note the the name of the command is umount, <u>not</u> unmount.# Make certain you are not located in the /archive directory, and issue the following command to unmount the /archive directory:<br><b><code><span style="color:#3366CC;font-size:1.2em;">umount /archive</span></code></b># Issue the '''mount''' command (without arguments) to confirm it has been unmounted.# View the contents of the file-system table /etc/fstab by issuing the following command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">cat /etc/fstab</span></code></b># Note the line that automatically mounts a file-system (''/dev/sda3'', type ''ext4'') to '''/archive'''. This was automatically performed for you via the '''system-config-lvm''' utility.# View and record the fields for the '''/archive''' mount in your lab logbook, and then issue the following command to reconnect or mount '''/archive''':<br><b><code><span style="color:#3366CC;font-size:1.2em;">mount -t ext4 /dev/centos_centos2/archive /archive</span></code></b><br><br>'''NOTE:''' If you are having problem mounting, use the /dev pathname listing in your /etc/fstab file.<br><br># Confirm that this file-system has been properly mounted. Note: You could have also issued the command: '''mount -a''' to <u>automatically</u> mount the file-systems contained in the '''/etc/fstab''' file.<br><br>Tip: If you had to do manually configure /etc/fstab (eg. only in text-based mode - centos3), you could have issued the command (as root):<br> <b><code><span style="color:#3366CC;font-size:1.2em;">echo "/dev/centos_centos2/archive /archive ext4 defaults 1 2" >> /etc/fstab</span></code></b><br>(although we don't need to do this, since it was already done).<br><br># '''A curious question''': If root needs to unmount the '''/home''' directory for maintenance but we had to first login in graphically as a regular user, then su to "root", isn't our regular user still logged in so we can't un-mount the /home directory?!? How can we as a Linux System Administrator get around the problem (hint: you already learned it somewhere in lab3!!! Wow, using what we already taught can pay-off in the future ... lol!).
== Part 2: Monitoring Disk Space ==
[[Image:disk_usage.png|thumb|500px|right|The '''df''' and '''du''' commands are useful tools for Linux system administrators to flag disk space issues and investigate their causes.]]
Another essential duty of a Linux system administrator is to anticipate problems and take preventative measures to avoid computer system problems <u>before</u> that occur.
Monitoring disk space activity helps provide Linux system administrators information to help take corrective action before problems can occur.
# Remain in your '''centos2''' VM for this section.
# Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">df -h</span></code></b>
# Note the disk space usage for '''/''', '''/home''', and '''/archive''' partitions.
# If a partition is running out of available space, the Linux System Administrator can reallocate space among partitions or add another disk and grow the file system (like you did in a previous investigation). The administrator also can investigate the cause of low disk space. Two examples immediately come to mind: excessive use of space from users, and potential penetration from hackers.
# To investigate excessive disk usage by regular users, you can obtain a total amount of disk usage for that user by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">du -hs /home/regularuserid</span></code></b>
# To provided a more detailed list of usage (file-by-file), issue the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">du -h /home/regularuserid | more</span></code></b>
# If there is a recurring space usage problem with regular users, the Linux system administrator can impose quotas (caps on disk usage). This method is not taught in this course.
# The methods to monitor potential penetration to a Linux system are too numerous, and are taught in other coures (for example: SEC520). On method of monitoring potential penetration is to look for abnormally large files. Issue the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">find -P / -size +100000k</span></code></b>
# Did you see any files that are that size?
# The next section will apply some of these tools we have discussed into a shell script and crontab entry to periodically monitor and contact the system administrator of potential disk space issues (before they become a serious problem).
'''Answer the Part 2 observations / questions in your lab log book.'''
= INVESTIGATION 3: LOOKING AHEAD =
==Automating Routine Tasks (Scheduling The Running of Shell Script Via Crontab)==
{|width="40%" align="right" cellpadding="10"
|- valign="top"
|{{Admon/tip|Bash Shell Scripting Tips:|<br><ul><li>'''Using awk to Manipulate Text:'''<br><br>Legend has it that the '''awk''' command was invented by three C programmers that wanted to create a utility in Unix that had programming syntax more like C programming. People started to use the command and found it very useful for report generation and file repair or manipulation.<br><br>The command mimics a C program, with braces '''{ }''' that surround the action to perform based on records from a database file matching either test conditions, regular expressions, etc. Fields appear as numbers with $.<br><br>'''<u>Examples</u>:'''<br><br>''awk '{print}' data-file.txt''<br><br>''awk -F";" '{print $5,$3}' data-file.txt''<br><br>''awk -F"," '$4 >= 10000 {print $1, $2}' salary.txt''</li></ul>}}
|}
This emphasis on this section focuses on how to run useful shell scripts or shell script that we have created at specific dates/times. It would be silly to expect a system administrator to stay up late (eg. 2 a.m.) to manually run a shell script to terminate processes or to re-boot Linux servers. Database files (tables) are used to provide instructions on how frequent shell scripts or commands can be run. The '''cron''' daemon is used to refer to these files and to run them on a pre-determined basis. The term '''cron''' comes from the old word '''chronograph''' meaning a special type of watch (actually a ''stop-watch'') to help monitor and schedule routine tasks.
#Perform this section in your '''c7host''' machine
#Make certain you are logged in as '''root'''.
#Download, study, and run the following shell script. Issue the command:<br><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">wget https://scs.senecac.on.ca/~murray.saul/monitor-disk-space.bash</span></code></b>
#Try to understand what this Bash Shell script does (refer to man pages for the '''awk''' command), and then run the script as root.
In order to automatically run the above-mentioned script periodically, you use the scheduler in Linux called '''crontab'''. The term crontab stands for '''Chronograph Tables''', where a chronograph is the old term for a timepiece (the forerunner of the modern watch). You can run the crontab command to schedule commands and shell script to be run in a number of different ways.
<br><br>
<ol>
<li value="5">Quickly view the tutorial about the <b>[http://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800 Using crontab]</b> file to understand the purpose of this file and how to basically set up a schedule to run a shell script.</li> <li>Issue the following Linux commandto setup a crontab entry for root: <ulbr> <lib><code>service <span style=" pointer-events:none;cursor:default;color:#3366CC;font-statussize:1.2em;">crontab -alle</codespan></licode> </ulb> </li> <li>Note Enter the following line in order to run at 6:00 on the services that are currently runningfirst day of every month:<br><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">0 6 1 * * /root/monitor-disk-space.bash #Runs first day of each month (6:00 am)</lispan> <li/code>Use the <code/b>service</codeli><li> command to stop the service named '''iptablesSave'''the crontab entry.</li> <li>Issue Confirm that the entry was properly saved by issuing the following command:<codebr>service</codeb> command to verify that this service has stopped.</licode> <lispan style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">If you reboot now crontab - the iptables service will be turned back on. We don't want it on though, it causes students headaches. To turn it off permanently we need to use the chkconfig command: l<code/span>chkconfig iptables off</code></lib> </li>Reboot and confirm that it's no longer running.</liol><'''Answer Investigation 3 observations /ol>questions in your lab log book.'''
= LAB 5 SIGN-OFF (SHOW INSTRUCTOR) ={{Admon/important|Time for a new backup, INCLUDING YOUR VIRTUAL HARD DRIVE!|If you have successfully completed this lab, make a new backup of your virtual machines. <br><br>'''Answer the Investigation 5 observations / questions Virtual hard-drives created in your this lab log book.are image files, and now need to be backed up as well!'''.}}
==Preparing for Practice For Quizzes, Tests, Midterm & Final Exam ==
#What is the advantage of disabling services such as bluetootha VG?#What is the difference between a .tgz file and a .tar.gz filePV? What do these stand forLV?#What is the purpose total size of a repository?#What is source codethe "main" VG on your system?#How do you build software from source codecreate an LV?#Which is preferred: installing from How do resize an RPM file, or installing from source code? WhyLV?#How do would you use <code>serviceadd the disk partition '''/initdev/chkconfig</code> sdb7''' to:your volume group "main"?#*show/set current runlevelHow would you increase the size of the root filesystem by 50 MB?#*list servicesHow can you determine if a partition has been mounted onto a system?#*stop How can you unmount an existing partition from the file-system?# How can you temporarily mount a servicepartition on a file-system?#*start How can you permanently mount a servicepartition on a file-system upon boot-up?#*Why is it important to learn how to manage servicesWhat are the separate elements (fields) of the '''/etc/fstab''' file?#*Why is it important Describe the tools that a Linux system administrator have to stop certain services?monitor disk space usage.