Difference between revisions of "OPS235 Lab 1 - CentOS7"
Line 306: | Line 306: | ||
<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:<blockquote><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></blockquote></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>chmod u+rx text-report.bash</code></b></li><li>Run this Bash Shell script by issuing the command: <b><code>./text-report.bash</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> | <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:<blockquote><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></blockquote></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>chmod u+rx text-report.bash</code></b></li><li>Run this Bash Shell script by issuing the command: <b><code>./text-report.bash</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> | ||
− | |width="40%"|{{Admon/tip|Bash Shell Scripting Tips:|<br><ul><li>'''She-bang line on first line of shell script:'''<br><br>Shell scripts have evolved of the past 40 years. To avoid running a newer shell script on an older shell, it is recommended to force running the shell script in the correct shell. In order to do this, on the first line at the very beginning of the shell script, you add the '''#!''' ('''# - shhhh as a comment''', and''' ! is referred to as "bang" run a commmand''': in this case, '''run the command: /bin/bash'''). You can issue the Linux command '''which bash''' to get the correct location. If there is no bash shell on that machine, the shell script will not run (as a precaution - the Linux admin will know how to make a fix to the shell script if required)<br>. </li><li>'''Variables:'''<br><br> There are 3 types of variables that can be used in shell scripting: '''ENVIRONMENT''' (eg. $USER), '''user-defined''' ($varName), and '''positional parameters''' (eg. $1, $2... containing arguments after shell script or by using set command (eg. '''set $(ls)''' ). Using dollar sign ('''$''') in front of variable expands the value assigned.<br><br></li><li>Command Substitution:<br><br>A very useful trick to take output from a command to be used as an argument for another command. Examples include: '''file $(ls)'''<br>'''set $(ls);echo $#;echo $*'''<br>'''echo "hostname: $(hostname)"'''<br><br><li>'''Logic Control Flow Statements:'''<br><br>The '''test''' command can be used to see if a condition is true or false<br>(i.e. test $USER = "root") . The '''$?''' special shell variable stores the result (zero if true, non-zero if false). Square brackets '''[ ]''' can be used to represent the test command with the condition <u>inside</u> the brackets (spaces separating brackets).Can use '''if''' / '''if-else''' / '''if-elif-else''' statements with brackets. The '''exit''' command can be used to terminate the shell script with a false value.<br><br>Examples:<pre> | + | |width="40%"|{{Admon/tip|Bash Shell Scripting Tips:|<br><ul><li>'''She-bang line on first line of shell script:'''<br><br>Shell scripts have evolved of the past 40 years. To avoid running a newer shell script on an older shell, it is recommended to force running the shell script in the correct shell. In order to do this, on the first line at the very beginning of the shell script, you add the '''#!''' ('''# - shhhh as a comment''', and''' ! is referred to as "bang" run a commmand''': in this case, '''run the command: /bin/bash'''). You can issue the Linux command '''which bash''' to get the correct location. If there is no bash shell on that machine, the shell script will not run (as a precaution - the Linux admin will know how to make a fix to the shell script if required)<br>. </li><li>'''Variables:'''<br><br> There are 3 types of variables that can be used in shell scripting: '''ENVIRONMENT''' (eg. $USER), '''user-defined''' ($varName), and '''positional parameters''' (eg. $1, $2... containing arguments after shell script or by using set command (eg. '''set $(ls)''' ). Using dollar sign ('''$''') in front of variable expands the value assigned.<br><br></li><li>Command Substitution:<br><br>A very useful trick to take output from a command to be used as an argument for another command. Examples include:<br>'''file $(ls)'''<br>'''set $(ls);echo $#;echo $*'''<br>'''echo "hostname: $(hostname)"'''<br><br><li>'''Logic Control Flow Statements:'''<br><br>The '''test''' command can be used to see if a condition is true or false<br>(i.e. test $USER = "root") . The '''$?''' special shell variable stores the result (zero if true, non-zero if false). Square brackets '''[ ]''' can be used to represent the test command with the condition <u>inside</u> the brackets (spaces separating brackets).Can use '''if''' / '''if-else''' / '''if-elif-else''' statements with brackets. The '''exit''' command can be used to terminate the shell script with a false value.<br><br>Examples:<pre> |
if [ $USER != "root" ] | if [ $USER != "root" ] | ||
then | then |
Revision as of 12:01, 1 April 2015
Contents
LAB PREPARATION
Purpose / Objectives of Lab 1
You need to install a Linux OS to be a host or "platform" to install and use other Linux VMs (Virtual Machines) during this course.
The Linux OS you will be installing in this lab will be a Host Machine (hostname: c7host) that will allow you to run Virtualization Software to create 3 separate virtual machines (to be performed in lab2). It is important to install this host machine correctly since other labs will depend on the stability of this host machine.
Main objectives:
- Correctly install the CentOS 7 FULL INSTALL DVD (not LIVE DVD) on your removable hard disk.
- Record installation characteristics of CentOS 7 FULL INSTALL in a chart (contained in lab2 logbook chart) to compare with other installation methods performed in lab2.
- Verify correct settings prior to proceeding with host installation stages.
- Obtain Linux server information after installation to create a software asset report for later access.
- Disable Linux Kernel security enhancements to allow easier internal networking connections (to be reactivated in a later lab).
- Observe that Bash Shell Scripts can automate routine tasks.
Minimum Required Materials
My Toolkit (CLI Reference)
Package Management | System Information | Networking | Miscellaneous
grep
|
INVESTIGATION 1: CREATE HOST MACHINE (c7host)
For the next 3 investigations, you will learn how to install your Centos Full DVD onto your removable hard disk. You will customize your install to setup several separate partitions: root (/), /home, /var/lib/libvirt/images (to store virtual machine images to be created in lab2), and a swap partition.
Make certain to record your observations of this install in the comparison chart for c7host in your lab2 logbook.
Part 1: Start Installation
- Host Machine Details:
- Name: c7host
- Boot media / Installation: CentOS7 Full Install DVD
- Memory: 16GB
- Disk space: 250GB (or higher)
- CPUs: 1
|
Part 2: Custom Partitioning
|
Part 3: Completing the Installation
- During the installation process, you will required to create a root password (for administration access) and create a regular user account. Click on Root Password and enter your root password. Think of an appropriate password and record that password somewhere in case you forget! An indicator will appear to show you how secure your password is. Retype your root password and click Done (you may have to click Done twice if your password is strong).
- You need to create a regular user account. This account will be used to graphical log into your host machine. It is never recommended to graphically log into a graphical Linux/Unix system as root. It is better to log into a regualr user account, then run a command to login as root (you will learn how to do this later in this lab.
- Click User Creation and enter your full name, username, and an appropriate password (and confirm password). Click Done to finish.
- Remember to record this host installation information in the comparison chart in lab2.
- When installation is complete, you will notice a message at the bottom of the screen stating: CentOS is now successfully installed and ready for you to use!
- Click the Reboot button. Your DVD will briefly open in the DVD drive bay. Make certain to remove this installation DVD so that Centos will boot from your hard drive.
- After the system reboots, login by clicking on your account name and entering the regular user password.
- The last phase of the installation process should now run:
- Click Accept to confirm you will abide by the License and click Done.
- Accept defaults to participate running KDump application that will report errors to developers for improvements to Centos7.
- Select English as the default input source.
- Quickly view Getting Started Resources, then close the help window.
- Proceed to Investigation 2 to obtain basic information from your newly installed Centos Host machine.
Answer Investigation 1 observations (all parts and questions) in your lab log book.
INVESTIGATION 2: OBTAINING HOST MACHINE SYSTEM INFORMATION
Part 1: Obtaining Package Management / Package Information
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:
|
Part2: Obtaining System Information
|
Answer the Investigation 2 observations / questions in your lab log book.
INVESTIGATION 3: LOOKING AHEAD
Part 1: Disable SELinux and Perform Software Updates
|
Part 2: Automating Routine Tasks (Shell Scripting)
You may have learned about creating and running Bash Shell Scripts in your ULI101 course. Shell scripts help Linux users and system administrators to automatic 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 your newly-installed Linux host machine. Take time to view Shell Scripting Tips on the right-hand side, and run the online tutorial to learn how to create simple shell scripts.
#!/bin/bash # Forces script to run in the bash shell # Author: *** INSERT YOUR NAME *** # Date: *** CURRENT DATE *** # # Purpose: To present sysadmin to create an software inventory # report containing selected elements # # USAGE: ./report.bash if [ $USER != "root" ] # checks to see if user is root, and exits script if not then echo "You must be logged in as root to run the command." >&2 # >&2 is a "redirection trick" to convert output as stderr echo "Either login as root or issue command \"sudo ./report1.bash\"" >&2 exit 1 fi
# Create report title echo "SOFTWARE ASSET REPORT FOR INSTALLED LINUX SYSTEM" > /root/report.txt echo "Date: $(date +'%A %B %d, %Y (%H:%M:%p)')" >> /root/report.txt echo >> /root/report.txt
echo >> /root/report.txt echo "Hostname: $(hostname)" >> /root/report.txt echo >> /root/report.txt echo >> /root/report.txt echo "Kernel Version: $(uname -rv)" >> /root/report.txt echo >> /root/report.txt
|
Answer the Investigation 3 observations / questions in your lab log book.
LAB 1 SIGN-OFF (SHOW INSTRUCTOR)
Arrange evidence (command output) for each of these items on your screen, then ask your instructor to review them and sign off on the lab's completion:
- ✓ Output of lsblk command showing correct partition names and sizes
- ✓ Correct IP address and MAC address
- ✓ Default route (gateway)
- ✓ DNS name server IP Address
- ✓ Contents of your report.bash shell script
- ✓ lab1 notes and first column of Comparison Chart in lab2.
ADDITIONAL PRACTICE
- How many packages were installed?
- How many files (correct to the nearest hundred) were installed?
- How many users were created automatically on your system (regular, admin)?
- List 3 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?
- What is the command to copy files to your USB key?
- How can Shell Scripts be used to help automate a task performed in lab1?