Changes

Jump to: navigation, search

OPS235 Lab 2 - CentOS7 - VMware

40,897 bytes removed, 12:56, 15 September 2016
Redirected page to OPS235
[[Category:OPS235]]  = LAB PREPARATION =[[Image:vmware-1.png|thumb|right|300px|At the end of lab2, your VMware Workstation application will contain '''4 virtual machines'''. You will now have the option to run one virtual machine at a time, or run all machines simultaneously to learn about networking (covered in later labs) ]] === Purpose / Objectives of Lab2=== '''In this lab, you will create another three virtual machines''' to learn how to install Centos Linux in different ways including network installs.<br><br><u>Main Objectives</u> * '''Create 3 separate VMs (virtual machines) using different installation methods:''':* Centos Live DVD (with Install to Harddisk program):* Network Centos Installation without configuration file:* Network Centos Installation with configuration file (Kickstart)* Understand the '''advantages and disadvantages of each type of installation''', and be able to '''select the best installation method''' for a particular situation.* Create and run '''Bash Shell scripts''' to automatically create a post-install report for an installed VM.  {|width="100%" cellspacing="0" |- valign="top" |colspan="2" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;"|Minimum Required Materials<br> |colspan="3" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;"|Linux Command Reference<br>|- valign="top" | |[[Image:ubs-key.png|thumb|left|85px|<b>USB key</b><br>(for backups)]] | |[[Image:log-book.png|thumb|left|70px|<b>Lab2 Log Book</b>]] | valign="top"|Package Management<br>[http://www.rpm.org/max-rpm/rpm.8.html rpm]<br>[http://man7.org/linux/man-pages/man8/yum.8.html yum]<br>System Information<br>[http://man7.org/linux/man-pages/man1/hostname.1.html hostname]<br>[http://man7.org/linux/man-pages/man1/uname.1.html uname]<br>[http://man7.org/linux/man-pages/man1/ps.1.html ps]<br>[http://man7.org/linux/man-pages/man8/lsblk.8.html lsblk]<br>Networking<br>[http://man7.org/linux/man-pages/man8/ifconfig.8.html ifconfig]<br>[http://man7.org/linux/man-pages/man8/netstat.8.html netstat]<br>[http://man7.org/linux/man-pages/man8/route.8.html route]<br>[http://linux.die.net/man/1/nslookup nslookup]<br>|width="15%" valign="top"|Miscellaneous<br>[http://unixhelp.ed.ac.uk/CGI/man-cgi?gzip gzip, gunzip]<br>[http://unixhelp.ed.ac.uk/CGI/man-cgi?grep grep]<br>[http://man7.org/linux/man-pages/man1/wc.1.html wc]<br>[http://man7.org/linux/man-pages/man1/pwd.1.html pwd]<br>[http://man7.org/linux/man-pages/man1/ls.1.html ls]<br>[http://man7.org/linux/man-pages/man1/more.1.html more]<br>[http://man7.org/linux/man-pages/man1/file.1.html file]<br>[http://man7.org/linux/man-pages/man1/wget.1.html wget]<br>[http://man7.org/linux/man-pages/man1/chmod.1.html chmod]<br>[http://ss64.com/vi.html vi]  ||Linux Command Reference:<br><ul><li>Shell Scripting - Part I (Scripting Basics):<br>'''/home/murray.saul/scripting-1'''<br>Shell Scripting - Part 2 (Logic & Math Expressions):<br>'''/home/murray.saul/scripting-2'''</li><li>Shell Scripting - Part 3 (Loops)<br>'''/home/murray.saul/scripting-3'''</li></ul> |}  =INVESTIGATION 1:CREATE OTHER VIRTUAL MACHINES (INSTALL COMPARISON)===Virtualization Application Setup / Comparison Chart== '''Record VM Installation in Lab2 (Installation Comparison Chart):''' You will be learning to perform several different type of CENTOS Linux installs. Lab2 has a '''comparison chart''' for comparing various Linux installs. You were required in lab1 to record your observation for your '''centos1''' installation. As you proceed throughout this lab, you will be required to fill in the comparison chart for the remaining 3 virtual machines that you will be installing.  == Part 1: Installing from a Downloaded Image (Centos7 LIVE CD) =={| width="40%" align="right" cellpadding="10"|- valign="top"|{{Admon/tip|Perform Downloads and Network installs at Seneca|'''It is recommended to perform this lab in one of Seneca College's labs'''. This lab uses servers which are on the Seneca network and which are not available from other locations (such as your home). If you attempt this lab from another location, adjust the belmont.senecac.on.ca URLs to point to another mirror server -- note that you may need to change the directory name as well as the server name. The installation of the '''centos4''' virtual machine <u>must</u> be done at Seneca.}}|} :'''VM Details:''' :: '''VM Name (and hostname):''' centos2:: '''Boot media:''' LIVE CD Image (downloaded iso file):: '''Installation source:''' Downloaded Centos7 LIVE CD image (http://belmont.senecac.on.ca/centos/7/isos/x86_64/CentOS-7-x86_64-LiveGNOME-1511.iso):: '''VM Image Pathname:''' /var/lib/libvirt/images/centos2.img:: '''Memory:''' 2GB:: '''Disk space:''' 10GB:: '''File System (root partition):''' ext4:: '''CPUs:''' 1 You do not need to burn a DVD for the Centos7 install image. You can simply download an image file (.iso), and refer to this downloaded image in order to install the Linux OS. This is the second method of installation that we will now investigate. # Open a web-browser, click on the link below to save on your Windows machine in your Seneca Lab (Downloads section).<br><br><b><code><span style="color:#3366CC;font-size:1.2em;">http://belmont.senecac.on.ca/centos/7/isos/x86_64/CentOS-7-x86_64-LiveGNOME-1511.iso</span></code></b><br><br># Launch the VMWare Workstation application.# Click on the icon to ''Create a New Virtual Machine'' and select '''Custom (Advanced)'''. [[Image:vm-path.png|thumb|right|300px|When your '''centos2''' LIVE machine boots-up, immediately double-click on the '''Install to Hard Disk''' icon to run the installation program.]]<ol><li value="4">'''The virtual machine will now start'''.</li><li>Immediately double-click on the icon called '''Install to Hard Disk'''.</li><li>Start timing your installation and making notes for '''centos2''' virtual machine in the '''installation comparison chart in lab2 logbook'''.</li><li>Select your downloaded iso Centos7 Gnome LIVE image (under ''Downloads'' folder) and click '''Next'''. Basically, you perform the same steps is in lab1 (i.e. select '''Custom (Advanced)''' with '''2 GB of RAM''', the VM name will be called '''centos2''' and the Hard Disk size will be '''10 GB''' (not 20GB). </li><li>When your VM boots-up, Double-click '''Install to Hard Drive'''. The installation program, similar to the one used when installing CentOS in Lab 1, will appear. You basically perform the same installation operations for this VM including for '''Date & Time''', '''Network & Hostname''', and '''Installation Destination'''. Make certain to use the '''hostname''': '''<u>centos1</u>''' as opposed to ''c7host'') for this installation. (with a few slight differences).</li><li>For '''Installation Destination''', select the destination option: '''I will configure partitioning''' and then click '''Done'''. Make certain that the '''Partition Scheme''' is set to '''LVM''' and then click on the link: '''Click to Create Automatically'''. '''Done'''. Check to make certain that the root partition has file system type: '''ext4'''.</li><li>Accept the changes and then click '''Begin Installation'''.<ol type="a"><li>You will be required to make selections very similar to what you did in lab1.</li><li>While the system is installing, take a few minutes to record your observations (including slight differences with centos1 install as opposed to c7host install).</li><li>When the installation process is complete, note the time required to install this system and record in the installation comparison chart of your lab2 logbook.<br><br></li></ol></li><li>Power-off your Centos7 LIVE system.</li><li>Restart your centos2 VM, and enter 1, 2, c, c, like you did in lab1.</li><li>Finish the final steps in the setup process (like you did in lab1).</li><li>It is recommended that you turn off the screen-saver (like you did in Lab1: [http://zenit.senecac.on.ca/wiki/index.php/OPS235_Lab_1_-_CentOS7#Turn-Off_Screen_Saver_Lock Turn-off Screen Saver Lock]).</li></ol>{| width="100%" align="right" cellpadding="10"|- valign="top"|colspan="2"|{{Admon/important|Important Network Service Tasks|Please perform the tasks below in order allow these CentOS systems to be able to communicate with each other. '''Failure to properly perform these operations can cause problems in future labs'''.|}}|}<ol> <li value="20">Make certain to '''disable SELinux for centos2''' ([http://zenit.senecac.on.ca/wiki/index.php/OPS235_Lab_1_-_CentOS7_-_VMware#Disable_SELinux_and_Perform_Software_Updates refer to lab1])</li><li>Start and enable the SSH server to allow access to your virtual machine with these commands (semi-colon allows commands to be run in sequence):<br /> <b><code><span style="color:#3366CC;font-size:1.2em;">systemctl start sshd; systemctl enable sshd</span></code></b></li> <li>Find out the IP address of your virtual machine and the name of your Ethernet network adaptor: <b><code><span style="color:#3366CC;font-size:1.2em;">ifconfig</span></code></b> </li> <li>Enter the following command on your virtual machine to create a firewall exception to allow ssh traffic into the machine:<br /> <b><code><span style="color:#3366CC;font-size:1.2em;">iptables -I INPUT -p tcp -s0/0 -d0/0 --dport 22 -j ACCEPT</span></code></b></li><li>If you are logged in as root, logout to your regular user account.</li><li>Confirm that you can ssh to your virtual machine from the host (your main CentOS installation): <b><code><span style="color:#3366CC;font-size:1.2em;">ssh regularuserid@IPaddress</span></code></b> (where '''regularuserid''' is your regular user login id, and '''IPaddress''' is the '''IP_ADDRESS''' of your '''centos2''' VM!).</li></ol> {{Admon/important|Remember to Backup your VM to USB Key!|Remember that you need to backup your '''centos2''' VM to your USB key before you leave your Seneca lab, or you will lose your work!}} == Part 2: Installing from a Network =={| width="40%" align="right" cellpadding="10"|- valign="top"|colspan="2"|{{Admon/important|Authenticate to the network|The rest of this lab uses network access.''' Be sure to authenticate to the network using your browser before proceeding'''.}}|} :'''VM Details:''' :: '''VM Name (and hostname):''' centos3:: '''Boot media:''' Network installation:: '''Installation source URL:''' http://belmont.senecac.on.ca/centos/7/os/x86_64/:: '''VM Image Pathname:''' /var/lib/libvirt/images/centos3.img:: '''Memory:''' 2048MB:: '''Disk space:''' 20GB:: '''CPUs:''' 1  # Create the VM (called '''centos3''') as you did with the ''centos1'' machine, except for the following differences:<br><br><ol type="a"><li>Select '''Network Installation''' using the installation source URL displayed above.</li><li>When customizing your partitions, do the same operation that you did in centos2, but after automatically creating the partitions, reduce the size of the root LVM partition to '''8000 MB''' and add an LVM partition with a size of '''2000 MB''' (mount point: '''/home''', name: '''home''', and make certain root and /home partitions have '''ext4''' file system).</li><li>Don't forget to install the GNOME desktop here as you will need a GUI for Centos3<br><br></li></ol># Complete the installation. Login to your regular user account, and perform a yum update for the centos3 VM (reboot if required). Make certain to adjust your screen-saver settings if desired.# Repeat the steps as you did to '''start the SSH service''', '''set iptables to accept connections via ssh''', '''test connections between centos3 and centos1''', and '''disable SELinux''' (refer to lab1).# Record the time taken to install, and compare this to the time taken by the previous installations. Record your findings in the Installation Comparison chart in lab2 logbook. {{Admon/important|Remember to Backup your VM to USB Key!|Remember that you need to backup your '''centos3''' VM to your USB key before you leave your Seneca lab, or you will lose your work!}} == Part 3: Installing from a Network using a Kickstart File == :'''VM Details:''' :: '''VM Name (and hostname):''' centos4:: '''Boot media:''' Network installation:: '''Installation source URL:''' http://belmont.senecac.on.ca/centos/7/os/x86_64/:: '''Kickstart File URL:''' http://matrix.senecac.on.ca/~andrew.smith/ops235/centos7-kickstart-v01.cfg:: '''VM Image Pathname:''' /var/lib/libvirt/images/centos4.img:: '''Memory:''' 2048MB:: '''Disk space:''' 15GB:: '''CPUs:''' 1  # Create the VM as you did with the ''centos3'' virtual machine, specifying a network install as before, but specify the kickstart location under the "options section" for network install. What do you think is the purpose of this kickstart file?# Observe the installation. How is it different from booting from a downloaded image?# Complete the installation. Record the time taken to install, and compare this to the time taken by the previous installations.<br><br>If the during the installation, you see the message at the bottom '''Pane is Dead''', click the '''Virtual Machine''' menu at the top, select '''Shut Down''' -> '''Force Off''', '''right-click''' on '''centos4''' in the ''virtual manager'' window and select '''Delete'''. Redo the VM setup for a new instance of the ''centos4'' VM.# What happens when the installation is finished?# Take a look at the kickstart file (eg. view url in a webj-browser) to determine the root password as well as the name and password for the first user account!# Boot the virtual machine and log in (use the user ID and password information from the previous step). Compare the experience to the first time you booted the other virtual machines. Record this information in the '''table contained in Investigation 4'''.# Repeat the steps as you did to '''start the SSH service''', '''set iptables to accept connections via ssh''', '''test connections between centos4 and centos1''', and '''disable SELinux''' (refer to lab1).# Remember that centos4 is text-based interface only (no graphics). To recover from a blank screen, press a key (like the SPACE key) to return to the screen display.# Record the time taken to install, and compare this to the time taken by the previous installations. Record your findings in the Installation Comparison chart in lab2 logbook.  '''Answer the Investigation 1 observations / questions in your lab log book.''' {{Admon/important|Remember to Backup your VM to USB Key!|Remember that you need to backup your '''centos3''' VM to your USB key before you leave your Seneca lab, or you will lose your work!}} =INVESTIGATION 2: COMMON POST-INSTALL TASKS= ==Part 1: Perform Software Updates=={|width="40%" align="right" cellpadding="10"|- valign="top"|{{Admon/caution|Allow Time to Perform Yum Updates|Allow sufficient time in order to perform updates prior to the end of the lab. Since you will be updating ALL of your VMs, allow 15-20 "lead-time" to start your updates and to backup your VMs prior to the end of the lab. NEVER force a shut-down of your VM while updates are running, since this will ruin your VM, and you will have to restore from a backup, or redo your labs for that VM!}}|} It is important as a Linux System Administrator to update software on your Linux system periodically. Performing periodic updates will fix software bugs and inefficiencies as well as apply security patches in order to better secure your Linux server. '''You are required to perform the following command for ALL of your 4 VMs:''' <b><code><span style="color:#3366CC;font-size:1.2em;">yum update</span></code></b>  This will download and install all of the packages that have been updated since the installation DVD image was created. If you complete this command at Seneca, it should run quite fast as Seneca College hosts a CentOS Repository mirror (a copy of all of the current CentOS packages, on a local web server). You will be reminded at the end of each of the remaining labs to perform software updates on ALL of your VMs.    ==Part 2: Accessing Administrative Priviledges=={|width="40%" align="right" cellpadding="10"|- valign="top"|{{Admon/note|Accessing the Administration Account (root)| Many administrative tasks require the root administrative account. There are many ways to access this administration account:<ul><li>Login: '''root''' (enter root password)</li><li>Switch User to root (without login):<ul><li>'''su''': Remains in regular user's directory, does not run root's startup script(s).</li><li>'''su -''' : Changes to root's home directory (/root) and runs root's start script(s).</li></ul></li></ul>}}|} Navigate through your Graphical CentOS system, '''locate and run a terminal program (in order to issue Linux commands). Issue and record the commands used and the output generated in each of the following steps:''' #With older (ancient) versions of Linux, a user once may have been allowed to login to their graphical Linux system using '''root''' as their user-name and their root password. This has been determined to be a security risk and that option has been removed with many or all Linux operating systems.#Therefore, from this point onwards, you will be logging into your regular user account instead and issuing a command to login as the ''root'' user. #Refer to the Information box regarding how to access the admin account from the command line.#Issue the command <b><code><span style="color:#3366CC;font-size:1.3em;">su </span></code></b> Issue the '''pwd''' and '''whoami''' commands to confirm your directory pathname. When finished logout of this account.#Issue the command <b><code><span style="color:#3366CC;font-size:1.3em;">su - </span></code></b> Issue the '''pwd''' and '''whoami''' commands to confirm your directory pathname. What do you notice are the main differences between using '''su''' versus using '''su -''' ?# An installation log file called <b><code><span style="color:#3366CC;font-size:1.2em;">/var/log/anaconda/packaging.log</span></code></b> has been created to record the installation of your centos1 machine. This file is an ASCII file which can be viewed with the <b><code><span style="color:#3366CC;font-size:1.2em;">more</span></code></b> command. # You can make use of this file to determine how many packages have been installed: complete the following command to count the number of packages that are labelled "Installing" in the installation log file::: <b><code><span style="color:#3366CC;font-size:1.2em;">grep -i packaging /var/log/anaconda/packaging.log | wc -l'''</span></code></b>  ==Part 3: Common Post-Install Commands &amp; Shell Scripting=={|width="40%" align="right" cellpadding="10"|- valign="top"|{{Admon/note|Bash Shell Scripting Reference Guide:|<br>'''<u>She-bang Line</u>'''<ul><li>Forces shell script to run in a specific Shell</li><li>Some shell syntax not backward compatible</li><li>'''#!''' must be at beginning of first line of shell script</li><li>Example: '''#!/bin/bash'''<br><br></li></ul>'''<u>Variables</u>'''<br><blockquote>'''Environment'''<ul><li>System-wide or "global" variable</li><li>Usually appear in UPPERCASE letters</li><li>Can view with command: '''set &#124; more'''</li><li>'''$''' in front to expand variable to value<li>Examples: '''USER''', '''PATH''', '''HOME''', '''SHELL'''<br></li></ul></blockquote><blockquote>'''User-defined''' <ul><li>Variable created by user (command line, scripting)</li><li>Examples:<br>''myVar&#61;"my value"; readonly myVar; export myVar''<br>''read -p "enter value: " myVar''<br></li></ul></blockquote><blockquote>'''Positional parameters'''<ul><li>Assign values with set command or shell script arguments</li><li>These variables are numbered (eg. $1, $2 ... $10}</li><li>Special parameters: $*, $@, $#, $$, $?<br></li></ul></blockquote>'''<u>Command Substitution</u>'''<ul><li>Useful method to expand output from a command to be used as an argument for another command.</li><li>Examples:<br>''file $(ls)''<br>''set $(ls);echo $#;echo $*''<br>''echo "hostname: $(hostname)"''<br><br></li></ul>'''<u>Logic Control Flow Statements</u>'''<ul><li>'''$?''' variable true (0) if command runs; otherwise is false (non-zero)</li>Example:<br>''if echo $myVar &#124; grep "match"''<br>''then''<br>''echo "Match"''<br>''fi''<br></li><li>The '''test''' command is used to test conditions. Square brackets '''[ ]''' is short-cut for test command (args contained inside with spaces). The '''exit''' command can be used to terminate the shell script with a false value.<br>Example:<br>''if [ $USER &#61; "root" ]''<br>''then''<br>&nbsp;''echo "You must be root" ''<br>&nbsp;''exit1''<br>''fi''<br></li><li>For numberic comparison, use the following '''test options''':<br> '''-gt''','''-ge''', '''-lt''', '''-le''', '''-eq''', '''-ne'''<br>Examples:<br>''if test $age -gt 65 ''<br>''then''<br>&nbsp;''echo "retire"''<br>''else''<br>&nbsp;''echo "don't retire"''<br>''fi''<br><br>''if [ $grade -gt 79 ]''<br>''then''<br>&nbsp;''echo "You get Good Mark"''<br>''elif [ $grade -gt 49 ]''<br>''then''<br>&nbsp;''echo "You pass"''<br>''else''<br>&nbsp;''echo "You fail"''<br>''fi''<br></li><li>For testing for file information, you can use '''-d''' to test if directory pathname exists, and '''-f''' if the file pathname exists. You can use '''!''' for negation.<br><br>Examples:<br>''if [ -d directory-pathname ]''<br>''then''<br> ''echo "directory exists"''<br>''fi''<br><br>''if [ ! - f file-pathname ]''<br>''then''<br> ''echo "File does not exist"''<br>''fi''</li><li>'''Loops (iteration):'''<br><br>Loops and logic are a very important elements of shell scripting (not to mention programming as well). Determinant loops (such as '''for''' loops) usually repeat for a preset number of times (eg. counts, positional parameters stored). In-determinant loops (such as '''while''' or '''until''' loops) may repeat based on unknown conditions (like waiting for user to enter correct data). Test conditions can be used with in-determinant loops, or even commands! If a command runs successfully (eg ls, cd, grep matching a pattern), zero (true) value is returned, otherwise a non-zero (false) value is returned. Command options or redirection to /'''dev/null''' can be used to just test if command runs, but not display stdout or stderr. Conditional statements "and" (&amp;&amp;) / "or" (&#124;&#124;) can also be used when testing multiple conditions.<br><br>'''<u>Examples (try in a shell script)</u>'''<br><br>''set ops235 is fun''<br>''for x''<br>''do''<br>&nbsp;''echo "argument is $x"''<br>''done''<br><br>''for x in $(ls)''<br>''do''<br> &nbsp;''echo "Filename: $x"''<br>''done''<br><br>''read -p "enter a whole number: " num''<br>''until echo $num &#124; grep -q "^[0-9][0-9]*$"''<br>''do''<br> &nbsp;''read -p "Incorrect. Please enter WHOLE NUMBER: " num''<br>''done''<br><br>''read -p "pick a number between 1 and 10: " num''<br>''while [ $num -lt 1 ] &#124;&#124; [ $num -gt 10 ]<br>''do''<br> &nbsp;''read -p "Incorrect. Please pick number between 1 and 10: " num''<br>''done''<br><br></li></ul>}}|}  It is very common for System Administrators to keep records regarding their installed computer systems. For example, it is necessary to have a record of all the hardware information for each machine in order to help fix computer hardware problems, and to assist when purchasing additional consistent computer hardware. Therefore, it makes sense to also have a record of the installed computer software as well. This can contain information regarding the Linux operating system, installed software, and network connectivity information.  '''Perform the Following Steps:''' # Study the Linux commands and their purpose to note computer software information for your installed centos1 VM. You should take time to issue each of these commands to view the output, and record this chart in your lab1 logbook.<br><br># Login to your centos1 VM, open a Bash Shell terminal, and login as root by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">su -</span></code></b><br><br># Make certain to record output from these commands (except for the '''ps -ef''' output) in your lab1 logbook.  <table cellspacing="0" cellpadding="5" width="50%" style="border-top: thin solid black;margin-left:60px;"> <tr valign="top>  <td style="border-bottom: thin solid black;font-weight:bold;background-color:#ffffff;">Command(s)</td> <td style="border-bottom: thin solid black;font-weight:bold;background-color:#ffffff;">Purpose</td> </tr> <tr valign="top"> <td width="20%" style="border-bottom: thin solid black;"><b><code><span style="color:#3366CC;font-size:1.2em;">uname -rv</span></code></b><br><b><code><span style="color:#3366CC;font-size:1.2em;">hostname</span></code></b><br><b><code><span style="color:#3366CC;font-size:1.2em;">ps -ef</span></code></b></td> <td width="20%" style="border-bottom: thin solid black;">Basic Linux OS information such as '''kernel''' version, '''host-name''' of Linux server, and all '''processes''' that are running on the system after installation.</td> </tr><tr valign="top"> <td width="20%" style="border-bottom: thin solid black;"><b><code><span style="color:#3366CC;font-size:1.2em;">rpm -q -a | wc -l'''</span></code></b><br><b><code><span style="color:#3366CC;font-size:1.2em;">rpm -q -a -l | wc -l'''</span></code></b><br><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">rpm -q -l gedit | wc -l</span></code></b></td> <td width="20%" style="border-bottom: thin solid black;">Obtain number of installed packages in the rpm database. Option '''-q''' is to "query" informationo, option '''-a''' means for all installed packages, option '''-l''' means all files installed as opposed to just the application.</td> </tr>  <tr valign="top"> <td width="20%" style="border-bottom: thin solid black;"><b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">ifconfig</span></code></b><br><b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">route -n</span></code></b><br><b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">nslookup</span></code></b></td> <td width="20%" style="border-bottom: thin solid black;">Obtain network connectivity confirmation including: '''IP ADDRESS''', '''Netmask''', '''routing''' (default gateway), and the default '''Domain Name Server'''.</td> </tr></table>  :You may have learned about creating and running Bash Shell Scripts in your ULI101 course. Shell scripts help Linux users and system administrators to automate repetitive tasks to become more efficient and to help them save time. You will be reviewing and building a basic Bash Shell script to generate information reports for your newly-installed Linux host machine.  <ol><li value="4">Refer to the Bash Shell Scripting Guide prior to proceeding with this section. As you continue, you are required to make Bash Shell scripting notes in your lab1 logbook.</li><li>Create a directory called bin in your root home directory to store your shell scripts by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">mkdir ~/bin</span></code></b></li><li>Change to that newly-created '''bin''' directory</li></ol>  :'''NOTE:''' Although it is possible to copy and paste, is it highly recommended to manually enter the following Bash Shell scripting content to become familiar with writing Bash Shell scripting code. Remember: you will be required to create a Bash Shell script on your final exam, so you need the practice!  <ol><li value="7">Launch a text editor (such as <b><code><span style="color:#3366CC;font-size:1.2em;">vi</span></code></b> or <b><code><span style="color:#3366CC;font-size:1.2em;">nano</span></code></b>) to create a Bash Shell script called: <b><code><span style="color:#3366CC;font-size:1.2em;">myreport.bash</span></code></b> in your current directory.</li><li>Copy and paste the text below into your vi editing session for your file report.bash<br> (how do you copy and paste efficiently in Linux?)<br></li></ol> <code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;font-weight:bold;"><br>&#35;!/bin/bash<br><br>&#35; Author: *** INSERT YOUR NAME ***<br>&#35; Date: *** CURRENT DATE ***<br>&#35;<br>&#35; Purpose: Creates system info report<br>&#35;<br>&#35; USAGE: ./myreport.bash<br><br>if [ $USER != "root" ] # only runs if logged in as root<br>then<br>&nbsp;echo "You must be logged in as root." >&2<br>&nbsp;exit 1<br>fi<br></code><br><ol><li value="9">Save your editing session, assign the '''myreport.bash''' file read and execute permissions (at least for the owner) and run by typing:<br><b><code><span style="color:#3366CC;font-size:1.2em;">./myreport.bash</span></code></b></li><li>Did it run? If not what do you think you need to do in order to run the Bash Shell Script?</li><li>Issue the command <b><code><span style="color:#3366CC;font-size:1.2em;">su -</span></code></b> and run the script from the regular user's home directory (not root's home directory):<br><b><code><span style="color:#3366CC;font-size:1.2em;">~regularuserid/myreport.bash</span></code></b></li><li> Did it work?</li><li>Reopen your text-editing session for '''~regularuserid/myreport.bash''' and add the following lines of code to the bottom of the shell script file:</ol><br><code style="color:#3366CC;font-family:courier;font-size:.9em;font-weight:bold;">&#35; Create report title<br><br>echo "SYSTEM REPORT" > /root/report.txt<br>echo "Date: $(date +'%A %B %d, %Y (%H:%M:%p)')" >> /root/report.txt<br>echo >> /root/report.txt<br></code><br><ol><li value="8">Save and run the bash shell script. View the contents of the file called '''report.txt''' that was generated (I hope you are using the up arrow key to issue previously issued commands in order to save time!). Notice how the redirection symbol &gt; is used at the beginning of the report, and then the other redirection symbol &gt;&gt; is used to help "grow" the report with the other content.</li><li>The only remaining content of the report would be the system information. We can use a shell scripting trick called "command substitution" $( .. ) in order place results from an command to be used by another command (like echo). Re-edit the shell script and add the following code at the bottom of the shell script file:</li></ol><br><code style="color:#3366CC;font-family:courier;font-size:.9em;font-weight:bold;">echo >> /root/report.txt<br>echo "Hostname: $(hostname)" >> /root/report.txt<br>echo >> /root/report.txt<br>echo "Kernel Version: $(uname -rv)" >> /root/report.txt<br>echo >> /root/report.txt<br></code><br><ol><li value="10">Save, run the script, and view the ''report.txt'' contents (are you using tip that was given to save time?).</li><li>Edit the shell script and include output from the <b><code><span style="color:#3366CC;font-size:1.2em;">ps aux</span></code></b> and <b><code><span style="color:#3366CC;font-size:1.2em;">ifconfig</span></code></b> commands (with appropriate titles). Remember to redirect that output to add to the bottom of the file!</li><li>Save, run and confirm that the shell script is working correctly.</li><li>What would be the use of keeping this shell script as a Linux system administrator?</li></ol><ol><li value="14">Here are some more "complex" Bash Shell scripts, that perform the same task. Although you are not require to understand some of these other tricks, it is recommended that you view the contents of the scripts and save them for future consideration or exmaples.</li><li>The <b><code>wget</code></b> command can be used to quickly download files from the Internet. Issue the following 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/text-report.bash</span></code></b></li><li>Verify that the file '''text-report.bash''' was downloaded to your current directory.</li><li>Assign read and execute permissions for this file by issuing the command: <b><code><span style="color:#3366CC;font-size:1.2em;">chmod u+rx text-report.bash</span></code></b></li><li>Run this Bash Shell script by issuing the command: <b><code><span style="color:#3366CC;font-size:1.2em;">./text-report.bash</span></code></b></li><li>Check to see if it created a report in your current directory. What is the purpose of the report?</li><li>Use the <b>vi</b> text editor to view the contents of the file <b>text-report.bash</b>. Can you understand how this script works?<br><br></li><li>Use the <b><code>wget</code></b> command to download, study, and run the following shell scripts on-line:<blockquote><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">https://scs.senecac.on.ca/~murray.saul/report.bash<br>https://scs.senecac.on.ca/~murray.saul/report3.bash</span></code></b></blockquote></li><li>Try to understand what these Bash Shell scripts do.</li><li>You have completed lab1. Proceed to Completing The Lab, and follow the instructions for "lab sign-off".</li></ol>  ==Part 4: Manipulating VMWare Virtual Machines with vmrun Command==  Regardless of your host operating system, you can use the '''vmrun''' command to manipulate your VMs.  '''Perform the following Steps:''' # Determine which operating system is the host for your VMware Workstation application. Use the chart below to setup your OS's environment to run the '''vmrun''' command:  <table cellspacing="0" cellpadding="5" width="85%" style="border-top: thin solid black;margin-left:60px;"> <tr valign="top> <td width="15%" style="border-bottom: thin solid black;font-weight:bold;background-color:#ffffff;">Operating System</td> <td style="border-bottom: thin solid black;font-weight:bold;background-color:#ffffff;">Set-up Steps</td> </tr> <tr valign="top"> <td width="15%" style="border-bottom: thin solid black;"><b>Linux</b></td> <td style="border-bottom: thin solid black;">Edit the file '''/etc/ld.so.conffile''' and add the following line: /'''usr/lib/vmware-vix''' and then run the command: '''ldconfig'''.</td> </tr><tr valign="top"> <td width="15%" style="border-bottom: thin solid black;"><b>Windows</b></td> <td style="border-bottom: thin solid black;">Right-click on '''Computer''', then select '''Properties''' , '''AdvancedSystemSettings''' , '''EnvironmentVariables''', '''SystemVariables''', '''Path''', '''Edit''' and select the path below based on architecture:<br>32-bit: '''C:\Program Files\VMware\VMware VIX'''<br>64-bit: '''C:\Program Files (x86)\VMware\VMware VIX'''.</td> </tr>  <tr valign="top"> <td width="15%" style="border-bottom: thin solid black;"><b>Mac OS/X</b></td> <td style="border-bottom: thin solid black;">In a Terminal window, issue the following command to add the directory pathname to your system path:<br>'''export PATH="$PATH:/Applications/VMware\ Fusion.app/Contents'''/</td> </tr></table><br><ol><li value="2">The '''vmrun''' command is run with various arguments. The most common are: '''stop''', '''start''', '''reset''', '''suspend''', '''pause''', '''list''', and '''clone'''. This command is run with basically the same syntax regardless of the operating system that you are running.<br><br></li><li>Shut-down all of your VMs.</li><li>Issue the following command:<br><b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">vmrun start path-to-centos1.vmx</span></code></b>. What happens?</li><li>Use the vmrun command to start the other VMs.</li><li>Issue the following command:<br><b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">vmrun start path-to-centos4.vmx</span></code></b>. What happens?</li><li>Issue the following command:<b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">vmrun list path-to-centos1.vmx</span></code></b>. What happens? Why would you use this command?</li><li>Depending of your Operating system platform (Linux Bash Shell script, Windows Powershell script), download the following scripts in the table below to your current directory and run to see what happens. Notice how the '''for''' loop is used to in order to start and stop multiple VMs.</li></ol><br><table cellspacing="0" cellpadding="5" width="55%" style="border-top: thin solid black;margin-left:60px;"> <tr valign="top> <td style="border-bottom: thin solid black;font-weight:bold;background-color:#ffffff;">Operating System</td> <td style="border-bottom: thin solid black;font-weight:bold;background-color:#ffffff;">Various Start / Stop Scripts</td> </tr> <tr valign="top"> <td width="20%" style="border-bottom: thin solid black;"><b>Linux</b></td> <td style="border-bottom: thin solid black;">[https://scs.senecac.on.ca/~murray.saul/ops235/start-vm-cli.bash start-vm-cli.bash] | [https://scs.senecac.on.ca/~murray.saul/ops235/start-vm-gui.bash start-vm-gui.bash] | [https://scs.senecac.on.ca/~murray.saul/ops235/stop-vm-cli.bash stop-vm-cli.bash] | [https://scs.senecac.on.ca/~murray.saul/ops235/stop-vm-gui.bash stop-vm-gui.bash]</td> </tr><tr valign="top"> <td width="20%" style="border-bottom: thin solid black;"><b>Windows</b></td> <td style="border-bottom: thin solid black;">start-vms-cli | start-vms-gui | stop-vms-cli | stop-vms-gui</td> </tr>  <tr valign="top"> <td width="20%" style="border-bottom: thin solid black;"><b>Mac OS/X</b></td> <td style="border-bottom: thin solid black;">start-vms-cli | start-vms-gui | stop-vms-cli | stop-vms-gui</td> </tr></table><br><ol><li value="9">Notice that regardless of the operating system, that scripting is an essential tool for system administrators to control a computer system!</li></ol>  '''Answer Investigation 2 observations (all parts and questions) in your lab log book.'''  = LAB 2 SIGN-OFF (SHOW INSTRUCTOR) ={{Admon/important|Backup ALL of your VMs!|If you have successfully completed this lab, make a new backup of all of your virtual machines onto your UBS Key.}} ===Download and Run Lab2 Checking Script &amp; Show Lab2 Work=== '''Perform the Following Steps:''' # Make certain ALL of your VMs are running.# Switch to your '''centos2''' VM, open a terminal, login as root, and change directory to '''/root/bin'''.# Issue the Linux command: <b><code><span style="color:#3366CC;font-size:1.2em;">wget http://matrix.senecac.on.ca/~murray.saul/ops235/lab2-check-vm.bash</span></code></b># Give the '''lab2-check.bash''' file execute permissions (for the file owner).# Run the shell script and if any warnings, make fixes and re-run shell script until you receive "congratulations" message.#Arrange proof of the following on the screen: ::&#x2713; '''<u>All</u> VMs''':<blockquote><ul><li>All 4 VMs '''created''' and '''running'''</li><li>'''Disk layout''' and '''size''' correct on ALL virtual machines</li><li> Proof of '''yum updates''' on ALL VMs</li></ul></blockquote>::<span style="color:green;font-size:1.5em;">&#x2713;</span>'''centos2 VM''':<blockquote><ul><li>Creation of your bash shell script called '''myreport.bash'''</li><li>A list of your '''iptables''' rules (command: '''iptables -L''')</li><li>Output from running the '''lab2-check.bash''' script with all OK messages</li></ul></blockquote>::<span style="color:green;font-size:1.5em;">&#x2713;</span> Lab2 logbook notes and '''Installation Comparison chart''' completed. = Practice For Quizzes, Tests, Midterm &amp; Final Exam = # What is the name of the CentOS installation program?# What is the name of the file created by the CentOS installation program?# Which type of installation works best for confirming compatibility with hardware before installation? Why?# Which type of installation works best for installing large numbers of computers? Why?# How can you reduce the number of software updates required immediately after installation?# How do you start and stop virtual machines?# How do you SSH into your virtual machines?# List 2 ways that you can access your root account# What is the difference between the commands '''su''' and '''su -''' ?# What is the home directory for the user "root"?# How do you determine the host name of your GNU/Linux workstation?# What command can display the NIC's MAC address?# What command is used to get a list of running processes on your newly-installed system?# How create in a shell script to force the user to run shell script as root?# How to store each file-name in your current directory as separate positional parameters? How to list all of the positional parameters? How to display the number of positional parameters?  [[Category:OPS235]]REDIRECT [[Category:OPS235 Labs]]
13,420
edits

Navigation menu