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.
Standart Wordpress OutPut
GCP PROD Workspace:
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.
- Agent Pools
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.
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.
(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
(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'
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
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);
?>
📧 How to make a mail server
🤖 How to make notification bot
🖥️ How to launch Ubuntu Desktop on Google Cloud