Saturday, February 13, 2016

Linux | Don't reboot after adding a new disk on a VM

It is quite common practice when adding a new drive to a Linux system to reboot the system afterwards so that the server can re-scan its hardware and detect the change. However, every now and then we get to make changes to a server that we don't want to reboot it for some reason. Or maybe you are lazy, like me and don't want to wait 1 min to reboot. In any case, bellow is a way to make your system re-scan the hardware and detect the changes.


Thursday, February 4, 2016

Linux | How to search for a particular string in multiple files

Every now and then I find myself into a situation where I have to search for a particular string from a set of files, and every time I have to remind myself again.

As the old proverb says: "The fool remembers, the smart writes down."

That is why I decided to write this down, so that I can come back and find it again.

# grep -rnw '/path/to/somewhere/' -e "pattern"

Here -r or -R is recursive, -n is line number and -w stands match the whole word. We can also add -l (lower-case L) to just give the file name of matching files.

So in my current example, I work on Nagios and I want to find the file containing that check_snmp command i would type:

# grep -rnw '/etc/nagios/objects/' -e 'check_snmp'

Which will produce the output:

/etc/nagios/objects/commands.cfg:147:# 'check_snmp' command definition
/etc/nagios/objects/commands.cfg:149:        command_name    check_snmp

From here we can basically see the file where check_snmp is defined along with the line number of that file.


Extending the command with --include or --exclude parameter we can create neatly commands to also search for files with particular extension. The bellow command will check only .cfg or .conf files.

# grep --include=\*.{cfg,conf} -rnw '/etc/nagios/objects/' -e 'check_snmp'

# grep --exclue=\*.0 -rnw '/etc/nagios/objects/' -e 'check_snmp'

And as always:

RTDM!

# man grep


Tuesday, January 19, 2016

CentOS V2V | Hyper-V to VMware - The easy way

I had a task to export a Hyper-V, CentOS 6 VM and deploy it to a vSphere cluster. Due to the nature of the VM we had to preserve it because the VM was already set up and it was too long for us to build a new one with the same settings.

Before start I would like to point out that if this is a Linux VM you are doing, then because there will be a complete hardware change you may end up with unbootable clone, which can be fixed. This did not happen to me though, but in the end of this article I will also point those things out as potential issues.


Sunday, December 27, 2015

Linux | Guidelines for setting up a Linux Server as a VM

These are just plain guidelines for setting up a Linux server as a virtual machine. As time passes I keep seeing the same mistakes from fellow admins, over and over again so I decided to mention some of it.

Feel free to add anything else in the comments or point me out should I am making a mistake somewhere along the way ;)

First things first, you have to decide what will be the use of the VM that you are creating? Will it be a file server, or a web server, or a database server? Perhaps it will be a dedicated VM for a couple of users. No matter your choice, if you are setting up the server as a virtual machine in you infrastructure you have to keep in mind a few things so these are just a few golden rules for setting up a Linux VM so that you don't end up crying later when things go bad.

Monday, December 21, 2015

CentOS 7 | Installation and setup of Icinga2 monitoring service - Part 2 - Setting up the Icinga Web 2 interface

This is part 2 of the tutorial where I'll be setting up the Icinga Web 2 web fronted from where we can log into our Icinga2 server and actually monitor our infrastructure.

If you came here from Google than you can find Part 1 here.

CentOS 7 | Installation and setup of Icinga2 monitoring service - Part 1

Knowing that there is a newer fancier Nagios fork called Icinga I always wanted to try it out, but
I really haven't got the time to do that. Finally when I got the time I realized that online guides for that are missing too. Being a CentOS supporter, I decided that during that process i could write a tutorial for CentOS 7.

This is the part 1 of the tutorial where I'll be going through the steps for preparing the server and setting up the Icinga2 service. In part two I'll be going through the steps for installing and setting up the Icingaweb2 web service which basically is one of the several available Incinga2 front-end applications.

Sunday, December 13, 2015

vSphere | Virtual Machine that is neither powered on nor powered off

I had a very interesting problem with a VM for which I concluded being in a phantom state, that is a VM that is neither powered on, nor powered off. No matter what you try to do to the VM you always end up with error message that says:

The attempted operation cannot be performed in the current state: Powered ON.

The thing is, that if you try to access the console, the machine is not powered on. Even more, if you open the VMRC you could end up seeing an error message:

Unable to connect to the MKS: The operation is not allowed in the current state.

So what should I do? I decided to hit the ESXi Shell. VMware has a pretty nice KB article and even a video on what to do when you encounter this problem:


Connect to the host using an SSH client and try the steps described into that article. However if the VM still cannot be powered off than you must reboot the ESXi host in order to refresh the VM state.

If this happens too often then you must consider moving everything off that host, as this probably indicates problems with the host itself.