Installation (Ubuntu)
Whilst this page was written with the installation of a Ubuntu Server 10.04 LTS in mind, it can also be used for Ubuntu 12.
Prepare Virtual Machine
- Create a virtual machine with the following options (use Custom)
- Guest OS: Linux > Ubuntu 64bit
- CPU: 1
- Memory: 512 MB
- Disk: 36GB
- Then add a second 36GB disk on a separate physical datastore (if you intend to use software RAID)
- Attach Ubuntu install ISO to the CD-ROM
Note that the specs above should be altered to suit your purposes. Whilst there is no need to use a 64 bit OS as opposed to 32 bit if you don't need to address lots of memory, it is standard these days.
OS Installation
Installing Ubuntu Server (LTS) is relatively painless, its generally a case of following the default or sensible choices for your locale. However, below are step-by-step instructions, which you probably won't require, but may help if you're not familiar with the terminology.
If you're completely new make sure you read through the instructions 1st, so that you're prepared for the information you'll need to provide.
- Select language for installer
- Select Install Ubuntu Server
- Choose Language screens
- Select language for server (and remainder of the installer)
- Select location
- Ubuntu Installer Main Menu screens
- Select Yes for questions to determine appropriate keyboard, or No to just select a keyboard layout
- Configure the network screen
- Enter the hostname for the server (not a FQDN, so
hostname
rather thanhostname.domain.com
)
- Enter the hostname for the server (not a FQDN, so
- Configure the clock screen
- Select Yes to accept the suggested timezone, or No to alter
- Partition disks screens
- If you want to install the server onto software RAID'ed disks see Install on Software RAID
- Select Guided - use entire disk and set up LVM
- Select the disk to partition and install the OS onto
- Select Yes to Write the changes to disks and configure LVM
- Accept the full amount to partition
- Select Yes to Write the changes to disks
- Set up users and passwords screens
- Enter your name
- Enter your username (that you will use to login with)
- Enter your password
- If you use a weak password (eg less that 8 characters) you'll be asked to confirm this is OK once you've verified it
- Re-enter (verify) your password
- Select No to not Encrypt your home drive
- If you are really worried about your dat being compromised you should consider encrypting the whole drive during its partitioning
- Configure the package manager screen
- Enter proxy server details if required for server to access the internet for updates
- Select and install software screen
- Select No automatic updates if you want to control how updates are applied yourself, otherwise select Install security updates automatically
- Software selection screens
- Select OpenSSH Server (press [Space] when item is highlighted), this allows you to Putty/SSH to the server
- Select any other required software, eg
- DNS Server - Only required if you want your server to be a DNS server; or in order to configure split DNS, which is required for an exchange server install
- LAMP Server - Only required for Apache webserver (with MySQL and PHP)
- Configuring grub-pc screen
- Select Yes to Install the GRUB boot loader to the master boot record
- Finish the installation screen
- Select Continue
Install on Software RAID
On the Partition Disks screens use the following to setup software RAID during OS installation.
- If setting up software RAID follow the steps below, otherwise just select Guided - use entire disk and set up LVM
- Select "Manual
- Then create a partition...
- Select the first disk (
sda
) and on the next screen, Yes, to Create new empty partition table on this device? - Select the FREE SPACE, then Create a new Partition, and use all but the last 2GB of space,
- And then select type of Primary, and create at Beginning
- Change Use as to physical volume for RAID, and change the Bootable flag to Yes, the select Done setting up this partition
- Select the first disk (
- Repeat the above on the remaining FREE SPACE on
sda
, to create another primary physical volume for RAID, but 'not bootable - Select the second disk,
sdb
, and repeat the steps taken forsda
to create two identical partitions - On the same screen, select the Configure Software RAID option (at the top), and then confirm through the next screen
- Create a RAID pack/multidisk...
- Select Create MD device, then select RAID1 (ie a mirror), then confirm 2 Active devices, and 0 Spare devices
- Select both
/dev/sda1
and/dev/sdb1
partitions, and then select Finish
- Repeat the above to create a RAID volume using
/dev/sda2
and/dev/sdb2
partitions - Now select the RAID device #0 partition (select the #1 just under RAID1 device line), and change the Use as and select Ext3...
- Change the Mount point to /, then select Done configuring this partition
- Now select the RAID device #1 partition (select the #1 just under RAID1 device line), and change the Use as and select Swap area
- Then select Done configuring this partition then finally Finish partitioning and write changes to disk, and confirm to Write the changes to disks
- Accept the "The kernel was unable to re-read...system will need to restart" complaints for each RAID multidisk, after which the install will continue (note there's a little more to do post install to ensure you can boot using the second disk should the first fail).
Much of this page was originally borrowed heavily from the following pages - they are well worth a read!
- http://www.howtoforge.com/perfect-server-ubuntu8.04-lts
- http://www.howtoforge.com/how-to-install-ubuntu8.04-with-software-raid1
Post OS Install Config
Enable Root
- Use the command
sudo passwd root
- Enter your user password
- Enter a strong password for the root account
For Ubuntu 18...
- Use the command
sudo passwd
- Enter your user password
- Enter a strong password for the root account
Finish Software RAID config
Only if configured during install
- Start-up grub (by entering
grub
and enter the following commands (seems to work better via SSH than direct console)...device (hd1) /dev/sdb
root (hd1,0)
setup (hd1)
quit
- Then edit the
/boot/grub/menu.lst
config file. Go to the end of the file where the boot options are, and create a copy of the first option and edit the following linestitle
Add "Primary disk fail" or something similar to endroot
Changehd0
tohd1
- To check the RAID setup of your drives use
mdadm --misc -D /dev/md0
mdadm --misc -D /dev/md1
Change IP Address (Pre v18)
v8 Hardy Heron / v10 Lucid Lynx
- Edit the
/etc/network/interfaces
file in the following fashion to set static address details
# The primary network interface auto eth0 iface eth0 inet static address 192.168.1.150 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1
- Then check the local hosts file
/etc/hosts
, so that the IP v4 part looks like this (so the host can resolve itself)...
127.0.0.1 localhost 192.168.1.150 hostname.domain.com hostname
- Check that DNS resolution is setup correctly in
/etc/resolv.conf
. Add additional DNS nameservers as required, as found in in order of preference. You can also add the domain of the server (domain
), and add domain suffix searches (search
), both are optional. For example...
nameserver 192.168.1.20 nameserver 127.0.0.1 domain domain.com search domain.com search domain.com
- Then restart networking
/etc/init.d/networking restart
- Confirm network config is as expected with
ifconfig
v12 Precise Pangolin
- Edit the
/etc/network/interfaces
file in the following fashion to set static address details
# The primary network interface auto eth0 iface eth0 inet static address 192.168.1.150 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 192.168.1.20 8.8.8.8 dns-domain localdomain.com dns-search localdomain.com anotherdomain.com
- Then check the local hosts file
/etc/hosts
, so that the IP v4 part looks like this (so the host can resolve itself)...
127.0.0.1 localhost 192.168.1.150 hostname.domain.com hostname
- Then restart networking
service networking restart
- Confirm network interface config is as expected with
ifconfig
- Confirm DNS config is as expected with
less /etc/resolv.conf
Persistent Route
To add a persistent route to an interface, add using the following syntax (example sends traffic to 172.32.1.0/24 via eth1 to 192.168.1.100
up route add -net 172.32.1.0/24 gw 192.168.1.100 dev eth1
Additional IPs / Multihome
To add additional IP addresses to an interface, create sub-interfaces as below.
auto eth0:1 auto eth0:2 # Sub 1 iface eth0:1 inet static address 192.168.1.160 netmask 255.255.255.0 # Sub 2 iface eth0:2 inet static address 192.168.1.161 netmask 255.255.255.0
RTNETLINK answers: File exists - Note that you can't use the same default gateway twice, doing so will cause this error
Change IP Address (v18 onwards)
Ubuntu now uses Netplan, do not use the /etc/network/interfaces
config file, use either /etc/netplan/01-netcfg.yaml
or /etc/netplan/50-cloud-init.yaml
. Formatting is very important with YAML files, indents especially.
- Find the interface name (eg
ens2
)ip link
- Edit the
/etc/netplan/01-netcfg.yaml
config file as show below - Apply the changes
netplan apply
network: version: 2 renderer: networkd ethernets: ens2: dhcp4: no addresses: - 192.168.1.50/24 gateway4: 192.168.1.1 nameservers: addresses: [192.168.1.1,8.8.8.8]
Persistent Route
To add a persistent route to an interface, add using the following syntax (example sends traffic to 172.32.1.0/24 via eth1 to 192.168.2.100) to add the routes
config to the interface the traffic should go through.
ens2: addresses: - 192.168.2.50/24 dhcp4: no routes: - to: 172.32.1.0/24 via: 192.168.2.100
Update the OS
- Run the following command to update the apt package database
apt-get update
- To install any updates
apt-get upgrade
- If updates are being held back (eg linux image), then use
aptitude safe-upgrade
- If running in VMware VM, install VM Tools
Remove Old Version
Old kernel images will tend to linger in /boot
and source code will remain in /user/src
. These can be safely removed so long as you're completely certain which you are using (normally the latest)
- Get the versions currently installed
dpkg --get-selections | grep linux-image
- Remove unwanted versions (don't remove the current or base/unversioned image)
- EG
apt-get purge linux-image-3.2.0-32-virtual
- If you've got lots to remove its easier to do lots in one go
- EG
apt-get purge linux-image-3.2.0-51-virtual linux-image-3.2.0-52-virtual
- EG
- EG
To remove old source, just delete manually,
- EG
rm -fr /usr/src/linux-headers-3.2.0-51
NTP
Not required if your server doesn't really need bang on accurate time
Out of the box your server will sync every time its restarted and drift a bit in-between. There is an additional resource demand in running the NTP daemon so unless you need to, there's no need to install the full blown NTP daemon.
I tend to have one or two servers updating from remote (public) servers, and then all others updating from those.
- Install the service
apt-get install ntp
- Update the NTP config file,
/etc/ntp.conf
(Example below is for a server updating from public European servers - see http://www.pool.ntp.org/)server 0.europe.pool.ntp.org
server 1.europe.pool.ntp.org
server 2.europe.pool.ntp.org
server 3.europe.pool.ntp.org
- Restart the NTP service
systemctl restart ntp
- Verify using the following commands
ntpq -np
date