How to create Raid1 mirroring with 3rd & 4th Drives in OVH servers

OVH panel offers easy Raid configuration for the partitions in up to 2 drives. Recently I was working on a server that has 2 SSDs and 2 HDDs. The server is intended to serve as a Shared Hosting server. My idea was to install the OS on the SSDs and use the HDDs for hosting website data. It was not much of a hassle to install the OS on SSds on Raid1. I can easily add the two HDDs as additional drives and mount them both to be used for storage. But there’s a drawback in such configuration. There will be no redundancy for the storage drives. If any of those HDDs crash – I will lose all data on it. So, my idea is to create another Raid1 with the two HDDs. Unfortunately, it is not possible from the OVH panel and OVH denied any support on this issue. Therefore I had to do it myself.

Since many of the server providers are offering servers with 4 drives – I believe some of you might find this useful. The idea is to create two Raid arrays of 4 drives. In this case – the two SSDs were already in Raid 1 – configured by the OVH panel. So what I needed to do is to create another Raid 1 with the other two HDDs.

Here is how the initial configuration looked like:

#lsblk

ovh default settings with 4 drives

There already is a Raid1 between the second partitions of the two SSDs (nvme0n1p2 & nvme1n1p2). The two HDDs are “sda” & “sdb” which are unformatted and no partitions are created.

The basic steps are as follows:

  1. Create a partition in sda with full volume
  2. Create a partition in sdb with full volume
  3. Create a Raid1 with the two partitions from sda & sdb
  4.  Set the file system (ext4) for the newly created Raid1
  5. Mount the newly created Raid1 to be used as the new volume in the server.

IMPORTANT NOTES:

To check the current Raid configuration:
#cat /proc/mdstat

To create a new partition in a drive:
# fdisk /dev/sd[x]

fdisk can create partitions with max 2TB. Here in my case the two HDDs were of 4TB each. Therefore I had to use GPT parted to create the partition. If you want to learn more about GPT click here.

1. Create a partition in sda with full volume:

# parted /dev/sda

Output:

GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted)
Creates a new GPT disklabel i.e. partition table:
#(parted) mklabel gpt
Sample outputs:
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted)

Next, set the default unit to TB, enter:
#(parted) unit TB

To create a 3.7TB partition size, enter:
#(parted) mkpart primary 0 0
OR
#(parted) mkpart primary 0.00TB 3.70TB

To print the current partitions, enter:
#(parted) print

Sample outputs:
Model: ATA ST33000651AS (scsi)
Disk /dev/sda: 3.70TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 0.00TB 4.00TB 4.00TB ext4 primary

Quit and save the changes, enter:
#(parted) quit
Sample outputs:
Information: You may need to update /etc/fstab. (Since we will be creating Raid with this partition – not need to add this in /etc/fstab in this case)

Use the mkfs.ext3 or mkfs.ext4 (ext4 preferred) command to format the file system, enter:
# mkfs.ext3 /dev/sda1

OR
# mkfs.ext4 /dev/sda1

2. Create a partition in sdb with full volume

# parted /dev/sdb

#(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted)

Next, set the default unit to TB, enter:
#(parted) unit TB

To create a 3.7TB partition size, enter:
#(parted) mkpart primary 0 0
OR
#(parted) mkpart primary 0.00TB 3.70TB

To print the current partitions, enter:
#(parted) print
Sample outputs:

Model: SATA ST33000651AS (scsi)
Disk /dev/sdb: 3.70TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 0.00TB 4.00TB 4.00TB ext4 primary

Quit and save the changes, enter:

#(parted) quit

Sample outputs:
Information: You may need to update /etc/fstab.

Use the mkfs.ext3 or mkfs.ext4 (ext4 preferred) command to format the file system, enter:
# mkfs.ext3 /dev/sdb1
OR
# mkfs.ext4 /dev/sdb1

IMPORTANT NOTE:
BEFORE PROCEEDING TO NEXT STEP CHECK THE FILE SYSTEMS OF THE NEWLY CREATED PARTITIONS OF THE TWO DRIVES:

#fdisk -l

If you see something like the following:
partition file type microsoft basic

You need to do some extra steps to convert these partitions to ext4. Please check the (#13 reply) THIS LINK for details.
=============================================================
Solution: Install gdisk (yum install gdisk) (Check: https://bbs.archlinux.org/viewtopic.php?id=191163 (check #13 reply))
NEED TO CHANGE THE FILE SYSTEMS (reported by fdisk -l) from Microsoft Basic to “Linux File System” with the above-mentioned solution)

# yum install gdisk
# gdisk /dev/sda 🙁
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

#Command (? for help): t
#Partition number (1-1): 1
Current type is ‘Microsoft basic data’
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to ‘Linux filesystem’

#Command (? for help): p
#Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.

DO THE SAME FOR SDB
=============================================================

3. Create a Raid1 with the two partitions from sda & sdb

We already had a Raid1 of the two partitions from SSD named “md2”. We can find it:

# cat /proc/mdstat

In steps 1 & 2 – we created two new partitions in “sda” & “sdb” named “sda1” & “sdb1” respectively.
partitions 3rd 4th drive no raid yet

Check the Raid status of sda1 & sdb1:
# mdadm –examine /dev/sd[a-b]1
– it will show no raid

NOW run the following to create the Raid1 between sda1 and sdb1:
# mdadm –create /dev/md3 –level=mirror –raid-devices=2 /dev/sd[a-b]1

The name of the new Raid1 array is “md3”.

Now check the “lsblk” again and it will show “md3” 3.7TB
md3 raid sda1 sdb1

Now if you check Raid status ( # cat /proc/mdstat ) you’ll see the Raid partitions sda1 & sdb1 are syncing.
md3 sda1 sdb1 sync

The 4TB disks took almost 5 hours to complete the syncing.

4. Set the file system (ext4) for the newly created Raid1

Execute the following command to set the file system (ext4) of the newly created md3 Raid drive:

# mkfs.ext4 /dev/md3

5. Mount the newly created Raid1

We want to mount the newly created Raid1 (md3) to the directory “/home2”. We need to do the following:

# mkdir /home2
# mount /dev/md3 /home2

md3 mounted home2

Now we need to edit /etc/fstab and add the new Raid volume – so that the storage volume is not lost after the server reboots.
edit etc fstab to save the storage volume home2

# nano /etc/fstab

add the following line: /dev/md3 /home2 ext4 defaults 0 0

and save the file. That’s it. The new storage volume will remain after server reboot and we can use this to store our data. If we now check the storage details – we will see the following:

final storage details after adding second raid1 storage

The process will be the same for servers from any provider and not only OVH. Feel free to add your suggestion if you think anything can be improved here or if you encounter any problems by following this article. Thank you.

How to clean /tmp directory automatically in Linux/cPanel using tmpwatch

The “tmpwatch ” command in linux is to removes files which haven’t been accessed for a period of time. The tmpwatch recursively removes files which haven’t been accessed for a given time. Normally, it’s used to clean up directories which are used for temporary holding space such as /tmp.

If you are noticing “/tmp” getting overloaded with files and not sure which files/folders to delete – you better use “tmpwatch” to cleanup or delete files/folders from the “/tmp” directory.

You’ll need SSH root access to install tmpwatch and add it in the cron. If your server is inaccessible due to “/tmp” getting full – you may restart the server and that should free up some space after reboot.

  1. Login to the server as root using SSH
  2. Run the following command:

    #yum install tmpwatch -y

  3. To delete temporary files (for example after every 12 hours) run the following command:

    #/usr/sbin/tmpwatch -am 12 /tmp

  4. The next step is to configure tmpwatch to run automatically through a cron. To do that type the following command:

    #crontab -e

  5. The above command will open the cron job list for the user root. Now go to the bottom and add the following line and save the file:

    0 4 * * * /usr/sbin/tmpwatch -am 12 /tmp

    If you are unable to add the above line, you may navigate to “/var/spool/cron” and open the cron file “root” with a text editor (such as, vi, nano). Add the line at the bottom and save the file:

    0 4 * * * /usr/sbin/tmpwatch -am 12 /tmp

Check the usage of “/tmp” and it should be clean by now.

Thank you.

How to force redirect http to https using .htaccess

how to force http to https redirection htaccess

If you have an SSL certificate installed and would like to force your website to load with https URL – you may add the following code in the .htaccess file (Linux based hosting):

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

You need to place the .htaccess file in the home directory of your website.

 

10 best Web Hosting companies – Plans & Pricing 2019

# 1


hostgator logo

HostGator is the largest shared hosting service provider in the whole world. There are good reasons for which millions of clients host there websites with HostGator. There service quality and support is superb and that is what set's them apart from others. Following are their Shared hosting packages:

shared hosting packages of hostgator

Besides Shared hosting - HostGator offers: Cloud Hosting, WordPress Hosting, VPS & Dedicated Servers.

# 2


siteground logo

SiteGround is popular hosting service provider which is known for its rock solid services and unbeatable support. Their shared hosting packages are as follows:

shared hosting packages of siteground

 

Besides Shared hosting - SiteGround offers: Cloud Hosting, WordPress Hosting and WooCommerce Hosting.

# 3


siteground logo

Eleven2 is a US-based web hosting service with a global presence. It was founded in 2003 and its office address is in Los Angeles. Eleven2 offers two types of shared hosting - Shared hosting with Standard storage and Shared hosting with SSD. Eleven2's shared hosting packages are as follows:

shared hosting packages of eleven2
SSD shared hosting packages of eleven2
Eleven2 Offers other services like: Reseller Hosting, SSD Reseller Hosting, Virtual Private Servers and Cloud Hosting.

# 4


bluehost logo

Bluehost is a web hosting company owned by Endurance International Group. It is one of the 20 largest web hosts, collectively hosting well over 2 million. If you are looking for a good web hosting company, you have probably heard of Bluehost. They are a popular and quickly growing web hosting company. BlueHost's shared hosting packages are as follows:

shared hosting packages of bluehost

Bluehost Offers other services like: Cloud Hosting, WordPress Hosting, Virtual Private Servers.

# 5


ipage logo

iPage is a popular web hosting platform for a very big number of websites. It is one of those inexpensive hosting providers who provides quality hosting services with great support. iPage shared hosting packages are as follows:

shared hosting packages of ipage

iPage Offers other services like: Dedicated Hosting & VPS Hosting.

# 6


justhot logo

JustHost is a simplified hosting provider which provides hosting packed with a lot of features - backed by their extremely good support. JustHost shared hosting packages are as follows:

shared hosting packages of justhost

JustHost doesn't offer any other services - but they do offer useful marketing tools (Google Ads credit) to get started well.

# 7


7uphost logo

7upHost is global web hosting service provider operating from Bangladesh. Established in 2008 it has been serving clients from all over the world. They offer rock solid hosting with a friendly support. 7upHost shared hosting packages are as follows:

shared hosting packages of 7uphost

7upHost offers all kinds of web hosting besides shared hosting: SSD Hosting, Reseller Hosting, Virtual Private Server, Dedicated Server, Managed AWS Hosting, Google Cloud, GSuite and Professional Email Hosting services.

# 8


A2 Hosting logo

A2 Hosting is much talked web hosting service provider now a days for their diversified hosting services. Their shared hosting packages are as follows:

shared hosting packages of A2 Hosting

A2 Hosting offers a variety of services like: WordPress Hosting, Reseller Hosting, Virtual Private Server, Dedicated Server.

# 9


DreamHost logo

DreamHost is one of those veteran web hosting providers still popular across the globe. Their shared hosting packages are as follows:

shared hosting packages of dreamhost

Other Services by DreamHost: Cloud Hosting, Virtual Private Server, Dedicated Hosting.

# 10


GreenGeeks logo

GreenGeeks is wellknown as an environment freidnly hosting service Provider. Their datacenters are powered by renewal energy sources. They are also reputed for their incredible hosting services and support. Their shared hosting packages are as follows:

shared hosting packages of greengeeks

GreenGeeks offers a variety of web hosting solutions, including shared hosting, reseller hosting, virtual private server hosting and dedicated Hosting.

Whitelist IP or IP range in/out using iptables

#Flush existing rules
iptables -F

# Set up default DROP rule for eth0 (Assuming eth0 is the Ethernet Port)
iptables -P INPUT DROP

# Allow existing connections to continue
iptables -A INPUT -i eth0 -m state –state ESTABLISHED,RELATED -j ACCEPT

# Accept everything from the 192.168.0.x network
iptables -A INPUT -i eth0 -s 192.168.0.0/24 -j ACCEPT

# Allow connections from this host to 192.168.1.10
iptables -A OUTPUT -o eth0 -d 192.168.1.10 -j ACCEPT

GMail Phishing scam – Becareful !!

If you are a tech savvy person – you probably know how phishing works. However, this time attackers tried to use optical illusion to trap people into a new phishing scam targeting the GMail users. Here’s how it looks like:

gmail phishing scam URL

Scammers attach an image which looks like it is an attachment. When you click on it – it takes you to the scammers destination – to the phishing link. And if you ignore the login URL – you are DONE!!

The phishing login page has been tricked as well to look like it is from Google. So even the most savviest person may fall for the trick. Here is how the phishing page URL will look like:

gmail phishing scam data url

Img credit: The Hacker News

 

So, next time you are forwarded to any login page – double – triple check.

You may find more about it in this link.