What is Multi-Cloud? How to improve your cloud strategy for 2018

For the past few years cloud computing has made it’s stable grounds in every tech company. With the wider adoption of clouds, the better services and tools and the vast investments in automation and scalability, now it’s time to pay a bit more attention on the quality of the service and end user experience and multi-cloud is the strategic approach that will be the main driving power in 2018.

Read More

Easy live partition resizing on Ubuntu 16.04

Overview

A great benefit of the cloud servers is the easy scaling of resources up and down. But after scaling to a larger cloud machine and acquiring more storage space, you should extend the Linux partitions on it as well as the file system, in order to use that new space.

The tricky part here comes when you want to resize the root partition and some old methods included taking your server off, mounting the storage drive on another Linux machine and resizing the partitions. That of course is very inconvenient in the case of a production server and there are better ways to resize your root partition without having to take it offline.

Read More

How to setup LXD Linux containers on Ubuntu 16.04 cloud machine?

Overview

Containers are a great tool for any scale, from a small dev environment set up on a cloud machine to a large and scalable applications infrastucture. The main benefits are the lightweight, fast and easy setup and the plenty of flexibility.

In this tutorial we’ll take a look at LXD containers – one of the most popular at the moment, especially good for its “virtual machine” like containerization.

Read More

How to setup automatic MySQL backup on Ubuntu/Debian and CentOS

   Overview

   This tutorial is to guide you on setting up a simple, automatic MySQL database backups using mysqldump and a cron job.

   Prerequisites

       

  •        Installed and running MySQL server
  •    

  •        SSH access
  •    

  •        root or sudo user

   Step 1: Backing up  a MySQL database

   You can use the ‘mysqldump’ that comes in any standard MySQL installation to do a database dump from the shell. To backup the ‘exampledb’ database to a file do:

   

       mysqldump -uroot -p exampledb > exampledb.sql

   Note that there is no space between the ‘-u’ switch and the user (root). With the ‘-p’ switch and paramater after it the ‘mysqldump’ will prompt you to enter a password.

   This command will output plain SQL queries in the exampledb.sql, but as they are text they can be compressed really good to save space. So to make a compressed backup, let’s do:

   

       mysqldump -uroot -p exampledb | gzip > exampledb.sql.gz

   You can use these commands to make manual backups of your databases. If you want to backup all databases on a server, use the ‘–all-databases’ switch instead of database name, like this:

   

       mysqldump -uroot -p –all-databases| gzip > mysql_server.sql.gz

   Step 2: Setting an automated scheduled backup of a MySQL database

   Now that you know how to make manual database backups, let’s automate them with a cron job. You must set up a cron job that calls the ‘mysqldump’ tool on a schedule.

   First let’s make a directory  for storing the backups:

   

       mkdir /var/backups/mysql

   As backups are more usefull when they provide history, let’s give the backup file with more meaningful name by adding the date and time when the backup was taken:

   

       mysqldump -uroot -p exampledb | gzip > /var/backups/mysql/exampledb.$(date +”%Y_%m_%d_%I_%M”).sql.gz

   To automate the backup process ‘mysqldump’ must have the user password inline, so it’s highly recommended to set up an additional database user specifically for backups.

   Open a crontab editor:

   

       crontab -e

   and add the following line at the bottom:

   

       0 1 * * *    mysqldump -uroot -p exampledb | gzip > /var/backups/mysql/exampledb.$(date +”\%Y_\%m_\%d_\%I_\%M”).sql.gz

   The “0 1 * * *” stands for a schedule on every 01:00 or everyday at one after midnight. The cron line format is “m h  dom mon dow   command”, where: 

       

  •        m – is for minutes
  •    

  •        h – is for hour
  •    

  •        dom – is the day of the month
  •    

  •        mon – is the month 
  •    

  •        dow – day of the week

   The  ‘*’ symbol in any of these means “on every” minute, hour, day and so.

    

   Saving the crontab will set your backup on schedule and you are good to go.

How to open SSH port on Ubuntu / Debian with ‘ufw’

   Ufw or ‘uncomplicated firewall’ is a really nice tool that allows you to easily manage ‘iptables’ firewall in Linux with a bit more user friendly frontend instead of ‘iptable’ chains and rules.

   It’s included in the most recent version of Debian and Ubuntu and we’ll start with a simple example – how to open or restrict SSH access to your cloud server.

   To allow the SSH port:

   

       ufw allow ssh

   or

   

       ufw allow 22/tcp

   This will open the SSH port ( TCP 22 ) to the entire world.

   Your cloud server is a public machine and you might want to protect it a bit better than being open to the whole Internet. To restrict the SSH access from only one IP address you can do:

   

       ufw allow from your_ip_address to any port 22

   for example

   

       ufw allow from 78.130.176.1 to any port 22

   You can also allow SSH access to you server from a range of addresses using the network slash notation:

   

       ufw allow from 78.130.176.0/24 to any port 22

    

   Before we are ready to go with your new firewall setup with ‘ufw’ we can check if it’s enabled by:

   

       ufw status

   and eventually if you get “status: inactive” enable it:

   

       ufw enable

    

   Get updates on cloud server security topics by following CloudBalkan.

Recursive search for a word in directory contents with grep and rgrep

   An easy way to search for a word within directory contents is the ‘rgrep’ command:

   

       rgrep “word /some/directory

   If you don’t have the rgrep command installed on your distribution, you can use grep with the following flags:

   

       grep -rnw “word/some/directory

    

   Example:

   

       grep -rnw “Failed password” /var/log/auth.log

   will list you all unsuccessful login attempts on your machine.

    

    

How to create an ‘tar’ archive from files newer than specified date

   If you need to archive only the recently modified files you can use this simple syntax of the ‘tar’ command:
    

   

       tar czf target-filename -N “8 hours ago” source-directory
    
   The ‘-N’ flag (newer) accepts standard GNU relative date formate like “8 hours ago”, “1 day ago” and “-1 month” aswell
    
   The ‘tar’ archive preserves the directory tree with all subfolders, making this command quite useful for easy file system incremental backups.
    
   An example use of the command to backup your web files modified during the last day, will look like:
    

   

       tar czf /var/backup/archive.tar.gz -N “1 day ago” /var/www