Wednesday, 11 January 2017

Software RAID 1 in Windows 7 for Increased Data Security

 Software RAID 1
Software RAID 1, or "Mirroring", makes an exact copy of all the data between two disks. So, when one of the drives fails - because HDD failure is a matter of time - all data is safe on the other disk. Let's create a software RAID 1 in Windows 7.
To create software RAID 1 with Windows 7, we will need two hard disk drives - preferably of the same size - and at least Windows 7 Professional or Windows 7 Ultimate.
Software RAID 1 in Windows 7 for Increased Data Security 00

We can't create a software RAID 1 in Windows 7 Home Premium

Software RAID in Windows 7 is nothing less than a mess. Different Windows 7 versions have arbitrary restrictions on which RAID levels they allow us to create.
If we bought a PC with pre-installed Windows 7, we probably have Windows 7 Home Premium. That means that software RAID 1 is out of reach.
Software RAID 1 in Windows 7 for Increased Data Security 01
Due to licensing reasons, on Windows 7 Home Premium we can only create a RAID 0, "Striping", which is a useless type of RAID for data security.
Software RAID 1 in Windows 7 for Increased Data Security 02
When one disk fails in the RAID 0, all the data from all the disks is lost, permanently and without any chance of recovery.
The "Spanned Volume" option isn't even RAID. It's a JBOD array (Just a Bunch of Disks), where two or more disks appear as a single large disk. But this too doesn't offer any data security, when one disk is lost, all the data from every disk in the array is lost.
So, we won't be covering either scenario in Windows 7 Home Premium.

Why software RAID 1 and not software RAID 5?

For the same arbitrary licensing reasons, software RAID 5 is completely off-limits to any version of Windows 7.
We will find the option by right-clicking on the drive, but it will always be grayed-out, just taunting us with what it would be...
Software RAID 1 in Windows 7 for Increased Data Security 02a
Only Windows Server editions - as old as Windows 2000 server - can create a software RAID 5.
With RAID 0 being useless for data security and RAID 5 being unavailable, creating a software RAID 1 in Windows 7 is the only viable option.

How to create a software RAID 1 in Windows 7

As we mentioned earlier, on a level 1 RAID two disks have the exact copy of all the data at any single moment. So, when one of them fails, the data is safe on the other.
Software RAID 1 in Windows 7 for Increased Data Security 04
The downside of RAID 1 is that we lose 50% of the total disk capacity. If we use two 1TB disks for RAID 1, the array will have a 1TB capacity in total.
To create the software RAID, we press the Windows key + R, to open the "Run" dialogue, and type:
diskmgmt.msc
Software RAID 1 in Windows 7 for Increased Data Security 05

Creating a software RAID 1 with brand new disks

If both of the disks we will use for the Software RAID 1 are brand new, once we open the Disc Management console, we will get a message to initialize the disks.
Software RAID 1 in Windows 7 for Increased Data Security 06
If the disks are smaller than 2TB each, the MBR partition style is good enough. Else, we need to select the GPT partition style.
After that, we right-click on one of the two unallocated volumes, and select "New Mirrored Volume...".
Software RAID 1 in Windows 7 for Increased Data Security 08
On the New Mirrored Volume Wizard, we add the 2nd disk...
Software RAID 1 in Windows 7 for Increased Data Security 09
...which will allow us to move forward.
Software RAID 1 in Windows 7 for Increased Data Security 10
In theory, we can have more than two disks in a RAID 1 array, but they will all be copies of one disk, and a terrible waste of space. Four 1TB disks in RAID 1 give us a 1TB array, with 75% of the total capacity lost.
Finally, we assign a drive letter to the new array...
Software RAID 1 in Windows 7 for Increased Data Security 11
...and format it to NTFS.
Software RAID 1 in Windows 7 for Increased Data Security 12
The system warns us that this operation will convert basic disks to dynamic. The only downside of that is that we can't dual-boot another operating system from a dynamic disk e.g. a Linux distribution or another version of Windows.
Software RAID 1 in Windows 7 for Increased Data Security 13
By choosing "Yes", our Software RAID 1 in Windows 7 is ready.
Software RAID 1 in Windows 7 for Increased Data Security 14
We will find it in the "Computer", as a single disk.
Software RAID 1 in Windows 7 for Increased Data Security 15

Creating a Software RAID 1 copy of an existing data disk or partition

Let's say we didn't buy two more disks but had already a disk or partition containing our data, and bought another disk to create a RAID 1.
In this case, we right-click the NTFS volume and select "Add Mirror...".
Software RAID 1 in Windows 7 for Increased Data Security 16
The system will show us the new disk, and we click on Add Mirror.
Software RAID 1 in Windows 7 for Increased Data Security 17
Both the disk we already had and the new disk will be converted to dynamic disks.
Software RAID 1 in Windows 7 for Increased Data Security 18
The software RAID 1 is created and starts resynching.
Software RAID 1 in Windows 7 for Increased Data Security 19
As you can see, the original data we had on the single disk isn't lost, and we have complete access to it while the RAID is resynching.
Software RAID 1 in Windows 7 for Increased Data Security 20
It's best to leave the RAID 1 resynching complete before we do any intensive writing or deleting of data. It is a strenuous procedure for the disks, and we shouldn't make it any harder. Disks are known to have failed during the RAID resynching.

Creating a Software RAID 1 for the Windows installation

Since we don't need to format both drives to create Software RAID 1, we can also create a RAID 1 with the Windows installation. But we shouldn't do this if we wish to dual-boot with another operating system, because of the dynamic disk restrictions we mentioned earlier.
We just need to mirror both the System Reserved partition...
Software RAID 1 in Windows 7 for Increased Data Security 20a
...and the C: partition.
Software RAID 1 in Windows 7 for Increased Data Security 20b
Mind you that if, for some reason, we don't have a "System Reserved" partition, it's impossible to create a bootable software RAID 1, the option will be grayed out.
Software RAID 1 in Windows 7 for Increased Data Security 20ba
Now, on each system startup, we will get two boot options, one for each disk.
Software RAID 1 in Windows 7 for Increased Data Security 20c
Both installations are identical, so it doesn't matter if we choose the "secondary plex" one.

What happens when one disk fails in RAID 1

When one of the hard drives does fail, we get a "Failed Redundancy" message at the Disk Management console.
Software RAID 1 in Windows 7 for Increased Data Security 21
We still have complete access to our data, and nothing is lost provided the other disk still works properly.
Unfortunately, the system doesn't give us any warning whatsoever that one of the disks has failed.
This is a huge oversight, especially if we consider that a Linux Software RAID can send us an email as soon as a disk fails. But that's Microsoft for you.
We must make a habit of checking ourselves the Disk Management console every once in a while, to make sure that RAID 1 is working with both disks and full redundancy.
If we have the Windows installation on RAID 1 and lose the original disk, we will just get a cryptic message when trying to start the plain Windows 7 option.
Software RAID 1 in Windows 7 for Increased Data Security 22
In this case, we need to reset and choose the secondary plex.
Software RAID 1 in Windows 7 for Increased Data Security 23

How to fix a collapsed software RAID 1

We must replace the HDD that has failed with a new one, as soon as possible.
Software RAID 1 in Windows 7 for Increased Data Security 24
Then, before we remake the array, we take a complete backup of any essential data from the working disk, preferably on an external hard drive.
Software RAID 1 in Windows 7 for Increased Data Security 25
The last thing we want is for the only working disk also to crash while rebuilding the array.
After we have backed up our data, we remove the mirror...
Software RAID 1 in Windows 7 for Increased Data Security 26
...making sure we have selected the Missing disk...
Software RAID 1 in Windows 7 for Increased Data Security 27
After that, the missing disk entry will disappear, and we can create the RAID with the new hard drive.
Software RAID 1 in Windows 7 for Increased Data Security 28

Why choose the Software RAID 1 instead of the motherboards "hardware" RAID?

Most current motherboards boast their RAID controller.
Many users think of this as a "hardware" RAID, and thus a better solution than a software RAID 1 or software RAID 5.
The thing is that motherboard RAID isn't hardware RAID. It is software RAID, run by the BIOS and the Windows drivers.
It's a worse solution than both true software and true hardware RAID, and that is why it is known as Fake RAID. You can read about it in the linked article.
The fact is that we need an expensive hardware RAID controller - upwards of $300-$400 - to get true hardware RAID. Some cheap PCI or PCI-E controllers also use Fake RAID.
All in all, software RAID 1 in Windows 7 is far from perfect, but it is the best way to get RAID 1 on our Windows 7 PC, without paying through the nose for it.


NRPE DOCUMENTATION

SETUP AND CONFIGURE NAGIOS CLIENT (NRPE) ON CENTOS/RHEL 6.3

NRPE is called as ‘Nagios Remote Plugin Executer’. It is a Nagios plugin that allows nagios server to remotely execute plugins on other Linux/Unix machines. The main reason for doing this is to allow Nagios to monitor “local” resources (like CPU load, memory usage, etc.) on remote machines. Since these public resources are not usually exposed to external machines, an agent like NRPE must be installed on the remote Linux/Unix machines.
This article will guide you through the installation and configuration steps of Nagios Client – NRPE on CentOS 6.3.
Server side Nagios core and plugin package version:
   Nagios Core: nagios-4.0.0
   Nagios Plugin: nagios-plugins-1.4.16
To install Nagios please see my Nagios Installation Docs.
For testing purpose we have setup following machines:

IP AddressHostname
Nagios Server10.0.1.10mon001
Nagios Client10.0.1.20haproxy001
1) Prerequisite
  • Nagios server in working condition.
  • Following dependent package to compile and install.
   yum install gcc glibc glibc-common xinetd 
Create nagios user and group by which we will be installing NRPE and Nagios-Plugin
   useradd -m nagios
   password nagios
2) Installation
2.1) Create a directory where you would download nagios software:
   mkdir /usr/local/src
   cd /usr/local/src
2.2) First of all we need to Download/Untar/Compile and Install all necessary files for Nagios-Plugin:
   wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
   cd nagios-plugins-1.4.16
   ./configure --with-nagios-user=nagios --with-nagios-group=nagios
   make
   make install
2.3) Then we need to Download/Untar/Compile and Install all necessary files for NRPE:
   cd /usr/local/src/
   wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
   ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios
   make all
   make install-plugin
   make install-daemon
   make install-daemon-config

Note: NRPE by default is installed under /usr/local/nagios directory.
2.4) Install the NRPE daemon as a service under xinetd.
   make install-xinetd
2.5) We need to fix permission as well.
   chown nagios.nagios /usr/local/nagios
   chown -R nagios.nagios /usr/local/nagios/libexec 
3) Configuration
3.1) Nagios Client (NRPE) Configuration
3.1.1) Add the IP Address of the Nagios monitoring server to “only_from” directive in /etc/xinetd.d/nrpe file:
   vi /etc/xinetd.d/nrpe
   only_from = 10.0.1.10
3.1.2) Add the following entry for the NRPE daemon to the /etc/services file:
   vi /etc/services
   nrpe              5666/tcp           # NRPE
3.1.3) Restart the xinetd service:
   service xinetd restart
3.2) Validation and Testing
3.2.1) We need to check if nrpe daemon is running under xinetd:
   netstat -at | grep nrpe
   tcp        0      0 *:nrpe                      *:*                         LISTEN 
3.2.2) Now we need to do the functional testing of NRPE daemon:
   /usr/local/nagios/libexec/check_nrpe -H localhost
   NRPE v2.14
3.2.3) Some inbuild checks that we can check:
   /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
   USERS OK - 3 users currently logged in |users=3;5;10;0

   /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
   OK - load average: 0.00, 0.02, 0.00|load1=0.000;15.000;30.000;0; load5=0.020;10.000;25.000;0; load15=0.000;5.000;20.000;0;
3.3) Firewall Rule for NRPE:
3.3.1) Firewall port that needs to be open for NRPE daemon on client machine:
   iptables -A INPUT -p tcp -m tcp –dport 5666 -j ACCEPT
3.3.2) Save the Iptables rules and restart it.
   service iptables save
   service iptables restart
Once we are fully convinced that NRPE is running successfully, now is time to do full-fledged setup:
4) Nagios Server Setup
4.1) We need to Download/Untar/Compile and Install NRPE Plugin
   cd /usr/local/src/
   wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
   ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios
   make all
   make install-plugin 
4.2) Validation/Testing
Now we need to make sure that NRPE plugin (from Nagios Server) can talk to nrpe daemon (Client machine). 
   /usr/local/nagios/libexec/check_nrpe -H 10.0.1.20
   NRPE v2.14
4.3) Creating Configuration file
4.3.1) Add the following *check_nrpe* definition in “commands.cfg” file:
   vi /usr/local/nagios/etc/commands.cfg

   define command{
      command_name   check_nrpe
      command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
4.3.2) We also need to create host and service definitions
   vi /usr/local/nagios/etc/objects/hosts.cfg

   define host{
      use          linux-box
      host_name    haproxy001
      alias        HA Proxy 001
      address      10.0.1.20
      }


   vi /usr/local/nagios/etc/objects/services.cfg

   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    CPU Load
      check_command          check_nrpe!check_load
      }

   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Current Users
      check_command          check_nrpe!check_users
      }

   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Zombie Processes
      check_command          check_nrpe!check_zombie_procs
      }

   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Total Processes
      check_command          check_nrpe!check_total_procs
      }
4.3.3) Verify your Nagios configuration files:
   /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
4.3.4) If there are errors, fix them. If everything is fine, restart Nagios:
   service nagios restart
That’s it! You should see the host and service definitions you created in the Nagios web interface. In a few minutes Nagios should have the current status information for the remote Linux/Unix machine.
5) Adding Custom Checks
5.1) Nagios Client (NRPE) Setup 

5.1.1) Adding Custom and other in build Checks provided by Nagios plugins you can find it in “/usr/local/nagios/libexec/”
Let say we need to add check_swap plugin that will send warning alert if free space is less than 20% and critical alert if swap free space is less than 10%.
On the NRPE Client machine (haproxy001) verify plugin is working fine:
   /usr/local/nagios/libexec/check_swap -w 20% -c 10%
5.1.1) Once we confirm that the plugin is working fine, we need to add the command entry in config file:
   vi /usr/local/nagios/etc/nrpe.cfg
   command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
5.1.3) Restart the NRPE Daemon:
   service xinetd restart
5.2) Nagios Server Setup
5.2.1) We need to define a new service for monitoring the swap usage on the remote host, by adding line in “service.cfg” file.
   vi /usr/local/nagios/etc/objects/services.cfg
   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Swap Usage
      check_command          check_nrpe!check_swap
      }
5.2.2) Verify your Nagios configuration files and in case there is no error restart the nagios server daemon:
   /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
   service nagios reload
You should see the new service definitions that we created in the Nagios web interface.


SETUP AND CONFIGURE NAGIOS CLIENT (NRPE) ON CENTOS/RHEL 6.3

NRPE is called as ‘Nagios Remote Plugin Executer’. It is a Nagios plugin that allows nagios server to remotely execute plugins on other Linux/Unix machines. The main reason for doing this is to allow Nagios to monitor “local” resources (like CPU load, memory usage, etc.) on remote machines. Since these public resources are not usually exposed to external machines, an agent like NRPE must be installed on the remote Linux/Unix machines.
This article will guide you through the installation and configuration steps of Nagios Client – NRPE on CentOS 6.3.
Server side Nagios core and plugin package version:
   Nagios Core: nagios-4.0.0
   Nagios Plugin: nagios-plugins-1.4.16
To install Nagios please see my Nagios Installation Docs.
For testing purpose we have setup following machines:

IP AddressHostname
Nagios Server10.0.1.10mon001
Nagios Client10.0.1.20haproxy001
1) Prerequisite
  • Nagios server in working condition.
  • Following dependent package to compile and install.
   yum install gcc glibc glibc-common xinetd 
Create nagios user and group by which we will be installing NRPE and Nagios-Plugin
   useradd -m nagios
   password nagios
2) Installation
2.1) Create a directory where you would download nagios software:
   mkdir /usr/local/src
   cd /usr/local/src
2.2) First of all we need to Download/Untar/Compile and Install all necessary files for Nagios-Plugin:
   wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
   cd nagios-plugins-1.4.16
   ./configure --with-nagios-user=nagios --with-nagios-group=nagios
   make
   make install
2.3) Then we need to Download/Untar/Compile and Install all necessary files for NRPE:
   cd /usr/local/src/
   wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
   ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios
   make all
   make install-plugin
   make install-daemon
   make install-daemon-config

Note: NRPE by default is installed under /usr/local/nagios directory.
2.4) Install the NRPE daemon as a service under xinetd.
   make install-xinetd
2.5) We need to fix permission as well.
   chown nagios.nagios /usr/local/nagios
   chown -R nagios.nagios /usr/local/nagios/libexec 
3) Configuration
3.1) Nagios Client (NRPE) Configuration
3.1.1) Add the IP Address of the Nagios monitoring server to “only_from” directive in /etc/xinetd.d/nrpe file:
   vi /etc/xinetd.d/nrpe
   only_from = 10.0.1.10
3.1.2) Add the following entry for the NRPE daemon to the /etc/services file:
   vi /etc/services
   nrpe              5666/tcp           # NRPE
3.1.3) Restart the xinetd service:
   service xinetd restart
3.2) Validation and Testing
3.2.1) We need to check if nrpe daemon is running under xinetd:
   netstat -at | grep nrpe
   tcp        0      0 *:nrpe                      *:*                         LISTEN 
3.2.2) Now we need to do the functional testing of NRPE daemon:
   /usr/local/nagios/libexec/check_nrpe -H localhost
   NRPE v2.14
3.2.3) Some inbuild checks that we can check:
   /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
   USERS OK - 3 users currently logged in |users=3;5;10;0

   /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
   OK - load average: 0.00, 0.02, 0.00|load1=0.000;15.000;30.000;0; load5=0.020;10.000;25.000;0; load15=0.000;5.000;20.000;0;
3.3) Firewall Rule for NRPE:
3.3.1) Firewall port that needs to be open for NRPE daemon on client machine:
   iptables -A INPUT -p tcp -m tcp –dport 5666 -j ACCEPT
3.3.2) Save the Iptables rules and restart it.
   service iptables save
   service iptables restart
Once we are fully convinced that NRPE is running successfully, now is time to do full-fledged setup:
4) Nagios Server Setup
4.1) We need to Download/Untar/Compile and Install NRPE Plugin
   cd /usr/local/src/
   wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
   ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios
   make all
   make install-plugin 
4.2) Validation/Testing
Now we need to make sure that NRPE plugin (from Nagios Server) can talk to nrpe daemon (Client machine). 
   /usr/local/nagios/libexec/check_nrpe -H 10.0.1.20
   NRPE v2.14
4.3) Creating Configuration file
4.3.1) Add the following *check_nrpe* definition in “commands.cfg” file:
   vi /usr/local/nagios/etc/commands.cfg

   define command{
      command_name   check_nrpe
      command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
4.3.2) We also need to create host and service definitions
   vi /usr/local/nagios/etc/objects/hosts.cfg

   define host{
      use          linux-box
      host_name    haproxy001
      alias        HA Proxy 001
      address      10.0.1.20
      }


   vi /usr/local/nagios/etc/objects/services.cfg

   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    CPU Load
      check_command          check_nrpe!check_load
      }

   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Current Users
      check_command          check_nrpe!check_users
      }

   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Zombie Processes
      check_command          check_nrpe!check_zombie_procs
      }

   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Total Processes
      check_command          check_nrpe!check_total_procs
      }
4.3.3) Verify your Nagios configuration files:
   /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
4.3.4) If there are errors, fix them. If everything is fine, restart Nagios:
   service nagios restart
That’s it! You should see the host and service definitions you created in the Nagios web interface. In a few minutes Nagios should have the current status information for the remote Linux/Unix machine.
5) Adding Custom Checks
5.1) Nagios Client (NRPE) Setup 

5.1.1) Adding Custom and other in build Checks provided by Nagios plugins you can find it in “/usr/local/nagios/libexec/”
Let say we need to add check_swap plugin that will send warning alert if free space is less than 20% and critical alert if swap free space is less than 10%.
On the NRPE Client machine (haproxy001) verify plugin is working fine:
   /usr/local/nagios/libexec/check_swap -w 20% -c 10%
5.1.1) Once we confirm that the plugin is working fine, we need to add the command entry in config file:
   vi /usr/local/nagios/etc/nrpe.cfg
   command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
5.1.3) Restart the NRPE Daemon:
   service xinetd restart
5.2) Nagios Server Setup
5.2.1) We need to define a new service for monitoring the swap usage on the remote host, by adding line in “service.cfg” file.
   vi /usr/local/nagios/etc/objects/services.cfg
   define service{
      use                    generic-service
      host_name              haproxy001
      service_description    Swap Usage
      check_command          check_nrpe!check_swap
      }
5.2.2) Verify your Nagios configuration files and in case there is no error restart the nagios server daemon:
   /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
   service nagios reload
You should see the new service definitions that we created in the Nagios web interface.