Ubuntu (Specific) Server
From QwikITedia
Contents |
APACHE Virtual Hosts - Ubuntu Configuration
Purpose
- To use one Apache install to render two or more websites
- These instructions are for Ubuntu Hardy Heron 64-Bit (v 8.04.x LTS) Server, and as such will work on all Debian based distros
Named Based Virtual Hosting
- In essence http requests for two different domain names go to the same server
- The Apache Virtual Hosting directive intercepts the request and directs it to the relevant document root based on configurations it is setup to exercise
Configuration
- First, we'll enable this functionality within Apache
- Second, we'll setup each virtual host
- Third, we'll make it active
Enable Vhosting within Apache
- Tell Apache that we’re using name based virtual hosting instead of IP based.
- Edit the apache2.conf file:
vi /etc/apache2/apache2.conf:
- Add the following line to the very end of this conf file: NameVirtualHost ip.address:port, for example
NameVirtualHost 12.0.0.124:80
- Debian and Ubuntu use /etc/apache2/sites-available/ and /etc/apache2/sites-enabled/ directories for defining virtual hosting. One nice thing about this is that you can have more sites “available” than you have “enabled”, meaning not everything configured is actually live and listening. This is nice to quickly disable a site for whatever reason.
Setup each Virtual Apache Server
- Create unique files for each of the domains within the /etc/apache2/sites-available/ folder. For example :
<VirtualHost 12.0.0.124:80>
ServerName myserver-A.com
ServerAlias www.myserver-A.com
ServerAdmin webmaster@myserver-A.com
DocumentRoot /var/www/www.myserver-A.com
ErrorLog /var/log/apache2/myserver-A-error.log
CustomLog /var/log/apache2/myserver-A-access.log combined
</VirtualHost>
- and :
<VirtualHost 12.0.0.124:80>
ServerName myserver-B.com
ServerAlias www.myserver-B.com
ServerAdmin webmaster@myserver-B.com
DocumentRoot /var/www/www.myserver-B.com
ErrorLog /var/log/apache2/myserver-B-error.log
CustomLog /var/log/apache2/myserver-B-access.log combined
</VirtualHost>
- As you can see, both websites use the same server and port but serve requests from different doc roots based on the servername which was sought in the request.
Activate the Virtual Hosts
- To activate the above configurations we have to create a symbolic link from each to the enabled folder(Ubuntu and Debian!):
cd /etc/apache2/sites-enabled/ ln -s ../sites-available/www.myserver-A.com . ln -s ../sites-available/www.myserver-B.com .
- Alternately upon Ubuntu you could use the inbuilt activation scripts:
cd /etc/apache2/sites-enabled/ sudo a2ensite www.myserver-A.com sudo a2ensite www.myserver-B.com
- Now we just have to get Apache to recognize these new virtual hosts otherwise it will merely serve whatever is in the default localhost docroot. You do this by :
- Stop and Start the server - drastic( sudo shutdown -r now )
- Stop and Start Apache - overkill( sudo /etc/init.d/apache2 stop and then start )
- Restart Apache - perfectly reasonable( sudo /etc/init.d/apache2 restart )
- Leave Apache Running and reload its config on the fly - perfect( sudo /etc/init.d/apache2 reload )
- I'm all about easy so you guessed it:
sudo /etc/init.d/apache2 restart
- If easy didn't do it check the logs or simply use step 3(perfectly reasonable)
Problems
- If a vhost you have configured is not working you basically go over these steps again. Chances are you have omitted to edit apache2.conf - notifying Apache that you are going to use name-based vhosts or else you have not enabled the vhost and restarted Apache or finally - you have a misconfigured Virtualhost directive. Check the examples above and ensure yours look something similar.
Deactivate a Virtual Host
- Couldn't be simpler. Just undo the Activation process in one of two ways:
cd /etc/apache2/sites-enabled/ sudo a2dissite www.myserver-A.com sudo a2dissite www.myserver-B.com
- or
cd /etc/apache2/sites-enabled/ unlink ../sites-available/www.myserver-A.com . unlink ../sites-available/www.myserver-B.com .
- Restart Apache:
sudo /etc/init.d/apache2 restart
Generic (Headless) Ubuntu Server Build
- This wiki doc is based upon the setup of a 64-Bit Ubuntu Hardy Heron Server
- Obtain the distro and burn to a CD/DVD
- Install via installation wizard and then add the following from comman line
sudo apt-get install <pacakge below in brackets>
- sshd (ssh)
- ssmtp (ssmtp)
- ntpd (ntp)
- sysstat(sysstat)
- syslog-ng(syslog-ng)
- curl( sudo aptitude install curl )
- Create user accts
sudo useradd –d /home/<user> -m <user>
- Give relevant(capable sys admins) users sudo
sudo adduser <user> admin
- Install make
sudo apt-get install make
- Install Java 6 (sun-java6-jdk)
sudo apt-get install sun-java6-jdk
- Set Default Editor to vi(OPTIONAL)
sudo update-alternatives --config editor Select 1 for vi
- Install subversion client
sudo apt-get install subversion
Setup iSCSI SAN Volume
- SAN Device = Dell EqualLogic Storage Array
Install Open-iSCSI Initiator
- as root install the opensource iscsi initiator on Myserver1:
root@myserver1:~# apt-get install open-iscsi
Configure Open-iSCSI
- You need to soft-link (path fix) few two files to autologin work i.e. fix file paths for iscsiadm, enter:
root@myserver1:~# ln -s /etc/{iscsid.conf,initiatorname.iscsi} /etc/iscsi/
ln: creating symbolic link `/etc/iscsi/iscsid.conf': File exists
ln: creating symbolic link `/etc/iscsi/initiatorname.iscsi': File exists
- Edit the configuration file at /etc/iscsi/iscsid.conf
root@myserver1:~# vi /etc/iscsi/iscsid.conf
- Under Startup Settings, Set node.session.auth.username, node.session.auth.password and other parameter as follows:
#***************** # Startup settings #***************** # To request that the iscsi initd scripts startup a session set to "automatic". # node.startup = automatic # # To manually startup the session set to "manual". The default is manual. # node.startup = manual # iscsi setup for Myserver + SAN node.startup = automatic node.session.auth.username = '' node.session.auth.password = '' discovery.sendtargets.auth.username = '' discovery.sendtargets.auth.password = '' node.session.timeo.replacement_timeout = 120 node.conn[0].timeo.login_timeout = 15 node.conn[0].timeo.logout_timeout = 15 node.conn[0].timeo.noop_out_interval = 10 node.conn[0].timeo.noop_out_timeout = 15 node.session.iscsi.InitialR2T = No node.session.iscsi.ImmediateData = Yes node.session.iscsi.FirstBurstLength = 262144 node.session.iscsi.MaxBurstLength = 16776192 node.conn[0].iscsi.MaxRecvDataSegmentLength = 65536
- Save and close the file. Restart open-iscsi service:
root@myserver1:~# /etc/init.d/open-iscsi restart
Create a volume on SAN
- Login to a server which the SANs iscsi serial cable is connected into
- Start a browser and go to http://12.x.y.z for example
- Enter Username and Password
- Create the volume and experience the myriad of options and outrageous confusion
Discover SAN from Server
- Now back in your ssh terminal upon Myserver1 server, As root, run a discovery against the iscsi host:
root@myserver1:~# iscsiadm -m discovery -t sendtargets -p 10.7.10.10 12.x.y.z:3260,1 iqn.2001-05.com.equallogic:0-8a0906-bd12dbf02-caa000001b84ac28-myserver-a root@myserver1:~#
- Record ID = iqn.2001-05.com.equallogic:0-8a0906-bd12dbf02-caa000001b84ac28-myserver-a
- Login to SAN from Myserver using the Record ID:
root@myserver1:~# iscsiadm --mode node --targetname iqn.2001-05.com.equallogic:0-8a0906-bd12dbf02-caa000001b84ac28-myserver-a --portal 12.a.b.c:3260 --login iscsiadm: no records found!
- Finally, restart the service again:
root@myserver1:/etc/network# /etc/init.d/open-iscsi restart
Format iSCSI Volume
- Now you should see an additional drive on the system such as /dev/sdb.
- Use /var/log/messages file to find out device name:
root@myserver1:/etc/network# tail -f /var/log/messages
You'll see something akin to:
Sep 29 14:27:47 myserver1 kernel: [ 9322.654601] sdb: sdb1 Sep 29 14:27:47 myserver1 kernel: [ 9322.668096] sd 4:0:0:0: [sdb] Attached SCSI disk Sep 29 14:27:47 myserver1 kernel: [ 9322.668139] sd 4:0:0:0: Attached scsi generic sg3 type 0
- Check Myservers paritions and ensure you can see the sdb volume(SAN):
root@myserver1:~# fdisk -l Disk /dev/sda: 146.1 GB, 146163105792 bytes 255 heads, 63 sectors/track, 17769 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000080 Device Boot Start End Blocks Id System /dev/sda1 * 1 17043 136897866 83 Linux /dev/sda2 17044 17769 5831595 5 Extended /dev/sda5 17044 17769 5831563+ 82 Linux swap / Solaris Disk /dev/sdb: 1073.7 GB, 1073747066880 bytes 255 heads, 63 sectors/track, 130542 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000000 Disk /dev/sdb doesn't contain a valid partition table root@myserver1:~#
So we need to partition /dev/sdb/ .. Let's make it Linux format...ext3:
root@myserver1:/# fdisk /dev/sdb
The number of cylinders for this disk is set to 130542.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130542, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130542, default 130542):
Using default value 130542
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
root@myserver1:/# mkfs.ext3 /dev/sdb1
mke2fs 1.40.8 (13-Mar-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
65544192 inodes, 262144645 blocks
13107232 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
8001 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Mount file system
root@myserver1:~# mkdir /iscsi root@myserver1:~# mount /dev/sdb1 /iscsi
- Take a peek:
root@myserver1:/# fdisk -l Disk /dev/sda: 146.1 GB, 146163105792 bytes 255 heads, 63 sectors/track, 17769 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000080 Device Boot Start End Blocks Id System /dev/sda1 * 1 17043 136897866 83 Linux /dev/sda2 17044 17769 5831595 5 Extended /dev/sda5 17044 17769 5831563+ 82 Linux swap / Solaris Disk /dev/sdb: 1073.7 GB, 1073747066880 bytes 255 heads, 63 sectors/track, 130542 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x020a585e Device Boot Start End Blocks Id System /dev/sdb1 1 130542 1048578583+ 83 Linux root@myserver1:/#
Update /etc/fstab file
- To ensure the Volume gets mounted after a system restart we add it to the fstab file:
root@myserver1:/# vi /etc/fstab
- Append the following:
# /dev/sdb - SAN unit /dev/sdb1 /iscsi ext3 defaults 1 2
- Save and close /etc/fstab
(optional)Label the Partition
- Use the e2label to give the new partition a label:
root@myserver1:/# e2label /dev/sdb1 /MyServer-A
- We've labelled it MyServer-A, above.
- Now you could change the /etc/fstab file to read as follows:
LABEL=/Myserver-A /iscsi ext3 defaults 1 2
Upgrade an Ubuntu Server from cli
- Let's assume we had a 64-Bit Gutsy Gibbon install which we wished to upgrade to a Hardy Heron install.
- Update /etc/apt/sources.list
sudo vi /etc/apt/sources.list
- Change all references from 'Gutsy' to 'Hardy' - save file
:1,$s/gutsy/hardy/g or :%s/gutsy/hardy/g :wq!
- Update the source list
sudo apt-get update
- Upgrade to the new distro
sudo apt-get dist-upgrade
Virtualization - Ubuntu JeOS
- Enable system BIOS for Virtualization Technology
- Install Ubuntu Hardy Heron v8.04.1 LTS Server
- Install KVM ontop of Hardy
- Configure the BRIDGE...or FAIL!!
- Turn off dhcbbd
- Use ubuntu-vm-builder to install JeOS
- Create a Virtual Machine Directory
mkdir /virtual-machines cd /virtual-machines
- Decide How many vms the server will have and make a directory for each
mkdir server-A mkdir server-B
- Move into each directory and build the VM in there using ubuntu-vm-builder
- You need sudo with ubuntu-vm-builder even if logged on as root
sudo ubuntu-vm-builder kvm hardy --arch amd64 --mem 3000 --rootsize 60000 --swapsize 6000 --kernel-flavour server --hostname server-B --domain usa --mirror http://archive.ubuntu.com/ubuntu --components main,universe,restricted --name 'James Smith' --user jsmith --pass changeme --ip 12.x.x.w --mask 255.255.255.0 --net 12.x.x.0 --bcast 12.x.x.255 --gw 12.x.x.254 --dns 12.x.x.2 --addpkg vim --addpkg openssh-server --libvirt qemu:///system
- Logon to Virsh to manage VM's:
virsh --connect qemu:///system
- List all the VM's( it'll retain names of old ones you tested with - need to figure out how to remove them )
virsh # list --all Id Name State ---------------------------------- - server-A shut off - server-A_ shut off - server-A__ shut off - server-B shut off - server-B_ shut off - server-B__ shut off
- The valid ones above are server-A and server-B
- Similar variations with appended underscores show up if you use the same server name .. Ubuntu vm mgr adds the underscores. This helps you understand how many times you've screwed up! : )
- To remove an inactive VM you must undefine it
virsh # list --all Id Name State ---------------------------------- 3 server-A running 4 server-B running - server-A_ shut off - server-A__ shut off - server-B_ shut off - server-B__ shut off virsh # undefine server-A_ Domain server-A_ has been undefined virsh # list --all Id Name State ---------------------------------- 3 server-A running 4 server-B running - server-A__ shut off - server-B_ shut off - server-B__ shut off
- To start the VM from VIRSH prompt:
virsh#start server-A Domain server-A started virsh#start server-B Domain server-B started
- Or from Linux root CL, Start the VM
virsh -c qemu:///system start server-B
- Stop the VM
virsh -c qemu:///system shutdown server-B
- See virsch commands for possibilities( scroll down )
- or
- See virsch commands for possibilities( 2/3 way down page )
SERVER-A Config :: USA domain sudo ubuntu-vm-builder kvm hardy --arch amd64 --mem 3000 --rootsize 60000 --swapsize 6000 --kernel-flavour server --hostname server-A --domain usa --mirror http://archive.ubuntu.com/ubuntu --components main,universe,restricted --name 'James Smith' --user jsmith --pass changeme --ip 12.x.x.y --mask 255.255.255.0 --net 12.x.x.0 --bcast 12.x.x.255 --gw 12.x.x.254 --dns 12.x.x.2 --addpkg vim --addpkg openssh-server --libvirt qemu:///system SERVER-B - Config :: USA domain sudo ubuntu-vm-builder kvm hardy --arch amd64 --mem 3000 --rootsize 60000 --swapsize 6000 --kernel-flavour server --hostname server-B --domain usa --mirror http://archive.ubuntu.com/ubuntu --components main,universe,restricted --name 'James Smith' --user jsmith --pass changeme --ip 12.x.x.w --mask 255.255.255.0 --net 12.x.x.0 --bcast 12.x.x.255 --gw 12.x.x.254 --dns 12.x.x.2 --addpkg vim --addpkg openssh-server --libvirt qemu:///system