Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e7e374f
Create MachineA.sh
hanz0m4 Apr 29, 2024
677c471
Create MachineB.sh
hanz0m4 Apr 29, 2024
5fc08ba
Create MachineC.sh
hanz0m4 Apr 29, 2024
a033c33
app.py
hanz0m4 Apr 29, 2024
f272813
Add files via upload
hanz0m4 Apr 29, 2024
e10d7ec
Delete README.md
hanz0m4 Apr 29, 2024
3ca3c90
Add files via upload
hanz0m4 Apr 29, 2024
fa954f9
Rename MachineA.sh to configs/MachineA.sh
hanz0m4 Apr 29, 2024
fb29d1b
Rename MachineB.sh to configs/MachineB.sh
hanz0m4 Apr 29, 2024
b878930
Rename MachineC.sh to configs/MachineC.sh
hanz0m4 Apr 29, 2024
8dab1fa
Rename app.py to application/app.py
hanz0m4 Apr 29, 2024
1fe7525
Add files via upload
hanz0m4 Apr 29, 2024
4fae671
Rename A - C.jpg to pictures/A - C.jpg
hanz0m4 Apr 29, 2024
404e289
Rename Bash_A.jpg to pictures/Bash_A.jpg
hanz0m4 Apr 29, 2024
43132b4
Rename Bash_B.jpg to pictures/Bash_B.jpg
hanz0m4 Apr 29, 2024
3d2ddac
Rename Bash_C.jpg to pictures/Bash_C.jpg
hanz0m4 Apr 29, 2024
fc4c7c4
Rename C - A - 2.jpg to pictures/C - A - 2.jpg
hanz0m4 Apr 29, 2024
06542c2
Rename C - A.jpg to pictures/C - A.jpg
hanz0m4 Apr 29, 2024
f0b5eb4
Rename Flask.jpg to pictures/Flask.jpg
hanz0m4 Apr 29, 2024
017e41b
Rename Http-server-1.jpg to pictures/Http-server-1.jpg
hanz0m4 Apr 29, 2024
f26470b
Rename Http-server.jpg to pictures/Http-server.jpg
hanz0m4 Apr 29, 2024
32c613a
Rename Key_A.jpg to pictures/Key_A.jpg
hanz0m4 Apr 29, 2024
7dd0ce8
Rename Key_B.jpg to pictures/Key_B.jpg
hanz0m4 Apr 29, 2024
c85eda0
Rename Key_C.jpg to pictures/Key_C.jpg
hanz0m4 Apr 29, 2024
30b6162
Rename Request-1.jpg to pictures/Request-1.jpg
hanz0m4 Apr 29, 2024
45c61f0
Rename Request-2.jpg to pictures/Request-2.jpg
hanz0m4 Apr 29, 2024
13615a5
Rename Virtual machines.jpg to pictures/Virtual machines.jpg
hanz0m4 Apr 29, 2024
bcb4e82
Rename adapter_A.jpg to pictures/adapter_A.jpg
hanz0m4 Apr 29, 2024
16e1193
Rename adapter_B_1.jpg to pictures/adapter_B_1.jpg
hanz0m4 Apr 29, 2024
a5726f0
Rename adapter_C.jpg to pictures/adapter_C.jpg
hanz0m4 Apr 29, 2024
4515c6e
Rename adapter_B_2.jpg to pictures/adapter_B_2.jpg
hanz0m4 Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 198 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,198 @@
# Введение
Данная практика посвещена базовым принципам администрирования Linux. Для выполнения практики необходимо развернуть 3 виртуальные машины Linux.

Как пример, можно использовать Virtual Box + Ubuntu Server 20.04.

# Задание
Для выполнения данного задания необходимо:
1. Развернуть три виртуальные машины Linux, согласно схеме ниже


![info](Linux%20Practice.png)

2. Linux A
1. Сконфигурировать Hostname следующим образом: <your_surname>_server (пропустить если делаете через Play with docker)
2. Создать пользователя <your_surname>_1 (пропустить если делаете через Play with docker)
3. Сконфигурировать виртуальный интерфейс со следующим ip адресом: 192.168.<день рождения>.10/24
4. Развернуть Http сервер на виртуальной машине на порту 5000. Необходимо реализовать минимум три эндпоинта (запрос /get, /post, /put)
3. Linux B
1. Сконфигурировать Hostname следующим образом: <your_surname>_gateway (пропустить если делаете через Play with docker)
2. Создать пользователя <your_surname>_2 (пропустить если делаете через Play with docker)
3. Сконфигурировать 2 виртуальных интерфейс со следующими ip адресом: 192.168.<день рождения>.1/24, 192.168.<месяц рождения>.10/24
4. С помощью утилит ip route и iptables настроить маршрут пакетов от Linux A до C. Должны быть запрещены все пакеты, кроме http пакетов через порт 5000 (маршруты обязательно, файрвол опционально)
5. Запустить программу tcpdump с фильтрацией по портам 5000
4. Linux C
1. Сконфигурировать Hostname следующим образом: <your_surname>_client (пропустить если делаете через Play with docker)
2. Создать пользователя <your_surname>_3 (пропустить если делаете через Play with docker)
3. Сконфигурировать виртуальный интерфейс со следующим ip адресом: 192.168.<месяц рождения>.100/24
4. С помощью команды curl на машине C послать 3 запроса на машину А в http сервер (/get, /post, /put)
5. При перезагрузки системы все сервисы и сетевая архитектура должны также функционировать (сохранить свои настройки)
6. Сделать скриншоты всех этапов задания
7. Оформить отчет в виде Markdown файла. Приложить конфигурационные файлы в репозиторий
8. Для play with docker также нужно написать bash скрипты для воспроизведения на новых вм


Репозиторий оформить следующим образом:
- application - исходный код http сервера
- configs - конфигурационные файлы сетевых настроек виртуальных машин
- report.md - Отчет markdown


P.S.
Если не получилось использовать разные утилиты для настройки сети, используйте netplan
Смотрите [мануал](./guide/Manual.md) - там информация для virtual box и Play with docker
# Отчет
## Описание задачи
Необходимо развернуть три виртуальные машины, согласно схеме:

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/23c907a8-bbe7-4213-9048-8f0159174e9d">
</p>

### Решение

Для построения и реализации поставленной задачи был использован сервис Play-with-docker.com, который позволяет подключаться удалённо к виртуальным машинам.

Первым этапом было создание виртуальных машин:

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/99ada9bf-c789-4fb0-8d81-a48b0b4b2620">
</p>

## Виртуальная машина А

Теперь необходимо настроить машину А (Сервер). Настройка заключается в создание ssh-ключа, создании адаптера для задания маршрутов.


Шаг №1. Генерация ssh-ключа.

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/4eee11b5-7456-4def-a5e7-1e07b7bb9f90">
</p>

Подключение к виртуальной машине А происходит по команде:
ssh ip172-18-0-34-conq0rgl2o9000dchcq0@direct.labs.play-with-docker.com

Шаг №2. Создание адаптера на машине А.

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/32bd29e3-7ad6-47c9-911d-d813dab9579e">
</p>

Шаг №3. Создание маршрута на машине А между А и С

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/49a02a1c-a707-4380-900c-de3442ff33e8">
</p>

Следующим этапом будет настройка машины Б, которая выступает связующим звеном между А и С.

## Виртуальная машина Б

Шаг №1. Генерация ssh-ключа

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/ba158ca2-dc7c-43fc-b41a-6945208d4bb1">
</p>

Подключение к виртуальной машине А происходит по команде: ssh ip172-18-0-75-conq0rgl2o9000dchcq0@direct.labs.play-with-docker.com

Шаг №2. Создание адаптера на виртуалке Б

Создадим 1-ый маршрут 192.168.24.1/24


<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/f348320f-5889-4d24-9afb-03577af2dbc2">
</p>

Создадим 2-ой маршрут 192.168.2.1/24

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/c3d9d4b0-456f-47cf-940a-1e90495d5ea7">
</p>

На данном этапе настройка машины Б завершается. Приступим к настройке машины С.

## Виртуальная машина С

Настройка виртуальной машины С заключается в созданиие ssh-ключа, адаптера.

Шаг №1. Генерация ssh-ключа

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/b88b49d1-35a0-48b6-9152-4bd22b818418">
</p>

Подключение к виртуальной машине C происходит по команде:
ssh ip172-18-0-122-conq0rgl2o9000dchcq0@direct.labs.play-with-docker.com

Шаг №2. Создание адаптера на виртуалке С и добавление маршрута между С и А

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/c2f28305-2ed5-42e9-bdc5-c635394c1e1d">
</p>

Настройка машины С завершено

## Создание и запуск http-сервера

Шаг №1. Установка модуля Flask на машине А

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/042e6db7-b6a2-4c81-be01-747c8165d57a">
</p>

Шаг №2. Создание файла app.py

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/b8854db2-c468-45c9-be14-07c8fe52c768">
</p>

Шаг №3. Разворачивание hhtp-сервера на 5000 порту на виртуалке А

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/ac437fdb-770d-4658-8bee-a0c388cab3c0">
</p>

Шаг №4. Отправка запроса с машины С на 5000 порт машины А

Машина С:

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/a1267b21-b8f3-4dd9-9373-9e25d2899e89">
</p>

Машина А:

<p align="center">
<img src="https://github.com/hanz0m4/devops/assets/166024789/5ab50d2b-3adb-403b-bbea-2b9acc16e976">
</p>

## Bash-скрипты для виртуалок А, Б и С

Также в рамках задания необходимо было прописать bash-скрипт для каждой виртуалки, который позволит в дальнейшим упростить запуска наших машин.

Виртуалка А.

```
#!/bin/bash
echo "Adapter for A"
ip link add macvlan1 link eth0 type macvlan mode bridge
ip address add dev macvlan1 192.168.24.10/24
ip link set macvlan1 up
ip route add 192.168.2.0/24 via 192.168.24.1

pip install flask

touch app.py

from flask import Flask, request

app = Flask(__name__)

@app.route('/', methods=['GET'])
def get_request():
return 'GET request'

@app.route('/', methods=['POST'])
def post_request():
data = request.get_json()
return f'POST request with data: {data}'

@app.route('/', methods=['PUT'])
def put_request():
data = request.get_json()
return f'PUT request with data: {data}'

app.run(host='0.0.0.0', port=5000)

python app.py
```
Виртуалка Б.
```
#!/bin/bash
echo "Configuring adapter for A"
ip link add macvlan1 link eth0 type macvlan mode bridge
ip address add dev macvlan1 192.168.24.1/24
ip link set macvlan1 up
echo "Adapter for A - ready\n"

echo "Configuring adapter for C"
ip link add macvlan2 link eth0 type macvlan mode bridge
ip address add dev macvlan2 192.168.2.1/24
ip link set macvlan2 up
echo "Adapter for C - ready\n"
```
Виртуалка С.
```
#!/bin/bash
echo "Configuring adapter for subnet C"
ip link add macvlan1 link eth0 type macvlan mode bridge
ip address add dev macvlan1 192.168.2.10/24
ip link set macvlan1 up
ip route add 192.168.24.0/24 via 192.168.2.1

echo "Adapter for C - ready"

printf "Sending request"
curl "http://192.168.28.10:5000"
```

19 changes: 19 additions & 0 deletions application/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import Flask, request

app = Flask(__name__)

@app.route('/', methods=['GET'])
def get_request():
return 'GET request'

@app.route('/', methods=['POST'])
def post_request():
data = request.get_json()
return f'POST request with data: {data}'

@app.route('/', methods=['PUT'])
def put_request():
data = request.get_json()
return f'PUT request with data: {data}'

app.run(host='0.0.0.0', port=5000)
32 changes: 32 additions & 0 deletions configs/MachineA.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
echo "Adapter for A"
ip link add macvlan1 link eth0 type macvlan mode bridge
ip address add dev macvlan1 192.168.24.10/24
ip link set macvlan1 up
ip route add 192.168.2.0/24 via 192.168.24.1

pip install flask

touch app.py

from flask import Flask, request

app = Flask(__name__)

@app.route('/', methods=['GET'])
def get_request():
return 'GET request'

@app.route('/', methods=['POST'])
def post_request():
data = request.get_json()
return f'POST request with data: {data}'

@app.route('/', methods=['PUT'])
def put_request():
data = request.get_json()
return f'PUT request with data: {data}'

app.run(host='0.0.0.0', port=5000)

python app.py
12 changes: 12 additions & 0 deletions configs/MachineB.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
echo "Configuring adapter for A"
ip link add macvlan1 link eth0 type macvlan mode bridge
ip address add dev macvlan1 192.168.24.1/24
ip link set macvlan1 up
echo "Adapter for A - ready\n"

echo "Configuring adapter for C"
ip link add macvlan2 link eth0 type macvlan mode bridge
ip address add dev macvlan2 192.168.2.1/24
ip link set macvlan2 up
echo "Adapter for C - ready\n"
11 changes: 11 additions & 0 deletions configs/MachineC.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
echo "Configuring adapter for subnet C"
ip link add macvlan1 link eth0 type macvlan mode bridge
ip address add dev macvlan1 192.168.2.10/24
ip link set macvlan1 up
ip route add 192.168.24.0/24 via 192.168.2.1

echo "Adapter for C - ready"

printf "Sending request"
curl "http://192.168.28.10:5000"
Binary file added pictures/A - C.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Bash_A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Bash_B.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Bash_C.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/C - A - 2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/C - A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Flask.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Http-server-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Http-server.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Key_A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Key_B.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Key_C.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Request-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Request-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/Virtual machines.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/adapter_A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/adapter_B_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/adapter_B_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/adapter_C.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.