Difference between revisions of "OPS235 Lab 2 - CentOS7 - VMware"
Line 284: | Line 284: | ||
'''Answer Investigation 2 observations (all parts and questions) in your lab log book.''' | '''Answer Investigation 2 observations (all parts and questions) in your lab log book.''' | ||
− | |||
− | |||
− | |||
− | |||
Revision as of 08:29, 23 May 2016
Contents
LAB PREPARATION
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.
Main Objectives
- Create 3 separate VMs (virtual machines) using different installation methods:
- Centos Live DVDInstallation
- 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.
Minimum Required Materials
My Toolkit (CLI Reference)
Virtualization:
x |
Commands | Installation Guides
Installing & Using KVM on CentOS |
INVESTIGATION 1: USING VIRTUALIZATION SOFTWARE TO CREATE VIRTUAL MACHINES
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)
- VM Details:
- VM Name (and hostname): centos2
- Boot media: LIVE CD Image
- 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
+++ Discuss the concept of installing a Linux Image file as opposed to a Linux Install DVD +++
- Open a web-browser, copy and paste the following URL into the web-browser to download the following Linux image file:
wget http://belmont.senecac.on.ca/centos/7/isos/x86_64/CentOS-7-x86_64-LiveGNOME-1511.iso
- Make certain you used the wget command to download the LiveGNOME iso file from the Belmont server (from previous instructions).
- In the Virtual Machine Manger, click on the icon to Create a Virtual Machine in the upper-left corner:
- A window will appear with the title New VM. There are five steps to be completed; click Forward after each step:
- Step 1 of 5:Select Local install media and click Forward.
- Step 2 of 5: Select Use ISO Image, click the Browse button, and then the Browse Local button. Navigate to the location of the downloaded Centos7 LIVE CD image, select the image file and click Open. When finished, click Forward to proceed.
- Step 3 of 5: Set the memory to 2048 MB and the number of CPUs to 1
- Step 4 of 5: This next step creates a disk file that will be used to simulate the virtual machine's disk drive. Select a size of 10 GB. Click on
Select managed or other existing storage and type the VM image file pathame:
/var/lib/libvirt/images/centos2.img (make certain that the pathname is correct) and then click Forward to proceed. - Step 5 of 5: Enter the virtual machine name: centos2. Review the VM information, and click Finish.
- The virtual machine will now start - start timing your installation and making notes for centos2 virtual machine in the installation comparison chart in lab2 logbook. The virtual machine is running from the live disc at this point, and no software has been installed on the hard drive of the virtual machine. The point of a live disk is to allow you to test the distribution to see whether you like it without installing to the hard-drive first.
- 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: centos2 as opposed to centos1) for this installation. (with a few slight differences).
- 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.
- Accept the changes and then click Begin Installation.
- You will be required to make selections very similar to what you did in lab1.
- While the system is installing, take a few minutes to record your observations (including slight differences with centos2 install as opposed to centos1 install).
- 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.
- Power-off your Centos7 LIVE system.
- You should notice that the Centos7 boot menu appears. Either press ENTER to start or wait for it to start automatically.
- Finish the final steps in the setup process (like you did in lab1).
- #You may want to turn off the screen-saver (like you did in Lab1): How to Turn-off Screen Saver (lab1)
- Enable SSH access to your virtual machine with these commands (semi-colon allows commands to be run in sequence):
service sshd start; chkconfig sshd on
- Find out the IP address of your virtual machine and the name of your Ethernet network adaptor:
ifconfig
- Enter the following command on your virtual machine to create a firewall exception to allow ssh traffic into the machine:
iptables -I INPUT -p tcp -s0/0 -d0/0 --dport 22 -j ACCEPT
- If you are logged in as root, logout to your regular user account.
- Confirm that you can ssh to your virtual machine from the host (your main CentOS installation):
ssh regularuserid@IPaddress
(where regularuserid is your regular user login id, and IPaddress is the IP_ADDRESS of your centos2 VM!). - Make certain to disable SELinux for centos2 (refer to lab1)
- Adjust your screen-saver settings and run a yum update on your centos2 VM before proceeding to Part 2
Part 2: Installing from a Network
- 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:
- Select Network Installation using the installation source URL displayed above.
- 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).
- Don't forget to install the GNOME desktop here as you will need a GUI for Centos3
- 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.
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.
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.
INVESTIGATION 2: COMMON POST-INSTALL TASKS
Part 1: Accessing Administrative Priviledges
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
su
Issue the pwd and whoami commands to confirm your directory pathname. When finished logout of this account. - Issue the command
su -
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
/var/log/anaconda/packaging.log
has been created to record the installation of your centos1 machine. This file is an ASCII file which can be viewed with themore
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:
-
grep -i packaging /var/log/anaconda/packaging.log | wc -l
-
Part 2: Common Post-Install Commands & Shell Scripting
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.
- Login to your centos1 VM, open a Bash Shell terminal, and login as root by issuing the command:
su -
- Make certain to record output from these commands (except for the ps -ef output) in your lab1 logbook.
Command(s) | Purpose |
uname -rv hostname ps -ef |
Basic Linux OS information such as kernel version, host-name of Linux server, and all processes that are running on the system after installation. |
rpm -q -a | wc -l rpm -q -a -l | wc -l rpm -q -l gedit | wc -l |
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. |
ifconfig route -n nslookup |
Obtain network connectivity confirmation including: IP ADDRESS, Netmask, routing (default gateway), and the default Domain Name Server. |
- 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.
- 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.
- Create a directory called bin in your root home directory to store your shell scripts by issuing the command:
mkdir ~/bin
- Change to that newly-created bin directory
- 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!
- Launch a text editor (such as
vi
ornano
) to create a Bash Shell script called:myreport.bash
in your current directory. - Copy and paste the text below into your vi editing session for your file report.bash
(how do you copy and paste efficiently in Linux?)
#!/bin/bash
# Author: *** INSERT YOUR NAME ***
# Date: *** CURRENT DATE ***
#
# Purpose: Creates system info report
#
# USAGE: ./myreport.bash
if [ $USER != "root" ] # only runs if logged in as root
then
echo "You must be logged in as root." >&2
exit 1
fi
- Save your editing session, assign the myreport.bash file read and execute permissions (at least for the owner) and run by typing:
./myreport.bash
- Did it run? If not what do you think you need to do in order to run the Bash Shell Script?
- Issue the command
su -
and run the script from the regular user's home directory (not root's home directory):~regularuserid/myreport.bash
- Did it work?
- Reopen your text-editing session for ~regularuserid/myreport.bash and add the following lines of code to the bottom of the shell script file:
# Create report title
echo "SYSTEM REPORT" > /root/report.txt
echo "Date: $(date +'%A %B %d, %Y (%H:%M:%p)')" >> /root/report.txt
echo >> /root/report.txt
- 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 > is used at the beginning of the report, and then the other redirection symbol >> is used to help "grow" the report with the other content.
- 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:
echo >> /root/report.txt
echo "Hostname: $(hostname)" >> /root/report.txt
echo >> /root/report.txt
echo "Kernel Version: $(uname -rv)" >> /root/report.txt
echo >> /root/report.txt
- Save, run the script, and view the report.txt contents (are you using tip that was given to save time?).
- Edit the shell script and include output from the
ps aux
andifconfig
commands (with appropriate titles). Remember to redirect that output to add to the bottom of the file! - Save, run and confirm that the shell script is working correctly.
- What would be the use of keeping this shell script as a Linux system administrator?
- 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.
- The
wget
command can be used to quickly download files from the Internet. Issue the following command:wget https://scs.senecac.on.ca/~murray.saul/text-report.bash
- Verify that the file text-report.bash was downloaded to your current directory.
- Assign read and execute permissions for this file by issuing the command:
chmod u+rx text-report.bash
- Run this Bash Shell script by issuing the command:
./text-report.bash
- Check to see if it created a report in your current directory. What is the purpose of the report?
- Use the vi text editor to view the contents of the file text-report.bash. Can you understand how this script works?
- Use the
wget
command to download, study, and run the following shell scripts on-line:https://scs.senecac.on.ca/~murray.saul/report.bash
https://scs.senecac.on.ca/~murray.saul/report3.bash - Try to understand what these Bash Shell scripts do.
- You have completed lab1. Proceed to Completing The Lab, and follow the instructions for "lab sign-off".
Answer Investigation 2 observations (all parts and questions) in your lab log book.
LAB 2 SIGN-OFF (SHOW INSTRUCTOR)
Download and Run Lab1 Checking Script & Show Lab1 Work
Perform the Following Steps:
- Issue the Linux command:
wget http://matrix.senecac.on.ca/~murray.saul/ops235/lab2-check.bash
- 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:
- ✓ All VMs:
- Working virtual machines created and running
- Disk layout and size correct on all virtual machines
- Proof of yum updates
- All virtual machines backed-up (eg. usb stick and/or home directory)
- ✓centos1 machine:
- Correct VM image filenames contained in /var/lib/libvirt/images directory
- Creation of your bash shell script called backupVM.bash
- A list of your iptables rules (command: iptables -L)
- ✓ Lab2 logbook notes and Installation Comparison chart completed
Practice For Quizzes, Tests, Midterm & 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?
- What is procedure to backup your VM images (and XML config files) to your USB key?
- The kickstart installation (centos4) was a network installation. Can a kickstart file be used with a DVD installation?
- The kickstart installation (centos4) was fairly fast. Why? Under what circumstances would it take a long time, even on a fast network?
- 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 filename in your current directory as separate positional parameters? How to list all of the positional parameters? How to display the number of positional parameters?