DevOps Lesson
import socket
# Change the following host and see what IP it prints!
host = "google.com"
ip = socket.gethostbyname(host)
print(ip)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
print("Successfully connected!")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
# Send a GET request to "/"
s.sendall(b"GET / HTTP/1.1\r\n\r\n")
# Recieve & print 2048 bytes of data
data = s.recv(2048)
print(data.decode())
import requests
# Change the URL to whatever you'd like
response = requests.get("https://youtube.com")
print("Status code:", response.status_code)
print("Headers:", response.headers)
print("Response text:", response.text[:100])
# Add a line to print the "Content-Type" header of the response
# Try an image URL!
aws = "3.130.255.192"
response = requests.get("http://" + aws)
print(response.text)
Configuration
server {
// Listen on virtual "port 80"
listen 80;
listen [::]:80;
server_name 3.130.255.192;
location / {
// Inform server about original client
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
// Forward all requests transparently to the server running on our computer
proxy_pass http://localhost:9099;
}
}
Load Balancing
upstream example.com {
server server1.example.com;
server server1.example.com;
}
HTTP Headers
server {
add_header X-Cool-Header "I love APCSP!";
location /pages {
add_header X-Cooler-Header "This is my secret header!";
}
}
Check In
- Research 1 HTTP header and describe, in detail, its purpose.
- Another commonly used HTTP header is the "Content-Type" header. The purpose of the Content-Type header is to specify the type of data that is being sent in the HTTP message body. The Content-Type header is typically used in HTTP requests to indicate the format of the data being sent to the server, and in HTTP responses to indicate the format of the data being sent back to the client.
- Write a line in a sample NGINX configuration that will add that specific header to the
/information
location
- information { add_header User-Agent "Custom User Agent"; }
- Explain the purpose of the load balancing performed by NGINX
- The purpose of load balancing performed by NGINX is to distribute incoming network traffic across multiple servers to improve reliability, scalability, and performance.
- Modify the following code block to obtain the value of the secret header on
/products
of the AWS site
- Imported request and changed it so the variable was in the print statement
import requests
aws = "3.130.255.192"
response = requests.get("http://" + aws+ "/products")
print("The secret header is:", response.headers)
CORS Hacks
- Explain what CORS is and what it stands for
- Cross-Origin Resource Sharing (CORS) is a standard mechanism that allows JavaScript XMLHttpRequest (XHR) calls executed in a webpage to interact with resources from domains of different origins. CORS is a commonly implemented solution to same-origin policy enforced by all browsers.
- Describe how you would be able to implement CORS into your own websites
- I would be able to implement CORS into my own website maybe through my backend. I am aware that we did something with CORS in our flasks to help us with our backend
- Describe why you would want to implement CORS into your own websites
- We should implement CORS into our websites because this can help protect our sites, and we should do it for our group website
- Implementing CORS in our group website would be helpful to do as a security measure for our website, especially if we will have
- How could use CORS to benefit yourself in the future?
- We could use CORS in our group project websites
- I want to try and make my own website, so by implementing CORS, I can make sure that no one else tries to do something to my website Total: 0.2 points
KASM Hacks
- What is the purpose of "sudo" when running commands in terminal?
- It is for the super user do.
- If the system is operated by multiple administrators instead of one, and many people share the root password, it becomes difficult to change the root password regularly, and the probability of the root password being exposed to the outside increases relatively.
- What are some commands which allow us to look at how the storage of a machine is set up as?
-
"diskmgmt.msc": This command opens the Disk Management tool, which displays information about the disks and volumes on your computer.
-
"wmic logicaldisk get size,freespace,caption": This command displays information about the size, free space, and name of each logical disk on your computer.
- What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
- Alternatives to using "curl -O" to retrieve the zip file for KASM could include:
- Using a web browser to download the zip file manually from the KASM website.
- Using a download manager or wget command to retrieve the file.
- Using a version control system like Git to clone the KASM repository directly.
- What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
- The install.sh command is typically a shell script used to install software or packages on a Unix-like operating system. This command is often used in conjunction with other command-line tools like apt-get on Ubuntu or yum on CentOS to automate the installation process and ensure that all necessary dependencies are installed. -Calling install.sh is necessary to ensure that the software or package is installed correctly and that all dependencies are met. The script takes care of all the necessary steps to set up the software, which can be a complex and time-consuming process if done manually. By running install.sh, the installation process is streamlined and automated, saving time and reducing the risk of errors or omissions in the installation process.
- Explain in at least 3-4 sentences how deploying KASM is related to/requires other topics talked about in the lesson and/or potential ways to add things mentioned in the lesson to this guide.
- Deploying KASM involves various related topics and potential additions from the lesson, including:
- Networking: Configuring network settings for KASM to ensure proper communication between the deployed application and other systems.
- Security: Implementing appropriate security measures, such as setting up firewalls or using encryption protocols, to protect the deployed KASM instance.
- System administration: Managing and monitoring the KASM deployment, performing updates, and troubleshooting issues.
- Integration: Integrating KASM with other tools, frameworks, or services mentioned in the lesson, such as Docker containers, load balancers, or monitoring solutions, to enhance functionality and performance. Total: 0.2 points Total: 0.2 points
AWS/RDS Hacks
See the setup post
- Create your own database in the EC2 I have created (ec2-database-connect)
- name it with your first and last name (example: aditya-nawandhar) (0.1)
- Create a table using the commands on the link provided. (0.1)
- using commands from the link provided make columns and rows with test data (can be anything) (example: “name” and “class” are the columns with rows being something like “Aditya” and “Junior”). At least 4 test rows (0.1)
- additional points if the data matches CPT (Bonus: 0.05)
Total: 0.3