Practical Assignment Three: systemd
systemd is the replacement to the legacy Unix SysV and BSD INIT daemons. It provides a suite of components for managing services, in addition to many other functions such as logging, device management, managing mounts, networks/sockets, etc.
In this assignment, you will use systemd to create a simple service that runs as a web service (using Python’s SimpleHTTPServer method).Step 1: Configure Firewalls and test Python
1. Configure Google Cloud Firewall to allow ports 80 and 8080 to your VM (this step is optional, but makes the assignment more fun):
a. Log in to your Google Cloud Console and navigate to your Virtual Instances in the Compute Engine.
b. Click on your Linux server to see the properties, then click “edit”
c. Find the section for “Network Tags” and add a tag. For example, I used “cis285-server”. You will reference this tag later; it is how this machine will be identified by Google’s virtual firewall. Be sure to click “Save” when you are done.
d. Click the main menu button (the “hamburger” with three horizontal lines), and go to the “Network” group, “VPC Networks”, then “Firewall”.
e. Create a new firewall rule. Select:
i. Direction: Ingress
ii. Targets: Specified Target Tags
iii. Target Tags: (enter the value you used for your “network tag” previously; for mine, I used “cis285-server”)
iv. Source Filter: IP Ranges
v. Source IP Ranges: 0.0.0.0/0
vi. Protocols/Ports: Specify TCP “80, 8080”
vii. Save the new rule.
2. Configure the firewall in your Linux Server:
a. Use the “su” command so you will have the “root” context. (Look for the # prompt, not $).
b. Your default zone should still be “public”; use the command firewall-cmd –get-active-zone to verify.
i. If the active zone is not public, use this command to set it:
1. firewall-cmd --set-default-zone=public --permanent
ii. Add FTP, HTTP, and port 8080 to your firewall rules:
1. firewall-cmd --zone=public --permanent --add-service=ftp
2. firewall-cmd --zone=public --permanent --add-service=http
3. firewall-cmd --zone=public --permanent --add-port=8080/tcp
iii. Verify it worked:
1. firewall-cmd --zone=public --list-ports
2. firewall-cmd --zone=public --list-services
3. Run a simple web server in your user-space:
a. Create the following web page file, and customize the code to include your name:
i. /home/student/index.html
This is my page!
This is a sample page
This is a sample web page to demonstrate Python's simple web server.
Brian Green b. From the same directory in which you created the HTML file, start the Python command to run a web server:
i. python -m SimpleHTTPServer 80
1. Note: if this fails to start, make sure you are running as “root” (use the su command to change to root).
ii. Test your web server:
1. Using your Linux Client:
a. SSH to your “client”
b. Use YUM to install Telnet: sudo yum install telnet
2. Use the telnet command to call the web server and retrieve your web page:
a. telnet hostname_or_ip 80
b. At the prompt, type:
GET /index HTTP/1.1 [Enter]
Host: foo [Enter]
[Enter]
c. Take a screen capture of the output from both the client and the server showing the loading of the page. Note, the HTML code should include your name.
3. Use a web browser to test your server (Optional):
a. In the Google Cloud console, find the external IP of your server VM. This is the same IP you use to SSH to your Linux machine.
b. Open a web browser and use that IP to view your web page!
iii. Use CTRL-C to kill your Python web server.
Part 2: Explore your Unit Files:
1. First, take a look at your systemd unit files in the following two directories:
a. /lib/systemd/system
b. /etc/systemd/system
i. Which of these have more unit files? Why is that?
/lib has more unit files as compare to /etc because /etc contains system specific unit files whereas /lib has vendor or distribution specific vendor files which are more in the numbers since numbers of services and functionalities more as compare system (hardware).
ii. What file extensions do you...