Files
homework42/README.md
2026-04-19 18:22:29 +03:00

115 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Домашнее задание 42
## Развертывание веб приложения
Для выполнение задания используется vagrant box Ubuntu 22.04
### Создание Vagrantfile
Зададим следующие характеристики для VM
- CPU - 1
- Memory - 1024mb
С хостовой машины прокинем 3 порт
8080 - 8080
8081 - 8081
8082 - 8082
Готовый [Vagrantfile](Vagrantfile)
### Cоздание ansible.yml
Сценарий для Ansible будет выполнять следующие действия:
1. Установка nginx, nodejs, php, mysql, flask
2. Создает базу mysql для wordpress, а так же нового пользователя для wordpress
3. Скачивает wordpress и разархивирует
4. Создает файл wp-config.php на основе wp-config-sample.php, и прописывает настройки базы mysql
5. Создает простой (Hello World!) сайт на flask
6. Запускает flask как сервис flask-hello
7. Создает простой (Hello World!) сайт на nodejs
8. Запускает nodejs как сервис nodejs-hello
9. Настраивает nginx для wordpress (порт 8080) через php-fpn, для flask (порт 8081) и nodejs (порт 8082) как прокси
Готовый [ansible.yml](ansible.yml)
### Проверка
Запускаем vagrant
```bash
alex@ubuntu-pc:~/Документы/42$ vagrant up
Bringing machine 'web' up with 'virtualbox' provider...
==> web: Importing base box 'ubuntu/jammy64'...
==> web: Matching MAC address for NAT networking...
==> web: Checking if box 'ubuntu/jammy64' version '20241002.0.0' is up to date...
==> web: Setting the name of the VM: 42_web_1776611376317_27957
==> web: Clearing any previously set network interfaces...
==> web: Preparing network interfaces based on configuration...
web: Adapter 1: nat
==> web: Forwarding ports...
web: 8080 (guest) => 8080 (host) (adapter 1)
web: 8081 (guest) => 8081 (host) (adapter 1)
web: 8082 (guest) => 8082 (host) (adapter 1)
web: 22 (guest) => 2222 (host) (adapter 1)
==> web: Running 'pre-boot' VM customizations...
==> web: Booting VM...
==> web: Waiting for machine to boot. This may take a few minutes...
web: SSH address: 127.0.0.1:2222
web: SSH username: vagrant
web: SSH auth method: private key
web: Warning: Connection reset. Retrying...
web: Warning: Connection reset. Retrying...
web:
web: Vagrant insecure key detected. Vagrant will automatically replace
web: this with a newly generated keypair for better security.
web:
web: Inserting generated public key within guest...
...
...
TASK [conf nginx wordpress] ****************************************************
changed: [web]
TASK [conf nginx flask] ********************************************************
changed: [web]
TASK [conf nginx nodejs] *******************************************************
changed: [web]
TASK [site wordpress enable wordpress] *****************************************
changed: [web]
TASK [site flask enable] *******************************************************
changed: [web]
TASK [site nodejs enable] ******************************************************
changed: [web]
TASK [restart Nginx] ***********************************************************
changed: [web]
PLAY RECAP *********************************************************************
web : ok=27 changed=24 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
Пробуем открыть адрес http://127.0.0.1:8080 на хостовой машине
![42_1](images/42_1.png)
Видим страинцу приветствия wordpress
Открываем адрес http://127.0.0.1:8081
![42_2](images/42_2.png)
Видим Hello World на flask
Открываем адрес http://127.0.0.1:8082
![42_3](images/42_3.png)
Видим Hello World на nodejs
Задание полностью выполнено!