In part 1 of the CentOS setup, we completed the ssh configuration along with a basic iptables install.
Let’s move on and install some personal configuration files to make our life easier. Once done, we can update the install and create a solid base for the ‘meat’ of the server.
OS check and Free
First thing is to confirm what OS we’re using. We know we should be using CentOS but let’s see:
You should get an output similar to this:
CentOS release 5 (Final)
Good. Memory usage should be very low at this point but let’s check using ‘free -m’ (the -m suffix displays the result in MB’s which I find easier to read):
It’s nice to know what is going on so let’s look at that output:
. total used free shared buffers cached
Mem: 254 55 199 0 2 21
-/+ buffers/cache: 30 223
Swap: 511 0 511
The line to take notice of is the second one as the first line includes cached memory – in this demo Cloud I have 254MB memory in total with 30MB actually used, 223MB free and no swap used. Nice.
Let’s make the terminal a bit more attractive and a bit more informative by adding a few lines to our .bash_profile file.
Add the next few lines at the end of the existing text. The following line will make the terminal display the server name in colour and display the working directory (the directory we are in) in a different colour:
export PS1=’\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: ‘
Now we can add aliases to the file. Aliases are short cuts to commands or sequences of commands. I’ve included a few below but you can have as many or as few as you want.
alias free=”free -m”
alias update=”sudo yum update”
alias install=”sudo yum install”
alias upgrade=”sudo yum upgrade”
alias remove=”sudo yum remove”
The examples above are pretty simple. Instead of typing ‘free -m’ every time I want to look at the memory usage, I just type ‘free. Typing ‘sudo yum install’ can get tedious, so I just type ‘install’.
I still need to provide my password for the sudo command to work, but it is more productive/quicker/easier to have short cuts.
To activate the changes enter this command:
You should now see the Cloud name in purple and the working directory in brown.
To change the colours to your choosing, adjust the 0;35m and the 0;33m values in the ‘export PS1’ line of your .bash_profile.
export PS1=’\[\033[0;32m\]\h\[\033[0;36m\] \w\[\033[00m\]: ‘
would give you a green and blue output.
The CentOS Cloud comes with a basic set of repositories that are defined in /etc/yum.repos.d.
Have a look at the enabled repositories:
sudo nano /etc/yum.repos.d/CentOS-Base.repo
As you scroll through the file, you will see each repository has a set of definitions including which mirror to use and what gpg key to use (and actually whether to check the package signature at all).
You can, of course, add more repositories whenever you want to but I would just give a word of caution: Some of the available repositories are not officially supported and may not receive any security updates should a flaw be discovered.
Keep in mind it is a server we are building and not a desktop.
Now we can update the package list that yum uses.
The command will also offer to install any updated packages. As with all installs have a careful look at the list and, once happy, press ‘y’ to continue:
sudo yum update
NOTE: If you have used the .bash_profile aliases shown above you just need to enter ‘update’ as the alias will use the entire command. I’ve put the whole thing here so you know what is happening.
That’s really the basics done for the Cloud.
Once any updates have been installed, we can move on to installing some essential packages.
CentOS has some handy meta-packages that include a set of pre-defined programs needed for a single purpose.
So instead of installing a dozen different package names, you can install just one meta-package. One such package is called ‘Development Tools’. Issue the command:
sudo yum groupinstall ‘Development Tools’
Notice the programs that are to be installed include gcc, make, patch and so on. All these are needed for many other programs to install properly. A neat system indeed.
Enter ‘Y’ and install them.
Now we have the necessary packages should we want to build an application from source.
We’ll go on and install a very useful package that we recommend called ‘screen’.
This is a great application that allows ‘virtual’ terminals to be opened in one console. Switching between them is done with the press of a key.
The advantages are that you can be working on more than one shell at a time, say one installing software and another monitoring network activity – all without having more than one physical shell open. If the SSH connection is cut for some reason or you have to leave the room then close the terminal and the work will still carry on in the background.
I recommend getting used to using screen. This screen tutorial gives an excellent introduction.
sudo yum install screen
To start a screen session simply enter the command:
Not much appears to have changed, but you can open another virtual terminal with a:
Ctl-A and then press ‘c’
Enter a simple command such as:
then nip back to the other virtual terminal with:
Ctl-A and then press ‘p’
You can have several processes running at the same time using this technique.