Changes

Jump to: navigation, search

OPS235 Lab 3 - CentOS7

6,876 bytes removed, 08:31, 28 March 2015
no edit summary
[[Category:OPS235]]
=Logical Volume Management and Software Package Management=
==IntroductionInvestigation 1: How do you query the RPM database? ==
RPM maintains a database of installed software. This information is very useful to system administrators. In this the previous lab youqueried that database using RPM with the -q argument. When you query the RPM database, you can separately specify::* Do an <u>operational task</u> on one or more packages (like installing or removing a package), using a '''select-option'''re going to:* What <u>information</u> you want about those packages, using a '''query-option'''
'''Perform the following steps:* Learn how to add and remove software packages on your different Linux systems.:* Learn how to properly adjust your various Linux file systems by using and managing LVM both graphically (centos2) as well as command line (centos3).'''
== Required Materials (Bring to All LabsPerform investigations 1 - 3 in your host machine (c6host) ==
* CentOS 6.5 x86_64 Live DVD* CentOS 6.5 x86_64 Installation DVD1* SATA Hard Disk (# Using information from the man page for <code>rpm</code>, fill in removable disk tray)* USB Memory Stick* Lab Logbookthis information:
==Prerequisites== * Completion and Instructor "Sign-off" of Lab 2: [[OPS235 Lab 2 - CentOS6]] ==Linux Command Online Reference==Each Link below displays online manpages for each command (via [http://linuxmanpages.com/ http://linuxmanpages.com]): {|width="100%" border="1" cellpadding="5"|'''LVM Information Utilities:'''-!Option|'''LVM Management Utilities:'''!Meaning!Select or query option?!Example command|'''Additional Utilities:'''-|- valign="top"a|Select all packages*[http://linuxmanpages.com/man8/vgs.8.php vgs]|select-option*[http://linuxmanpages.com/man8/lvs.8.php lvs]| *[http://linuxmanpages.com/man8/pvs.8.php pvs]|-*[http://linuxmanpages.com/man8/vgdisplay.8.php vgdisplay]| -l*[http://linuxmanpages.com/man8/lvdisplay.8.php lvdisplay]| *[http://linuxmanpages.com/man8/pvdisplay.8.php pvdisplay]| |*[http://www.centos.org/docs/5/html/Deployment_Guide|-en| -US/s1-system-config-lvmi|Show the package information.html system-config-lvm] (Tutorial)*[http://linuxmanpages.com/man8/lvextend.8.php lvextend]| | *[http://linuxmanpages.com/man8/resize2fs.8.php resize2fs]|-*[http://linuxmanpages.com/man8/lvcreate.8.php lvcreate]| -f filename*[http://linuxmanpages.com/man8/lvreduce.8.php lvreduce]| *[http://linuxmanpages.com/man8/pvcreate.8.php pvcreate]| *[http://linuxmanpages.com/man8/vgextend.8.php vgextend]| |-*[http://linuxmanpages.com/man8/mount.8.php mount]|packagename*[http://linuxmanpages.com/man8/umount.8.php umount]|Select just this package*[http://linuxmanpages.com/man8/yum.8.php yum]|select-option*[http://linuxmanpages.com/man8/rpm.8.php rpm]|
|}
==Resources on the web==Additional links to tutorials and HOWTOs:'''Please read this page to get an overview of LVM:'''<br /><br />:* [[Logical Volume Management]] ('''Note:''' It is recommended to return to this guide as a reference when performing Answer the next several investigations):* [http://fedoranews.org/alex/tutorial/rpm/ Using the RPM Utility]:* [http://www.centos.org/docs/5/html/yum/ Using the YUM Utility]   =Logical Volume Management (Introduction)= == Check Current LVM Information Prior to Performing Investigations == '''LVM''' ('''Logical Volume Management''') is used to manage hard disk drives / partitions for Unix/Linux systems. LVM provides more flexibility than just working with hard disks / hard disk partitions. '''Volume Groups''' are areas used to define '''Physical Volumes''' (i.e. hard disks, disk partitions, or other forms of storage devices). '''Logical Volumes''' are then used to relate directories (mount points) to a specific physical volume or for a "range" or "span" of physical volumes. Therefore, LVM allows more flexibility and growth potential for Linux systems (for example, having Logical volumes span multiple hard disks). CentOS uses LVM by default upon installation. Other Linux distributions may provide the capacity to install LVM, or later install and then use Logical Volume Management. '''Although the concept of LVM is simple, it takes practice and preparation (or "thinking ahead") in order to correctly use this valuable tool'''. It is important for students to gain an understanding of LVM, and how to manage their filesystems using LVM. It is recommended for students to read the following resource prior to this lab and/or return to the following resource while performing this lab: [[Logical Volume Management]] At this point, having completed [[OPS235 Lab 2 - CentOS6|Lab 2]] you should have roughly the following disk storage setup: ('''Note:''' These results are output from the '''vgs''', '''pvs''', and '''lvs''' commands that provide volume group, physical volume and logical volume information for each of the virtual machines that you created in lab2. Before proceeding, check these values with your own system to see if you are generally "on the right track".) * '''centos1'''  VG #PV #LV #SN Attr VSize VFree vg_centos1 1 2 0 wz--n- 9.50g 0  PV VG Fmt Attr PSize PFree /dev/vda3 vg_centos1 lvm2 a-- 9.50g 0  LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv_root vg_centos1 -wi-ao 8.03g lv_swap vg_centos1 -wi-ao 1.47g  * '''centos2'''  VG #PV #LV #SN Attr VSize VFree vg_centos2 1 3 0 wz--n- 19.51g 7.77g  PV VG Fmt Attr PSize PFree /dev/vda2 vg_centos2 lvm2 a-- 19.51g 7.77g  LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv_home vg_centos2 -wi-ao---- 1.95g lv_root vg_centos2 -wi-ao---- 7.81g lv_swap vg_centos2 -wi-ao---- 1.97g  * '''centos3 (Note: This VM has no GUI installed)''' VG #PV #LV #SN Attr VSize VFree vg_centos3 1 3 0 wz--n- 14.51g 4.54g  PV VG Fmt Attr PSize PFree /dev/vda3 vg_centos3 lvm2 a-- 14.51g 4.54g  LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv_home vg_centos3 -wi-ao---- Investigation 1.00g lv_root vg_centos3 -wi-ao---- 8.00g lv_swap vg_centos3 -wi-ao---- 992.00m * '''c6host (i.e. "removable hard disk" or "disk pack")''' Does not use LVM. Confirm this using the same commands used above. {{Admonobservations /note|VM Backups and Recovery|Most of these investigations will take place table contents in your virtual machines. If you make a significant mistake, your virtual machine may not bootlab log book. Remember that you created backups of your virtual machines in Lab 2, and you can restore them if something goes wrong.<br /><br />'''Remember: if you did not create backups for all of your VMs, then you don't have any restoration points to fall-back to!'''|}} == Investigation 4: Extend the size of lv_root using command-line tools == Perform this investigation in centos3. Let's say that you have run out of disk space on your computer (centos3), you need more space on the root filesystem, perhaps to host more webpages or a larger database or new software. What are your options? Getting a replacement harddrive would probably require reinstallation of the operating system and backup/restore of the data. Because we're using LVM though - we can avoid that. We can add a new harddrive (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. '''Perform the following operations to increase the size of lv_root in centos3:'''
<u>'''<font>Steps== Investigation 2:</font>'''</u>How do you install and remove software with RPM? ==
<ol> <li>Run # Use the graphical file manager (Nautilus) to change to the following commands and make note of directory on your Installation DVD. Go to the outputsub-directory called '''Packages'''. It should contain a file called:</li> <code>ls /dev/vd* pvs vgs lvs df lynx-2.8.6-h27.el6.x86_64.rpm</code> # Execute the following command: <licode>Open the centos3 virtual machine consolerpm -i lynx-2.8.6-27.el6.x86_64.rpm</licode> <li>Go # Issue an RPM query to check that lynx is installed. Record this command in your lab log-book.# Issue the hardware details viewfollowing command: </licode> <li>Click "Add Hardware" and add a new storage device of 2GBs, make sure it's a VirtIO disk.rpm -e lynx</licode> <li>Go back # Issue an RPM query to the console view</li>verify that lynx is no longer installed. Record this command in your lab log-book. <li>Run # Issue the same ls following command (performed in step 1), what's changed?</li>: <licode>Now we'll make the new device as a physical volume, add it to the volume group, and extend lv_root:rpm -i elinks-0.12.rpm</li> <code>pvcreate /dev/vdb. Did it work? Explain in your lab log-book why this command may not have worked.
vgextend vg_centos3 '''Answer the Investigation 2 observations /dev/vdbquestions in your lab log book.'''
lvextend -L +2G -r vg_centos3/lv_root</code> <li>Now rerun the ls/pvs/vgs/lvs/df commands. What has changed == Investigation 3: How do you install and what caused those changesremove software with ''yum''?</li> <li>Among the changes, note that your root filesystem is now 2GB bigger - and you have not even rebooted your machine!</li></ol>==
'''Answer {{Admon/note|Internet Connection|In order for yum to work you require a connection to the Investigation 4 observations / questions in your lab Internet. Establish this connection by using the browser to log book.'''into SeneNET}}
== Investigation 5: How is LVM managed using system-config-lvm? ==# Change to your home directory.
'''Perform this investigation on the VM named ''<u>centos2</u>''.'''
[[Image:Ops235_lab4_1.png|thumb|right|Screenshot of system-config-lvm in CentOS. Click to enlarge.]]
# Let's learn to administer (manage) our LVM graphically for our '''centos2''' Virtual Machine.<br />CentOS provides a tool called <code>system-config-lvm</code> to graphically administer LVM. The package is not installed by default, so you will need to install it by issuing: (<code>yum install system-config-lvm</code>).
<ol>
<li value="2">Use this tool to determine the current LVM configuration by clicking on the appropriate element and reading Issue the properties in the right-hand panel -- write down the answerscommand: <ol type="a"code> <li>What are the names and sizes of the '''PV'''s?yum install elinks</licode> <li>What is the name and size of the '''VG'''?</li> answer <licode>What are the names and sizes of the '''LV'''s?y</licode> <li>Is there any space in the VG which is not allocated to a LV?</li> </ol> </li> <li>Increase the size of the home file-system to '''4 GB''':question about installation.
<ol type="a">
<li>Click on the LV containing the Where did ''yum'home''' filesystem.</li> <li>Click on ''Edit Properties''.get the elinks software?</li> <li>Change the size to '''4 GB''Why could ' and click 'yum'Ok'install elinks when rpm couldn'.t?</li>
</ol>
</li> <li>Create a '''new 3G LV''' (LV Properties: linear) containing Issue an ext4 filesystem named lv_archive and mount it at '''RPM query to verify that elinks is installed. Record this command in your lab log-book.</archive'''li> <li>Backup Issue the command: <code>'''yum remove elinks</code></etc'''li> <li>Issue an RPM query to verify that elinks is no longer installed. Record this command in your lab log-book.</codeli> <li> into Issue this command: <code>'''/archive'''yum info cups</code></li>
</ol>
::* Copy Based on the files in /etc into the filesystem mounted at <code>/archive</code><br />(use the graphical tools or the command line. result, do you think that cups is a useful package for your system? If using cpnot, remember to use the -R option)try removing it.
<ol>
<li value="68">Shrink the size of <code>lv_archive</code> to '''1 GB''Unused and unneeded software can present a security risk and ties up disk space needlessly. Find at least 4 other packages (for example: games, sound & video, etc) that you're not using on your system, and remove them.</li> <li>Try shrinking the home file-systemBe careful to ensure that removing those packages does not also remove other software that you do need. What happens? Why?</li>
</ol>
'''Answer the Investigation 5 3 observations / questions in your lab log book.'''
= Storage Setup (prior to starting Lab 4) =Archiving Files / Compiling Software from Source Code==
At Archive files are often used to contain source code for software; in this point, having completed [[OPS235 Lab 3 - CentOS6|Lab 3]] lab you should have <u>'''roughly'''</u> the following disk storage setup:<br />('''Note:''' These results are output will also be compiling software from the '''vgs''', '''lvs''', and '''pvs''' commands within each virtual machinea source code archive. You will be using these commands in the following lab investigations)<br /><br />
* '''centos1'''{{Admon/note|Do not Shut-Down VMs Until Instructed|You will be running all 3 VMs eventually when performing this tutorial, Leave all VMs running until you are instructed to shut them down at the end of this lab.|}}
This VM has a GUI and no free space in the VG. VG #PV #LV #SN Attr VSize VFree vg_centos1 ===Investigation 1 2 0 wz--n- 9.80G 0 LV VG Attr LSize lv_root vg_centos1 -wi-ao 8.83G : How do you create an archive file?=== lv_swap vg_centos1 -wi-ao 992.00M PV VG Fmt Attr PSize PFree {{Admon/dev/vda2 vg_centos1 lvm2 a- 9note|Use centos3|Perform these steps in the '''centos3''' virtual machine.80G 0}}
* #Boot up your '''centos2centos3'''VM.#Change your working directory to <code>/usr/share/doc/sudo*</code>#Use the tar (tape archiver) command to create an archive file named <code>/tmp/archive1.tar</code>#*<code>tar cvf /tmp/archive1.tar .</code>
This VM has a GUI and free space in {{Admon/important | Warning! | Don't miss the VG'''. VG #PV #LV #SN Attr VSize VFree vg_centos2 1 4 0 wz--n- 19.51g 4.73g LV VG Attr LSize lv_archive vg_centos2 -wi-ao---- 1.00g lv_home vg_centos2 -wi-ao---- 4.00g lv_root vg_centos2 -wi-ao---- 7.81g lv_swap vg_centos2 -wi-ao---- 1.97g PV VG Fmt Attr PSize PFree ''' at the end of the <code>tar</dev/vda2 vg_centos2 lvm2 a-- 19.51g 4code> commands below! It specifies what should go into the archive: the contents of the current directory.73g}}
<ol> <li value="4">What do the options c, v, and f mean?</li> <li>Record the archive file size.</li> <li>Compress the file using <code>gzip</code>: <ul> <li><code>gzip /tmp/archive1.tar</code></li> </ul> </li> <li>Record the archive file size after compression.</li> <li>Make sure you're still in <code>/usr/share/doc/sudo* '''centos3'''</code> and then create a compressed archive:<ul> <li><code>tar cvzf /tmp/archive2.tgz .</code></li> </ul> </li> <li>What does the <code>z</code> option do?</li> <li>Compare the sizes of <code>/tmp/archive1.tar.gz</code> and <code>/tmp/archive2.tgz</code>. Why are they so close in size?</li></ol>
This VM has no GUI installed. VG #PV #LV #SN Attr VSize VFree vg_centos3 2 3 0 wz--n- 16.50g 0 LV VG Attr LSize lv_home vg_centos3 -wi-ao---- '''Answer the Investigation 1.00g lv_root vg_centos3 -wi-ao---- 10.00g lv_swap vg_centos3 -wi-ao---- 992.00m PV VG Fmt Attr PSize PFree observations /dev/vda3 vg_centos3 lvm2 a-- 14.51g 2.54g /dev/vdb vg_centos3 lvm2 a-- 2.00g 2questions in your lab log book.00g'''
* ===Investigation 2: How do you restore files from an archive?==={{Admon/note|Remain in your centos3 VM|Perform these steps in the '''centos3'''c6host (ivirtual machine.}}#Create the directory <code>/tmp/extract1</code>#Change to the <code>/tmp/extract1</code> directory.#Move the file archive1.tar.gz to your current directory.#Unzip the first archive you created:#*<code>gunzip archive1.tar.gz</code>#Extract the files from the first archive:#*<code>tar xvf archive1.tar</code>#Are all the files there? #Compare <code>/tmp/extract1/README</code> and <code>/usr/share/doc/sudo*/README</code>. Are they exactly the same? Why?#Create the directory <code>/tmp/extract2</code>#Move the file archive2.tgz to the <code>/tmp/extract2</code> directory.#Extract the files from the second archive:#*<code>tar xvzf /tmp/extract2/archive2.etgz</code>#Note that this time a separate <code>gunzip</code> command was not needed. Why?#Repeat the previous command, leaving out the option "disk packz")'''. Does it work? Why?#Compare the <code>README</code> file in this directory with the original file. Are they exactly the same?
'''Answer the Investigation 2 observations /dev/sdc3 20G 3.7G 15G 20% / /dev/sdc2 29G 4questions in your lab log book.7G 23G 18% /home /dev/sdc1 97G 48G 45G 52% /var/lib/libvirt/images'''
= Logical Volume Management (Continued) ==Investigation 3: How do you build software from source code?===
Now that you know how to create and decompress "zipped tarball archives", we will demonstrate how to install applications from websites containing these types of archives. Although this method is not as "user-friendly" as using the yum or rpm command, this method is useful if the application is NOT contained in regular software repositories...{{Admon/note|Recovering VMsUse centos2|Perform these steps in the '''Most of these investigations will take place in you virtual machines.centos2''' If you make a significant mistake, your virtual machine may not boot. Remember that you created backups of your virtual machines in Lab 3, and you can '''restore them if something goes wrong'''.}}
== Resources ==In order to build software from source code, you must have the appropriate software development tools (such as make and gcc) and libraries (such as GTK) installed. The required tools will vary depending on the computer languages used in the software being built.
Please read this page # Issue the following command to get an overview install a basic set of LVMdevelopment tools and libraries:[http://zenit.senecac.on.ca/wiki<br /index.php><code>yum groupinstall "Development Tools" "Development Libraries"</Logical_Volume_Management Logical Volume Management]code>
It is recommended to open another window(eg{{Admon/note|Installing Development Libraries|In the future, remember the above procedure whenever installing software from source. '''right-click'''Sometimes, '''open you need to install additional tools or libraries in new tab or window''') order to make reference to view LVM commands as you perform investigations 1 to 3.compile a particular software package}}
<ol> <li value== Investigation 1: How are LVMs are managed using Command-Line Tools =="3">Go to the directory <code>/tmp</code></li># You are going <li>Use the <code>wget</code> command to repeat download the same LVM management operations (as your did with "tar ball" that contains the ''centos2'' VM in '''lab3'''), but you will using command-line tools in source code for the '''centos3''' VMNLED text editor. Since the centos3 VM only operates in <code>wget</code> is a command-line mode, you will need to refer tool to download files from the web using the '''"Logical Volume Management"''' link abovehttp or ftp protocols.# Write down the exact commands used at each step, and record appropriate command output: <ul>:: a. Determine the current LVM configuration using the <codeli>pvs</code>, wget http://cdot.senecac.on.ca/software/nled/nled_2_52_src.tgz</code>vgs</codeli>, and <code/ul>lvs </codeli> commands.:: b <li>Extract the files.Grow the home filesystem Change to 2G using the command newly-extracted directory (<code>lvextend/tmp/nled-2.52</code> and )</li> <li>Check to see if there is a file named <code>resize2fsconfigure</code>.If so, run it; if not, skip this step. (Most but not all source code archives contain this file)</li>:: c.Create <li>Check to see if there is a new 2G LV containing an ext4 filesystem and mount it at /archive (use file named <code>mkdirMakefile</code>, or <code>lvcreatemakefile</code>. If so, type the command: <ul> <li><code>mkfsmake</code>, <code/li>mount </codeli>, edit Did the command work? Why? Use the file <code>/etc/fstabyum</code> (read command to install the resource: [https://wikipackage '''gcc'''.archlinux.orgWhat do you think the package ''gcc'' does?</index.phpli> </fstab https://wiki.archlinux.org/index.php/fstab] ), and then reboot to confirm automatic mount).ul>:: d.Copy <li>Reissue the contents of <code>/etcmake</code> into command. Where you successful? What does <code>make</archivecode> do?</codeli>. <li>Issue the command as root:: e.Shrink <code>lv_archiveyum list ncurses</code> to 1G (use . What do you see? Issue the command at root: <code>umountyum search ncurses</code>, . What do you observe?<code/li>resize2fs </codeli>In this case, you need to install the ncurses development libraries as well. Issue the following command as root: <code>lvreduceyum install ncurses-devel.x86_64</code>, and . Now issue the command: <code>mountmake</code>) == Investigation 2: How can a PV be added to an existing VG using Command-Line Tools? ==# Add an additional 2 GB virtual disk to your ''<u/li>centos1 </uli>'' system, we will use it Some software distributed as an additional physical volumesource code can automatically install itself.# Do the rest of Try this investigation in the command line.: <ul># You should now have both <li><code>/dev/vdamake install</code> and <code/li> </dev/vdbul> </codeli>.# Record <li>Most but not all source code archives include the size capability of the volume group and the amount of free space (Hint: use a command that you learned in a previous lab)installing themselves this way.</li># Read <li>If the resource [http:command <code>make install<//tldp.org/HOWTO/Partition/fdisk_partitioning.html Partitioning with fdisk] to learn code> does not work (how to properly create a partition with the fdisk can you tell? What command.# Use fdisk did you learn from ULI101 to partition /dev/vdb with a Linux single partition confirm that fills this command cannot be run from the whole disk.# Check command line?), copy the messages printed when <code>fdisknled</code> exits -- you may need to reboot the system in order for the new partition table to take effect.program manually:# Mark ''vdb1'' as a physical volume usable by LVM. <ul># Add the new physical volume to the existing volume group.# Verify that the volume group is larger and has more free space. {{Admon/note|Think!|The next part of this investigation requires some research, thought, and creativity.}}'''Using that additional space, create a separate filesystem for <li><code>cp nled /homeusr/local/bin</code>:'''</li># Create the logical volume <code/ul>lv_home </codeli> (1G ext4)# Find a way to move the contents of <li>Test <code>/homenled</code> onto to make sure itworks.</li># Change your system configuration so that <li>Why did copying the nled executable to /usr/local/bin allow the nled command to be run by name anywhere in the new filesystem is mounted on command prompt?<code/li>/home</codeol> from now on.
{{Admon'''Answer the Investigation 3 observations /tip|SELinux relabelling may be required|Your system may report that the files are not present questions in the new /home filesystem when they are clearly there. This is due to the Security-Enhanced Linux system (SELinux) preventing access to the files, because the files were tampered with (moved) and are no longer recognized as home directory contentyour lab log book. You can fix this problem by restoring the file context labels so that SELinux accepts the files as valid home directory content: <code>restorecon -r /home</code>}}'''
== Investigation 3: How can I use fdisk to manage storage on my disk pack? ==
'''On your <u>c6host</u> (i.e. "disk pack"), using your choice of the GUI and/or command-line tools:'''
# Create a new partition or logical drive ('''NOT a logical volume!''') - minimum 5G, leaving at least 10G free space in the extended partition.
# Format that partition (i.e. put a filesystem on it).
# Make sure it's mounted automatically on a mountpoint of your choosing (easiest is to create a new directory for a mountpoint).
= Updated backup instructions =
If you completed this lab correctly - please make sure you are still making full backups of your virtual machines.
Remember adding a new harddrive to centos3? You will need to back up that drive as well. If you don't - you will only have half of your machine backed up, which is of no use for a recovery.
= Completing the lab =
13,420
edits

Navigation menu