Ubuntu LTS setup - page 2

In page 1 of the Ubuntu LTS 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 Ubuntu LTS but let's check:

cat /etc/issue

You should get an output similar to this:

#Ubuntu 6.06 LTS \n \l

Now let's see how our memory usage is doing (the -m suffix displays the result in MB's which I find easier to read).

free -m

It's nice to know what is going on so let's look at that output:

.                  total       used       free     shared    buffers     cached
Mem:             254        68         185          0          2            38
-/+ buffers/cache:        27         227
Swap:            511        0           511

The important line is the second one as the first line includes cached memory - in this demo slice I have 254MB memory in total with 27MB actually used, 227MB free and no swap used. A good start I think.

.bash_profile

Let's make the terminal a bit prettier and bit more useful by adding a few lines to our .bash_profile file.

nano ~/.bash_profile

We need to add a few lines at the end of the existing text. The following line will make the terminal show 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'll add some aliases to the file. Aliases are simply 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 apt-get update"
alias install="sudo apt-get install"
alias upgrade="sudo apt-get upgrade"
alias remove="sudo apt-get 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 apt-get 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 we can either log out and log in again (a bit much!) or issue the following command:

source ~/.bash_profile

You should now see the slice 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. For example:

export PS1='\[\033[0;32m\]\h\[\033[0;36m\] \w\[\033[00m\]: '

would give you a green and blue output.

sources.list

Fun time over! We need to update the software catalogue now, but let's check the sources list that Ubuntu uses. So open up the file:

sudo nano /etc/apt/sources.list

You will see the default list as follows:

deb http://archive.ubuntu.com/ubuntu/ dapper main restricted universe
deb-src http://archive.ubuntu.com/ubuntu/ dapper main restricted universe

deb http://archive.ubuntu.com/ubuntu/ dapper-updates main restricted universe
deb-src http://archive.ubuntu.com/ubuntu/ dapper-updates main restricted universe

deb http://security.ubuntu.com/ubuntu dapper-security main restricted universe
deb-src http://security.ubuntu.com/ubuntu dapper-security main restricted universe

The defaults should suffice for most needs. You are free to add and change the repositories as you see fit but I would give a word of warning: some repositories, whilst classed as 'official' may not receive any security updates should an exploit be found.

Remember we are building a server and not a desktop here so we should be aiming for stability and security at all times.

update

Once done, issue the command:

sudo apt-get update

NOTE: If you have used the .bash_profile shown above, you do not need to give the whole command. You just need to enter 'update' and the alias will give the entire command. I've put the whole thing here so you know what is happening.

From the terminal output you will see the download of the updated package list.

The first thing we need to do is install some language packs. In my case I install the english ones. You may want to change it to your chosen language. We do this before updating anything else so the install does not throw up warnings and errors about locations and so on.

sudo apt-get install localeconf language-pack-en

NOTE: Again, if you use the .bash_profile aliases, you only need to type in 'install package_name' and not the whole command shown above.

Review what it's going to install and press 'Y'.

The install will ask a couple of questions: Answer 'yes' to both.

upgrade

Now let's update the installed software to the latest Ubuntu LTS ones:

sudo apt-get upgrade

Have a look at what is going to happen and press 'Y'.

reboot

That might take a little while to finish and when it is done we're going to reboot the server. It's one of the few times we'll reboot. We need to do it now as there may have been some significant changes in the base/minimal install. It simply ensures that all the init files and configurations are running nice and smoothly.

sudo shutdown -r now

That command tells it to shutdown, reboot and to do that right now!

You will be 'thrown' off the terminal. Wait a minutes or two (it doesn't take long) and log back in . If you want, you can also see the output of the reboot via the Ajax console in the Slicehost control panel.

Just login and click 'console' above your slice name. It's not essential to view it, but if you are new to servers, it can give a good idea of what happens in the boot process and may give an idea if something goes wrong.

Naturally, you can view the logs as well, but this is a nice and easy way of seeing the 'live action'.

My reboot took about 15 seconds. So log in:

ssh -p 30000 demo@YOURIPADDRESS

screen

First thing to do is install 'screen'. This is a great utility that allows us many 'virtual' terminals in our single terminal window.

It also has the ability to start a process and be left to it. The connection could drop or you can log out from work and log in again later from home to see how the process is doing. A 'normal' ssh connection will not do that - if the connection drops, the process stops which is very annoying when you're an hour into compiling GCC, as you have to start again!

So, let's install screen:

sudo apt-get install screen -y

Did you notice the -y at the end of the command? This tells the install to go ahead and not ask if I want to carry on. Not always recommended but it's safe here.

If you've never used screen before, have a look at this screen tutorial which also includes how to create a .screenrc file so it starts exactly how you want it to (my screen session starts with 3 terminals, one running 'top, one main work terminal and a spare terminal for other use).

Let's start screen:

screen

Press the 'Space Bar' and it looks just like the normal terminal, except the .bash_profile has not been initiated... Issue the 'source' command:

source ~/.bash_profile

Now we are back to using our aliases and useful bash prompt.

build essentials

Ok, last thing to do is install some common programmes that will save time and, possibly, frustration later on.

Ubuntu has some handy meta-packages that include a number of programmes needed for one purpose. So instead of installing a dozen different package names, you can install just one meta-package. One such package is called 'build-essential'. Issue the command:

sudo apt-get install build-essential

Notice the programmes that are to be installed include gcc, make, patch, headers and so on. All these are needed for many other programmes to install properly. A neat system indeed. Click 'Y' and install them.

done

Quite a lot happening here but now we have a secured slice.

The console is now informative and less drab and we can use the handy 'screen' tool.

The slice sources have been updated, the slice upgraded and the meta-package build-essential has been installed.

If you do this more than once or twice it doesn't take long at all and we now have the ideal base to install the 'meat' of our server - whether the primary task is to serve web pages, act as a database server, be a file repository and so on.

PickledOnion.

Article Comments:

Roel De Meester commented Thu Nov 29 21:25:14 UTC 2007:

sudo apt-get install localeconf language-pack-en should become sudo apt-get install locales language-pack-en

PickledOnion commented Fri Nov 30 10:41:48 UTC 2007:

Hi Roel,

Why?

PickledOnion.

Matt commented Fri Jan 11 02:04:34 UTC 2008:

It might be worthwhile to mention that iptables can be kind of finicky about whitespace in the file it's importing. I spent a few minutes trying to figure out why my copy-pasted version of your file just got me "iptables-restore v1.3.3: no command specified". Wget-ting the provided iptables file works just fine.

marvin commented Sat Jan 19 06:18:02 UTC 2008:

I have done everything then I get to the installs and when I type anything it doesn't do anything just gives me back the unix prompt. I typed install screen for example and I got no errors just the unix prompt back.Then I typed screen to launch it and got command not found...Have no idea whats going on ?

PickledOnion commented Sun Jan 20 16:28:25 UTC 2008:

marvin,

I am not sure what is happening there.

Have you tried the full command (sudo apt-get install screen)?

It's possible the aliases are not working.

PickledOnion

trnsfrmr commented Thu Feb 28 01:57:33 UTC 2008:

Why would:

sudo nano /etc/apt/sources.list

fail to bring up the list in Nano, but:

nano /etc/apt/sources.list

works!

Trying to follow the instructions by the letter, but this has thrown me...

_whynot commented Thu Mar 13 19:02:14 UTC 2008:

@trnsfrmr: My guess is that the permissions of the file /etc/apt/sources.list don't allow read access to anyone but root.

If you type ls -lah /etc/apt you might see something like -rw------- 1 root root 468 Oct 29 16:17 sources.list which would indicate that you need elevated permissions to read or modify the file.

Daniel commented Wed Apr 02 20:07:24 UTC 2008:

PickledOnion: Because the "localeconf" package is not available in Ubuntu 7.10, I used "sudo apt-get install locales language-pack-en"

James commented Mon Aug 04 21:03:25 UTC 2008:

Thanks. Very clear document. Worked without problems.

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)