Skip to content
/ LinOps Public

Examination work on the course of Devops engineer. The work reflects some skills obtained on the course.

Notifications You must be signed in to change notification settings

mlinops/LinOps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ubuntu-linux-minimalizm

LinOps religion

Hey! Lina is back ❤️

The basis for the work of the project are such systems as:

Technologies used in this project:

💜 Terraform is a tool from Hashicorp that helps you manage infrastructure declaratively. In this case, you do not have to manually create instances, networks, etc. in the console of your cloud provider; it is enough to write a configuration that will outline how you see your future infrastructure.
🔆Ansible is open source software that automates software delivery, configuration management, and application deployment.
🐳 Docker is a software for automating the deployment and management of applications in containerized environments, an application containerizer.

ksdfghjk

Project stend

изображение

ksdfghjk

Pipelines: изображение

Release CI/CD pipeline: изображение

Standart Wordpress OutPut

изображение

GCP PROD Workspace:

изображение

ksdfghjk

A bit of magic with Merlin VMs: 🪄

The good wizard Merlin came to help my project. Yes, yes, it was he who created 3 managing Ansible servers for each workspace. (It's a joke...)

Merlin VMs это - remote Ansible servers managed by Azure DevOps through an agent. Each workspace has its own 'wizard'.

Merlins can:

  • manage application configuration and deployment
  • slave servers monitoring
  • back up databases on slave servers
  • send messages to telegram bot

VMs had the Azure Pipeline Agent installed, therefore can be controlled when performing jobs of CI/CD pipelins.

~ Taking off his hat, he took a deep breath. All tests have been passed. Finally got some tea.

Let's take a closer look at Merlin virtual machines:

изображение

As you can see, each Merlin is assigned to his space. Connecting directly to 'dynamic' machines is done by creating an SSH connection.

ksdfghjk

Merlin VMS in Azure DevOps:

  • Agent Pools

изображение

DEV pool изображение

TEST pool изображение

PROD pool изображение

ksdfghjk

📫 Telegram notifications

To implement the project, monitoring the implementation of tasks was vital. Therefore, a special 'LinOps' bot was created for the project, which, after passing the CI / CD stages, sends a notification to the group in a telegram.

Безымянный

ksdfghjk

Monitoring

In order for Telegram to tell us about the availability of virtual machines and about creating a database backup, we need scripts with the creation of a notification.

🧐 Monitoring script

(Cron + Script --> ❗ Telegram notifications)

#!/bin/bash

# This script checks the availability of host

### Add the task to the CRON [/etc/crontab] ##############################
#                                                                        #   
#        * * * * * root bash /path/to/script > /dev/null 2&>1            #
#                                                                        #        
## In this case, sending 1 package is carried out every minute ###########

ping -t <HOST>

if [ $? -eq 0]; then
curl 'https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=<CHAT_ID>&text=WARNINNG! Server status NOT OK -- <HOST>'
else
echo OK >> /dev/null
fi

BackUp script

(Cron + Script --> ❗ Telegram notifications)

#!/bin/bash

# This script makes a backup copy of the necessary database from a remote host

## Add the task to the CRON [/etc/crontab] ###################################
#                                                                            #   
#          * * * * * root bash /path/to/script > /dev/null 2&>1              #
#                                                                            #         
## In this case, sending 1 package is carried out every minute ###############

now=$(date "+%Y-%m-%d-%S")
filename="$now.sql.gz"
ssh <USER>@<HOST> "mysqldump -u <DB_USER> -p<PASSWORD> <DB_NAME> | gzip -9" > /backup/$filename 
curl 'https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=<CHAT_ID>&text=Wordpress database backup create'

fff

To track the execution of CRON tasks, you can use an interesting service CRONITOR

изображение

To install and configure, you need to run the commands:
Install CronitorCLI:

curl https://cronitor.io/install-linux?sudo=1 -H "API-KEY: 3122de7d6ffb44a49558c53a4b3b4a00"  | sh

Run cronitor discover to selectively add monitoring to each job in your crontab files:

cronitor discover

ksdfghjk

✔️ Adding an article:

To add an article to a Wordpress site, we will use a script that must be placed in the Wordpress root folder:

<?php

require_once( dirname(__FILE__) . '/wp-load.php' );
require_once( dirname(__FILE__) . '/wp-admin/includes/admin.php' );

$post_data = array(
    'post_title'    => 'New test post with an additional field',
    'post_content'  => 'Content of the test post with an additional field',
    'post_status'   => 'publish',
    'post_author'   => 1,
    'post_category' => array(1)
);

// Create a post with required fields.
$post_id = wp_insert_post($post_data, true);
print_r($post_id);

?>

A few articles that might help you:

📧 How to make a mail server
🤖 How to make notification bot
🖥️ How to launch Ubuntu Desktop on Google Cloud

ubuntu-linux-minimalizm