Page 1 of 4 123 ... LastLast
Results 1 to 10 of 35

Thread: How to Install and Configure an Ubuntu Server 12.04 LTS

  1. #1
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Post How to Install and Configure an Ubuntu Server 12.04 LTS

    The most current version of the guide can be found here: How to Install and Configure an Ubuntu Server 12.04 LTS @ HammondsLegacy.com

    Greetings and salutations,

    I hope this thread will be helpful to those who follow in my foot steps as well as getting any advice based on what I have done / documented.

    This is a Work-In-Progress topic so I will be updating this thread as I complete/update my notes.

    When finished, this will be converted to a wiki page.

    High-level overview

    This document will cover installation of a dedicated Ubuntu server. This will be the "base" installation of the server as a prerequisite for other documents that will build upon it (e.g. MediaWiki and MySQL). The server will be installed inside a virtual machine vSphere 4.1 running on ESXi 4.1 servers. Notes will also be supplied for doing the same thing for Oracle's VirtualBox on a Windows 7 PC. Although there are some VMware-specific and VirtualBox-specific steps, they are very few and the majority of this documentation will work for other Virtual Machines or even directly installed onto a physical machine (e.g. bare-metal install).

    This document will also cover some custom scripts to help automate tasks such as backing up, automatically growing the file system when free space is low, etc.

    Tools utilized in this process




    Helpful links

    The list below are sources of information that helped me configure this system as well as some places that might be helpful to me later on as this process continues.



    Assumptions

    This documentation will need to make use of some very-specific information that will most-likely be different for each person / location. This variable data will be noted in this section and highlighted in red throughout the document as a reminder that you should plug-in your own value rather than actually using these "place-holder" values.

    Under no circumstance should you use the actual values listed below. They are place-holders for the real thing. This is just a checklist template you need to have answered before you start the install process.

    Wherever you see RED in this document, you need to substitute it for what your company uses.


    • Ubuntu Server name: srv-ubuntu
    • Internet domain: mydomain.com
    • Ubuntu Server IP address: 192.168.107.2
    • Ubuntu Server IP subnet mask: 255.255.255.0
    • Ubuntu Server IP gateway: 192.168.107.1
    • Internal DNS Server 1: 192.168.107.212
    • Internal DNS Server 2: 192.168.107.213
    • External DNS Server 1: 8.8.8.4
    • External DNS Server 2: 8.8.8.5
    • Ubuntu Admin ID: administrator
    • Ubuntu Admin Password: myadminpass
    • Email Server (remote): 192.168.107.25
    • Windows Share ID: myshare
    • Windows Share Password: mysharepass


    It is also assumed that the reader knows how to use the VI editor. If not, you will need to beef up your skill set or use a different editor in place of it.
    Last edited by CharlesA; July 18th, 2012 at 01:09 AM. Reason: added link to current guide

  2. #2
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    Analysis and Design

    The Ubuntu Server Long-Term Support (LTS) is great choice for companies because it is a solid operating system that happens to be free. If professional support is needed, there is an option to buy support for the Long-Term Support (LTS) versions of the operating system.

    The large decision over the configuration of Ubuntu is how the hard drive space is sliced up (partitioned). This documentation will focus on partitioning the drives in such a way that it allows for growth depending on what is needed for the specific application.

    This following design allows for dynamic growth and fine-tuning if need be. Being caught offguard with a scenario where space is filled up with no immediate option other than deleting files is never a good thing. Long-term life and growth of the system as well as budgeting concerns have to be taken into consideration.

    Isolating the root volume to mainly just static data that will not grow much over time is the central concern. Pushing the other folders into their own volumes will be done so their dynamic growth will not affect the root partition. Filling up the root volume on a *nix system is a very bad thing and should be avoided at all costs. The file systems will also not take up 100% of the logical volume. This will allow the file systems (through automated scripts) to grow as needed and give the administrators some time to add more drives if necessary or shrink other volumes to get more space.

    The volumes will initially be sliced up as follows:


    • boot - This will remain static in size. It is also the only space residing outside the Logical Volume Manager (LVM)
    • root volume - Operating system and everything else which should remain fairly static.
    • swap volume - This will remain static in size. However, if the amount of RAM is adjusted, this might need to be adjusted as well.
    • home volume - This is where personal files will be stored but likely not be used in most server configurations.
    • tmp volume - This location will be used for temporary storage. Size should be adjusted to match however it is being used.
    • usr volume - This will contain mostly static data and should not grow unexpectedly.
    • var volume - This is the app/database/log storage and will continue to grow over time.
    • srv volume - This will contain the files stored in the Samba share.
    • opt volume - This will contain specific software you add but may not be utilized at all depending on configuration.
    • bak volume - This will contain a local backup of the application. So space needs to be about double the size of your app data (typically double the /var size).
    • Offsite Storage - This will be handled elsewhere but will be mounted on this server.


    The partitions will be increased later as needed but will start off with a lower number.

    To get a good idea of the initial hard drive layout and to understand the process better, here is a graphical representation of the initial design for the server:



    These numbers will be used for the initial build of the system:

    boot = 200 MB
    root = 2 GB
    swap = 2 GB
    home = 0.2 GB
    tmp = 0.5 GB
    usr = 2.0 GB
    var = 2.0 GB
    srv = 0.2 GB
    opt = 0.2 GB
    bak = 0.5 GB

    NOTE #1: When the logical volumes and file systems are initially created, they consume the maximum amount of space allocated so that the file system size will initially equal the logical volume size. These partition sizes above are artificially small for that reason. These will be later modified so that the logical volume will be larger than the file system so that the file system has room to expand when needed in a safe and automated manner.

    NOTE #2: If you are going to have users with accounts on the system, you should also create a separate home volume and map it to /home in the same way /srv is done.

    Important info:
    - The /tmp folder is strictly temporary. By default, each time the server reboots, this folder is deleted and re-created.
    - The /bak folder will retain the most recent backup and is considered the "local" copy of the backup.

    VMware Virtual Machine Settings

    Virtual Manager: VMware vSphere Client 4.1
    Virtual Host: VMware ESXi Server 4.1


    • Configuration: Custom
    • Name: srv-ubuntu
    • Datastore: DS3400-LUN0
    • Virtual Machine Version: 7
    • Guest Operating System: Linux, Version: Ubuntu Linux (64-bit)
    • Number of virtual processors: 1
    • Memory Size: 1024 MB
    • Number of NICs: 1
    • NIC 1: VM Network
    • Adapter: E1000, Connect at Power On: Checked
    • SCSI controller: LSI Logic Parallel
    • Select a Disk: Create a new virtual disk
    • Create a Disk: 10 GB, No thin provisioning, No cluster features, Store with the virtual machine
    • Advanced Options: Virtual Device Node = SCSI (0:0)
    • Remove Floppy Drive
    • Mount CD/DVD Drive to Ubuntu ISO (ubuntu-12.04-server-amd64.iso). Make sure CD/DVD is set to Connect at power on
    • Set boot options to Force BIOS Setup so you can set CDROM to boot before the Hard Disk


    VirtualBox Virtual Machine Settings

    Virtual Manager: Oracle VirtualBox 4.1.16
    Virtual Host: Windows 7 Ultimate with SP1 (64-bit)


    • Name: srv-ubuntu
    • Operating System: Linux
    • Version: Ubuntu (64 bit)
    • Memory: 1024 MB
    • Check - Start-up Disk
      - Create new hard disk
      - VMDK
      - Dynamically allocated
      - Size: 10 GB
    • Select srv-ubuntu and click Settings (CTRL+S)
      - System, Processor, Enable PAE/NX
      - Network, Attached to: Bridged Adapter, Advanced, Adapter Type: Intel PRO/1000 MT Server
      - Storage, IDE Controller, Choose a virtual CD/DVD disk file, ubuntu-12.04-server-amd64.iso


    Install PuTTY

    When running inside a virtual machine, the response time for screen refreshes can be painfully slow to view man (manual) pages and navigating in VI (text editor). However, when using PuTTY via SSH, it is a far better solution for your Ubuntu console because it handles the screen draws much faster when scrolling and allows copying and pasting text between windows.

    For example, selecting and copying a command in this document and then right-clicking in the PuTTY window will paste the command and have it ready to execute. Any text/lines highlighted with the mouse will be automatically copied into clipboard memory.

    Download the portable edition and run the install...except it does not really "install" like a normal program, it simply extracts to a specified folder and will run from that folder even if you put it on a USB stick and carry over to a new computer (requires no install to run and thus leaves no footprint on your system)


    1. Start PuTTY
    2. Type the following and click the Save button:
      Host Name: SRV-Ubuntu (or the IP such as 192.168.107.2)
      Port: 22
      Connection type: SSH
      Saved Sessions: SRV-Ubuntu
    3. Now all you have to do is double-click on the session and it will connect to your server (when online).

  3. #3
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    Install Ubuntu Server

    NOTE: During the setup process throughout this entire document, most commands will require "sudo" as a prefix. However, this document will be using "sudo su" to temporarily gain root privileges so that subsequent commands will work without the need for the "sudo" prefix.


    1. Power on the Virtual Machine (VM)
    2. Press {ENTER} to accept English
    3. Select Install Ubuntu Server {ENTER}
    4. Press {ENTER} to accept English
    5. Press {ENTER} to accept United States
    6. Select No to not detect keyboard layout
    7. Press {ENTER} to accept English (US)
    8. Press {ENTER} to accept English (US)
    9. Type srv-ubuntu {ENTER} (this is your hostname)
    10. Type Administrator, {ENTER} for the full name
    11. Press {ENTER} to accept the default of the lowercase name of administrator
    12. Type myadminpass, {ENTER}, myadminpass, {ENTER}
    13. Select No, {ENTER} to not encrypt your home directory
    14. Press {ENTER} to accept detected time zone (America/Chicago)
    15. Select Manual {ENTER}
    16. Select SCSI3 (0,0,0) (sda) - 10.7 GB VMware Virtual disk {ENTER}
    17. Select Yes to create new empty partition table, {ENTER}
    18. Select pri/log 10.7 GB FREE SPACE {ENTER}
    19. Select Create a new partition {ENTER}
    20. Type 200MB, {ENTER} (NOTE: This will be the /boot partition)
    21. Select Primary {ENTER}
    22. Select Beginning {ENTER}
    23. Select Use as: Ext4 journaling file system {ENTER}
    24. Select Ext2 file system {ENTER}
    25. Select Mount point: / {ENTER}
    26. Select /boot - static files of the boot loader {ENTER}
    27. Select Bootable flag: off {ENTER} (NOTE: This toggles it on)
    28. Select Done setting up the partition {ENTER}
    29. Select Configure the Logical Volume Manager {ENTER}
    30. Select Yes to write change to disks and configure LVM, {ENTER}
    31. Select Create volume group {ENTER}
    32. Type LVG {ENTER}
    33. Select /dev/sda free #1 (10537MB; FREE SPACE), {SPACEBAR}, {ENTER}
    34. Select Yes to write change to disks and configure LVM, {ENTER}
    35. Select Create logical volume {ENTER}
    36. Select LVG (10531MB) {ENTER}
    37. Type root {ENTER}
    38. Type 2G {ENTER}
    39. Select Create logical volume {ENTER}
    40. Select LVG (8535MB) {ENTER}
    41. Type swap {ENTER}
    42. Type 2G {ENTER} (NOTE: This is double the amount of RAM)
    43. Select Create logical volume {ENTER}
    44. Select LVG (6538MB) {ENTER}
    45. Type home {ENTER}
    46. Type 0.2G {ENTER}
    47. Select Create logical volume {ENTER}
    48. Select LVG (6341MB) {ENTER}
    49. Type tmp {ENTER}
    50. Type 0.5G {ENTER}
    51. Select Create logical volume {ENTER}
    52. Select LVG (5842MB) {ENTER}
    53. Type usr {ENTER}
    54. Type 2G {ENTER}
    55. Select Create logical volume {ENTER}
    56. Select LVG (3846MB) {ENTER}
    57. Type var {ENTER}
    58. Type 2G {ENTER}
    59. Select Create logical volume {ENTER}
    60. Select LVG (1849MB) {ENTER}
    61. Type srv {ENTER}
    62. Type 0.2G {ENTER}
    63. Select Create logical volume {ENTER}
    64. Select LVG (1652MB) {ENTER}
    65. Type opt {ENTER}
    66. Type 0.2G {ENTER}
    67. Select Create logical volume {ENTER}
    68. Select LVG (1455MB) {ENTER}
    69. Type bak {ENTER}
    70. Type 0.5G {ENTER} (we will have a small amount leftover in LVG)
    71. Select Finish {ENTER}
    72. Select #1 2.0 GB directly under LVM VG LVG, LV root, {ENTER}
    73. Select Use as: do not use {ENTER}
    74. Select Ext4 journaling file system {ENTER}
    75. Select Mount point: none {ENTER}
    76. Select / - the root file system {ENTER}
    77. Select Label: none {ENTER}
    78. Type root {ENTER}
    79. Select Done setting up the partition {ENTER}
    80. Select #1 2.0 GB directly under LVM VG LVG, LV swap, {ENTER}
    81. Select Use as: do not use {ENTER}
    82. Select swap area {ENTER}
    83. Select Done setting up the partition {ENTER}
    84. Select #1 197.1 MB directly under LVM VG LVG, LV home, {ENTER}
    85. Select Use as: do not use {ENTER}
    86. Select Ext4 journaling file system {ENTER}
    87. Select Mount point: none {ENTER}
    88. Select /home {ENTER}
    89. Select Label: none {ENTER}
    90. Type home {ENTER}
    91. Select Done setting up the partition {ENTER}
    92. Select #1 499.1 MB directly under LVM VG LVG, LV tmp, {ENTER}
    93. Select Use as: do not use {ENTER}
    94. Select Ext4 journaling file system {ENTER}
    95. Select Mount point: none {ENTER}
    96. Select /tmp {ENTER}
    97. Select Label: none {ENTER}
    98. Type tmp {ENTER}
    99. Select Label: tmp {ENTER}
    100. Select Done setting up the partition {ENTER}
    101. Select #1 2.0 GB directly under LVM VG LVG, LV usr, {ENTER}
    102. Select Use as: do not use {ENTER}
    103. Select Ext4 journaling file system {ENTER}
    104. Select Mount point: none {ENTER}
    105. Select /usr {ENTER}
    106. Select Label: none {ENTER}
    107. Type usr {ENTER}
    108. Select Done setting up the partition {ENTER}
    109. Select #1 2.0 GB directly under LVM VG LVG, LV var, {ENTER}
    110. Select Use as: do not use {ENTER}
    111. Select Ext4 journaling file system {ENTER}
    112. Select Mount point: none {ENTER}
    113. Select /var {ENTER}
    114. Select Label: none {ENTER}
    115. Type var {ENTER}
    116. Select Done setting up the partition {ENTER}
    117. Select #1 197.1 MB directly under LVM VG LVG, LV srv, {ENTER}
    118. Select Use as: do not use {ENTER}
    119. Select Ext4 journaling file system {ENTER}
    120. Select Mount point: none {ENTER}
    121. Select /srv {ENTER}
    122. Select Label: none {ENTER}
    123. Type srv {ENTER}
    124. Select Done setting up the partition {ENTER}
    125. Select #1 197.1 MB directly under LVM VG LVG, LV opt, {ENTER}
    126. Select Use as: do not use {ENTER}
    127. Select Ext4 journaling file system {ENTER}
    128. Select Mount point: none {ENTER}
    129. Select /opt {ENTER}
    130. Select Label: none {ENTER}
    131. Type opt {ENTER}
    132. Select Done setting up the partition {ENTER}
    133. Select #1 499.1 MB directly under LVM VG LVG, LV bak, {ENTER}
    134. Select Use as: do not use {ENTER}
    135. Select Ext4 journaling file system {ENTER}
    136. Select Mount point: none {ENTER}
    137. Select Enter manually {ENTER}
    138. Type /bak {ENTER}
    139. Select Label: none {ENTER}
    140. Type bak {ENTER}
    141. Select Done setting up the partition {ENTER}
    142. Here is what the screen looks like at this point: Partitions
    143. Select Finish partitioning and write changes to disk {ENTER}
    144. Select Yes to write changes to disk, {ENTER}
    145. Press {ENTER} to accept a blank line for the HTTP proxy
    146. Select Install security updates automatically, {ENTER}
    147. Highlight only OpenSSH server and press {SPACEBAR} to enable, {ENTER} to continue. NOTE: This allows us to use PuTTY after installation to connect to the server.
    148. Select Yes, {ENTER} to install GRUB boot loader to the master boot record
    149. Installation Complete - from the VM menu, select VM --> Edit Settings and select CD/DVD Drive 1 and change to "Client Device" which will effectively remove the ISO. Now press {ENTER} to reboot.



    Initial Configurations


    1. At the login prompt, login with your administrator account (administrator / myadminpass)
    2. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    3. Type vi /etc/network/interfaces {ENTER} and change the following: (We need to change the network interface card (NIC) from using DHCP to a static IP)
      From:
      Code:
      iface eth0 inet dhcp
      To:
      Code:
      iface eth0 inet static
      address 192.168.107.2
      netmask 255.255.255.0
      gateway 192.168.107.1
      network 192.168.107.0
      broadcast 192.168.107.255
      dns-nameservers 192.168.107.212 192.168.107.213 8.8.8.4 8.8.8.5
      
      NOTE #1: You may need to manually remove the DHCP record (lease) associated to this Ubuntu server from your DHCP server so the correct IP can be found by other machines on the network. This can be avoided by temporarily configuring the VM Network Adapter connection to be "Host Only Network" instead of "VM Network" so the server is isolated during setup...at least until you reach the testing of the static IP below.

      NOTE #2: You might also need to manually add a HOST(A) record to your Windows DNS server (for srv-ubuntu.mydomain.com and srv-ubuntu.work.mydomain.com)
    4. Restart the network by typing /etc/init.d/networking restart
      NOTE: The above command complains about it being depricated and to use the following command but it simply does not work...so use the above command for now...not this one: service networking restart
    5. Sanity check! Type ifconfig and make sure the settings are correct. Then type ping www.google.com or similar and see if ping works.
    6. Shutdown and power off the server by typing shutdown -P now
    7. At this point forward, you can use PuTTY to access the console rather than the console itself for better performance, ability to scroll, etc.
    8. In VM menu, select VM --> Snapshot --> Take Snapshot. Give it a name like STEP 1 and description of Ubuntu Server 12.04 LTS, clean install, Static IP: 192.168.107.2 and click OK



    Operating System Patches


    1. Start the Ubuntu server and connect using PuTTY.
    2. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    3. Install the patches by typing the following commands:
      Code:
      
      aptitude update
      aptitude safe-upgrade
      
    4. Shutdown and power off the server by typing shutdown -P now
    5. In VM menu, select VM --> Snapshot --> Take Snapshot. Give it a name like STEP 2 and description of Ubuntu Server 12.04 LTS, Patches applied, Static IP: 192.168.107.2. The Snapshot Manager should now have a nice hierarchy of snapshots (STEP 1 --> STEP 2 --> You are here)
    Last edited by LHammonds; June 26th, 2012 at 06:43 PM.

  4. #4
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    Volume / Disk Management

    Earlier, it was mentioned that the partition design needed to have some breathing room in each volume so that the file system inside can grow as needed. When the volumes were created during setup, the file systems were automatically expanded to fill the entire volume. We will now correct this by adding more "drives" to the system and then extend each logical volume to gain some breathing space.

    Most logical volumes will be increased in size and then the file systems contained in them will be increased but not to the maximum amount.

    This design will allow growth when needed and ensure that there will be time to add additional hard drives BEFORE they are needed which will keep the administrators from being stuck between a rock and a hard place! Nobody wants to lose a job because somebody did not estimate growth correctly or the budget did not allow for large capacity when the system first rolled out.

    Here are the planned adjustments for each logical volume:

    root = 2 GB to 3 GB
    swap = 2 GB (no change)
    home = 0.2 GB to 1 GB
    tmp = 0.5 GB to 2 GB
    usr = 2.0 GB to 3 GB
    var = 2.0 GB to 3 GB
    srv = 0.2 GB to 2 GB
    opt = 0.2 GB to 2 GB
    bak = 0.5 GB to 4 GB

    Here are the planned adjustments for each file system:

    root = 2 GB (no change)
    swap = 2 GB (no change)
    home = 0.2 GB to 0.5 GB
    tmp = 0.5 GB to 1 GB
    usr = 2.0 GB (no change)
    var = 2.0 GB (no change)
    srv = 0.2 GB to 1 GB
    opt = 0.2 GB to 1 GB
    bak = 0.5 GB to 2 GB

    We started off with a 10 GB drive to hold these volumes but now need 22 GB. For this exercise, we will add two 12 GB drives to cover the additional storage needs. (NOTE: This was an arbitrary number in order to demonstrate how to add additional hard drives to the system)

    Here is a graphical representation of what needs to be accomplished:



    If we were to type df -h right now, we should see something like this:

    Code:
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/LVG-root  1.9G  429M  1.4G  24% /
    udev                  489M  4.0K  489M   1% /dev
    tmpfs                 200M  244K  199M   1% /run
    none                  5.0M     0  5.0M   0% /run/lock
    none                  498M     0  498M   0% /run/shm
    /dev/sda1             179M   47M  122M  28% /boot
    /dev/mapper/LVG-home  187M  9.5M  168M   6% /home
    /dev/mapper/LVG-tmp   473M   23M  427M   5% /tmp
    /dev/mapper/LVG-usr   1.9G  460M  1.4G  26% /usr
    /dev/mapper/LVG-var   1.9G  367M  1.5G  21% /var
    /dev/mapper/LVG-srv   187M  9.5M  168M   6% /srv
    /dev/mapper/LVG-opt   187M  9.5M  168M   6% /opt
    /dev/mapper/LVG-bak   473M   23M  427M   5% /bak
    Adding more space in VMware is easy. In this exercise, each drive will be added as a separate disk just as if we were to add a physical drive to a physical server.

    1. Shutdown and power off the server by typing shutdown -P now
    2. In the vSphere client, right-click the Virtual Machine and choose Edit Settings.
    3. On the hardware tab, click the Add button and select Hard Disk. Click Next, choose "Create a new virtual disk", click Next, set the size to 12 GB, click Next, Next, Finish.
    4. Add another 12 GB disk using the same steps above and click OK to close the settings and allow VMware to process the changes.


    Collect information about the newly added drives.

    1. Start the server and connect using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass) and then temporarily grant yourself super user privilages by typing sudo su
    3. Type pvdisplay which should show something similar to this:
      Code:
        --- Physical volume ---
        PV Name               /dev/sda5
        VG Name               LVG
        PV Size               9.81 GiB / not usable 3.00 MiB
        Allocatable           yes
        PE Size               4.00 MiB
        Total PE              2511
        Free PE               228
        Allocated PE          2283
        PV UUID               NkfC3i-ROqv-YuLZ-63VO-RTAU-l01p-suqi4O
      The important bits of info here are the PV Name and VG Name for our existing configuration.
    4. Type fdisk -l which should show something similar to this (however I abbreviated it to show just the important parts):
      Code:
      Disk /dev/sda: 10.7 GB, 10737418240 bytes
         Device Boot      Start         End      Blocks   Id  System
      /dev/sda1   *        2048      391167      194560   83  Linux
      /dev/sda2          393214    20969471    10288129    5  Extended
      /dev/sda5          393216    20969471    10288128   8e  Linux LVM
      
      Disk /dev/sdb: 12.9 GB, 12884901888 bytes
      Disk /dev/sdb doesn't contain a valid partition table
      Disk /dev/sdc: 12.9 GB, 12884901888 bytes
      Disk /dev/sdc doesn't contain a valid partition table
      The important bits of info here are the device paths for the new drives which I highlighted in red.


    Prepare the first drive (/dev/sdb) to be used by the LVM

    Type the following:
    Code:
    fdisk /dev/sdb
    n (Create New Partition)
    p (Primary Partition)
    1 (Partition Number)
    {ENTER} (use default for first cylinder)
    {ENTER} (use default for last cylinder)
    t (Change partition type)
    8e (Set to Linux LVM)
    p (Preview how the drive will look)
    w (Write changes)
    Prepare the second drive (/dev/sdc) to be used by the LVM

    Do the exact same steps as above but start with fdisk /dev/sdc

    Create physical volumes using the new drives

    If we type fdisk -l, we now see /dev/sdb1 and /dev/sdc1 which are Linux LVM partitions.

    Type the following to create physical volumes:
    Code:
    pvcreate /dev/sdb1
    pvcreate /dev/sdc1
    Now add the physical volumes to the volume group (LVG) by typing the following:
    Code:
    vgextend LVG /dev/sdb1
    vgextend LVG /dev/sdc1
    Now that the space of both drives have been added to the logical volume group called LVG, we can now allocate that space to grow the logical volumes.

    To get a list of volume paths to use in the next commands, type lvscan to show your current volumes and their sizes.

    Type the following to set the exact size of the volume by specifying the end-result size you want:

    Code:
    
    lvextend -L3G /dev/LVG/root
    lvextend -L1G /dev/LVG/home
    lvextend -L2G /dev/LVG/tmp
    lvextend -L3G /dev/LVG/usr
    lvextend -L3G /dev/LVG/var
    lvextend -L2G /dev/LVG/srv
    lvextend -L2G /dev/LVG/opt
    lvextend -L4G /dev/LVG/bak
    
    or you can grow each volume by the specified amount (the number after the plus sign):
    Code:
    
    lvextend -L+1G /dev/LVG/root
    lvextend -L+0.8G /dev/LVG/home
    lvextend -L+1.5G /dev/LVG/tmp
    lvextend -L+1G /dev/LVG/usr
    lvextend -L+1G /dev/LVG/var
    lvextend -L+1.8G /dev/LVG/srv
    lvextend -L+1.8G /dev/LVG/opt
    lvextend -L+3.5G /dev/LVG/bak
    
    To see the new sizes, type lvscan
    Code:
      ACTIVE            '/dev/LVG/root' [3.00 GiB] inherit
      ACTIVE            '/dev/LVG/swap' [1.86 GiB] inherit
      ACTIVE            '/dev/LVG/home' [1.00 GiB] inherit
      ACTIVE            '/dev/LVG/tmp' [2.00 GiB] inherit
      ACTIVE            '/dev/LVG/usr' [3.00 GiB] inherit
      ACTIVE            '/dev/LVG/var' [3.00 GiB] inherit
      ACTIVE            '/dev/LVG/srv' [2.00 GiB] inherit
      ACTIVE            '/dev/LVG/opt' [2.00 GiB] inherit
      ACTIVE            '/dev/LVG/bak' [4.00 GiB] inherit
    The last thing to do now is the actual growth of the file systems. We want to grow the existing file systems but only to a certain amount so we do not take up all the space in the volume. We want room for growth in the future so we have time to order and install new drives when needed.
    Code:
    
    resize2fs /dev/LVG/home 500M
    resize2fs /dev/LVG/tmp 1G
    resize2fs /dev/LVG/srv 1G
    resize2fs /dev/LVG/opt 1G
    resize2fs /dev/LVG/bak 2G
    
    If we need to increase space in /var at a later point, we can issue the following command without any downtime (we will automate this in a nifty script later):

    Code:
    resize2fs /dev/LVG/var 2560MB
    We could continue to increase this particular file system all the way until we reach the limit of the volume which is 3 GB at the moment.

    If we were to type df -h right now, we should see something like this:

    Code:
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/LVG-root  1.9G  429M  1.4G  24% /
    udev                  489M  4.0K  489M   1% /dev
    tmpfs                 200M  260K  199M   1% /run
    none                  5.0M     0  5.0M   0% /run/lock
    none                  498M     0  498M   0% /run/shm
    /dev/sda1             179M   47M  122M  28% /boot
    /dev/mapper/LVG-home  488M  9.7M  454M   3% /home
    /dev/mapper/LVG-tmp  1004M   23M  931M   3% /tmp
    /dev/mapper/LVG-usr   1.9G  460M  1.4G  26% /usr
    /dev/mapper/LVG-var   1.9G  367M  1.5G  21% /var
    /dev/mapper/LVG-srv   996M  9.9M  935M   2% /srv
    /dev/mapper/LVG-opt   996M  9.9M  935M   2% /opt
    /dev/mapper/LVG-bak   2.0G   23M  1.9G   2% /bak
    Remember, df -h will tell you the size of the file system and lvscan will tell you the size of the volumes where the file systems live in.

    TIP: If you want to see everything in a specific block size, such as everything showing up in megabytes, you can use df --block-size m

    Shutdown and power off the server by typing shutdown -P now

    In VM menu, select VM --> Snapshot --> Take Snapshot. Give it a name like STEP 3 and description of Ubuntu Server 12.04 LTS, Storage space adjusted, Static IP: 192.168.107.2. The Snapshot Manager should now have a nice hierarchy of snapshots (STEP 1 --> STEP 2 --> STEP 3 --> You are here)
    Last edited by LHammonds; June 26th, 2012 at 06:44 PM.

  5. #5
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    Software Configurations


    1. Turn on the server and connect using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    4. At the $ prompt, type aptitude -y install vim-nox for use instead of the built-in VI editor. more info
    5. At the $ prompt, type aptitude -y install p7zip-full to install 7-zip archive utility.
    6. At the $ prompt, type aptitude -y install sendemail to install a command-line email utility.
    7. Change the default shell from dash to bash. Type ls -l /bin/sh to see that it points to /bin/dash. Type dpkg-reconfigure dash and answer No. Type ls -l /bin/sh and it should now be pointing to /bin/bash
    8. It might be necessary to remove AppArmor to avoid problems by typing the following:
      Code:
      /etc/init.d/apparmor stop
      /etc/init.d/apparmor teardown
      update-rc.d -f apparmor remove
      aptitude remove apparmor apparmor-utils
    9. Type vi /etc/hosts and add your email server:
      Code:
      192.168.107.25    srv-mail
    10. Test the ability to send email by typing:
      Code:
      sendemail -f root@myserver -t MyTargetAddress@MyDomain.com -u "This is the Subject" -m "This is the body of the email" -s srv-mail:25
    11. Reboot the server by typing reboot



    VMware Tools

    VMware Tools need to be installed if the VM is using a VMware host. This will insure maximum performance in a virtual environment.


    1. In the VM toolbar for the VM, click Guest, Install VMware Tools
    2. Connect to the server using PuTTY
    3. At the login prompt, login with your administrator account (administrator / myadminpass)
    4. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    5. Type the following:
      Code:
      
      mkdir /mnt/cdrom
      mount /dev/cdrom /mnt/cdrom
      ls /mnt/cdrom       ( make sure you see a file such as VMwareTools-8.3.12-653202.tar.gz)
      tar zxvf /mnt/cdrom/VMwareTools* -C /tmp/
      cd /tmp/vmware-tools-distrib/
      ./vmware-install.pl -d
      reboot
      



    VMware Tools Upgrade

    Before the updated version can be installed, the currently installed version must 1st be removed.

    To determine which version is installed, run this command:
    Code:
    
    grep buildNr /usr/bin/vmware-config-tools.pl
    

    1. Connect to the server using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    4. Type the following to remove VMware Tools:
      Code:
      
      vmware-uninstall-tools.pl
      
    5. Now install the new VMware Tools as described in the install section above.




    VirtualBox Guest Additions - Installation

    The Guest Additions need to be installed if the VM is using a VirtualBox host. This will insure maximum performance in a virtual environmnet.


    1. Connect to the server using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    4. You need to perform the following commands to fulfill the prerequisites:
      Code:
      
      aptitude install dkms
      reboot
      
    5. Connect to the server using PuTTY.
    6. At the login prompt, login with your administrator account (administrator / myadminpass)
    7. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    8. From the VirtualBox menu, click Devices, Install Guest Additions
    9. At the console, type the following:
      Code:
      
      mkdir -p /mnt/cdrom
      mount /dev/cdrom /mnt/cdrom
      /mnt/cdrom/VBoxLinuxAdditions.run
      
    10. NOTE: The X Windows System drivers will fail to load because this is a headless server with no GUI (which is OK)
    11. To see if the services are running, type /etc/init.d/vboxadd-service status or service vboxadd-service status



    VirtualBox Guest Additions - Upgrading

    If VirtualBox is updated on the host machine, each VM also needs the upgraded Guest Additions.

    Then mount the CDROM and run the installer just like the above. Reboot after it is upgraded.


    1. Connect to the server using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    4. From the VirtualBox menu, click Devices, Install Guest Additions
    5. At the console, type the following:
      Code:
      
      mount /dev/cdrom /mnt/cdrom
      /mnt/cdrom/VBoxLinuxAdditions.run
      reboot
      



    VirtualBox Guest Additions - Uninstallation

    If a VM will be migrated from VirtualBox to something like a VMware, the Guest Additions on the VM will need to be removed.


    1. Connect to the server using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    4. Type the following:
      Code:
      
      cd /opt/VBox*
      ./uninstall.sh
      
    Last edited by LHammonds; June 26th, 2012 at 06:45 PM.

  6. #6
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    Configure Ubuntu for File Sharing

    This file sharing section is optional but can be handy if you need to swap files between the Linux server and a Windows machine.

    This documentation will utilize this share for passing pre-configured files (configs, scripts, etc.) to make it faster/easier during installation.


    1. Start the Ubuntu server and connect using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privilages by typing sudo su{ENTER} and then provide the administrator password (myadminpass).
    4. Install Samba by typing aptitude -y install samba smbfs (NOTE: To share a folder with Windows, you just need the samba package, to connect to a Windows share, you need both samba and smbfs)
    5. Type the following commands:
      Code:
      
      cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
      mkdir -p /srv/samba/share
      chown nobody:nogroup /srv/samba/share/
      chmod 0777 /srv/samba/share
      
    6. Edit the configuration file by typing vi /etc/samba/smb.conf
    7. Change workgroup = WORKGROUP to workgroup = work (you are using the domain alias)
    8. Change:
      Code:
      #   security = user
      to:
      Code:
         security = user
    9. Add the following section to the end of the file:
      Code:
      [share]
      comment = Ubuntu File Server Share
      path = /srv/samba/share
      browsable = yes
      guest ok = yes
      read only = no
      create mask = 0755
    10. Save and exit the file.
    11. Restart the samba services to utilize the new configuration by typing:
      Code:
      restart smbd
      restart nmbd
    12. You should now be able to click Start --> Run and type \\srv-ubuntu or \\192.168.107.2 {ENTER} and see an explorer window with a Share folder. Drag-n-drop a file into the Share folder. If it worked, it will not display an error message and you should be able to view it from the server by typing ls -l /srv/samba/share/
    13. Shutdown and power off the server by typing shutdown -P now
    14. In VM menu, select VM --> Snapshot --> Take Snapshot. Give it a name like STEP 4 and description of Ubuntu Server 12.04 LTS, File share configured, Static IP: 192.168.107.2. The Snapshot Manager should now have a nice hierarchy of snapshots (STEP 1 --> STEP 2 --> STEP 3 --> STEP 4 --> You are here)
    Last edited by LHammonds; June 26th, 2012 at 06:45 PM.

  7. #7
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    Scripting

    Much of the solutions beyond this point involve scripts (programming snippets / automated commands).

    In particular, they are Bash Scripts. I chose this due to its popularity and the fact it comes with Ubuntu. I try to make use of what comes with the system without requiring additional software / services unless they really add to the bottom line such as decreasing the time it takes for a process to run or to conserve storage and bandwidth usage.

    When setting up a server and testing things out, there is typically very little concern for procedures / process since much of the activity is exploration and experimentation as well as not having an impact on production. However, once a server goes into production, processes and procedures need to be in place to ensure the availability of the services being provided.

    In regards to these scripts, they will be treated like any other program and will require being tested, documented and go through a promotion process.

    The ideal situation would involve 3 servers (for a single server setup). A test / development server, a quality assurance staging server and the production server itself. If 3 servers cannot be utilized, then it can still work well with 2 servers. Testing scripts / programs / restore on the production server is not advisable and many times impractical...how can you test your restore process / data periodically if you only have a production server?

    The QA Staging server would resemble the production server as close as possible. The server should be setup in such a way that production backups are restored to this server which also tests and validates the backup / restore process as well as maintains a close representation of the production server to mitigate variable risk involved when testing new or modified programs and upgrades.

    The test / development server can serve as the QA server if absolutely necessary.

    The directory structure and how scripts can import other scripts will be configured to facilitate this process.

    Example:

    Directory path for scripts to import common variables, functions and server settings: /var/scripts/common/

    Directory path for production scripts: /var/scripts/prod/

    Directory path for QA staging area scripts: /var/scripts/qa/

    Directory path for test / development scripts: /var/scripts/test/

    Directory path for data for use by scripts: /var/scripts/data/

    With a production and test servers on physically different machines, the "common" scripts folder can be custom-tailored for that environment and allow for minimal changes to a script when running on the test, QA or production server. This is similar to "normalizing" a database. If you have a variable, path or function that is duplicated in multiple scripts, consider pulling it out and placing it in the common folder. If ever you need to change who receives the email reports, you only need to update a single script and all programs will use the new reference from that point on.

    Most of my scripts will import a file called "standard.conf" from the common script folder.

    /var/scripts/common/standard.conf (contents of the file on the production server)
    Code:
    ## Global Variables ##
    TEMPDIR="/tmp"
    LOGDIR="/var/log"
    SHAREDIR="/srv/samba/share"
    MYDOMAIN="mydomain.com"
    ADMINEMAIL="admin@${MYDOMAIN}"
    REPORTEMAIL="lhammonds@${MYDOMAIN}"
    BACKUPDIR="/bak"
    OFFSITEDIR="/mnt/backup"
    OFFSITETESTFILE="${OFFSITEDIR}/online.txt"
    ARCHIVEMETHOD="tar.7z"    ## Choices are tar.7z or tgz
    HOSTNAME="$(hostname -s)"
    SCRIPTNAME="$0"
    SCRIPTDIR="/var/scripts"
    MAILFILE="${TEMPDIR}/mailfile.$$"
    
    ## Global Functions ##
    
    function f_sendmail()
    {
      ## Purpose: Send administrative email message.
      ## Parameter #1 = Subject
      ## Parameter #2 = Body
      sendemail -f "${ADMINEMAIL}" -t "${REPORTEMAIL}" -u "${1}" -m "${2}\n\nServer: ${HOSTNAME}\nProgram: ${SCRIPTNAME}\nLog: ${LOGFILE}" -s srv-mail:25 1>/dev/null 2>&1
    }
    
    function f_sendusermail()
    {
      ## Purpose: Send end-user email message.
      ## Parameter #1 = To
      ## Parameter #2 = Subject
      ## Parameter #3 = Body
      sendemail -f "${ADMINEMAIL}" -t "${1}" -u "${2}" -m "${3}" -s srv-mail:25 1>/dev/null 2>&1
    }
    
    function f_mount()
    {
      ## Mount the pre-configured Windows share folder.
      ## NOTE: The Windows share should have a file called "online.txt"
      mount -t cifs //srv-backup/mysql ${OFFSITEDIR} --options nouser,rw,nofail,noatime,noexec,credentials=/etc/cifspw
    }
    
    function f_umount()
    {
      ## Dismount the Windows share folder.
      ## NOTE: The unmounted folder should have a file called "offline.txt"
      umount ${OFFSITEDIR}
    }

    /var/scripts/common/standard.conf (contents of the file on the test server)
    Code:
    ## Global Variables ##
    TEMPDIR="/tmp"
    LOGDIR="/var/log"
    SHAREDIR="/srv/samba/share"
    MYDOMAIN="mytestdomain.com"
    ADMINEMAIL="test1@${MYDOMAIN}"
    REPORTEMAIL="test2@${MYDOMAIN}"
    BACKUPDIR="/bak"
    OFFSITEDIR="/mnt/fakedir"
    OFFSITETESTFILE="${OFFSITEDIR}/online.txt"
    ARCHIVEMETHOD="tar.7z"    ## Choices are tar.7z or tgz
    HOSTNAME="$(hostname -s)"
    SCRIPTNAME="$0"
    SCRIPTDIR="/var/scripts"
    MAILFILE="${TEMPDIR}/mailfile.$$"
    
    ## Global Functions ##
    
    function f_sendmail()
    {
      ## Purpose: Send administrative email message.
      ## Parameter #1 = Subject
      ## Parameter #2 = Body
      sendemail -f "${ADMINEMAIL}" -t "${REPORTEMAIL}" -u "${1}" -m "${2}\n\nServer: ${HOSTNAME}\nProgram: ${SCRIPTNAME}\nLog: ${LOGFILE}" -s srv-mail:25 1>/dev/null 2>&1
    }
    
    function f_sendusermail()
    {
      ## Purpose: Send end-user email message.
      ## Parameter #1 = To
      ## Parameter #2 = Subject
      ## Parameter #3 = Body
      sendemail -f "${ADMINEMAIL}" -t "${1}" -u "${2}" -m "${3}" -s srv-mail:25 1>/dev/null 2>&1
    }
    
    function f_mount()
    {
      ## Mount the pre-configured Windows share folder.
      ## NOTE: The Windows share should have a file called "online.txt"
      mount -t cifs //mypc/share ${OFFSITEDIR} --options nouser,rw,nofail,noatime,noexec,credentials=/etc/cifspw
    }
    
    function f_umount()
    {
      ## Dismount the Windows share folder.
      ## NOTE: The unmounted folder should have a file called "offline.txt"
      umount ${OFFSITEDIR}
    }

    When receiving administrative email notifications, the server name, script name and path will be included at the bottom of the email every time. It will be readily apparent if the email was generated from the test, qa or production server simply because of the location (even if test, qa and production are all on the same server).

    Here are the scripts to help automate the creation of this structure on the various servers (would run all of them if all are the same box)

    setup-script-prod.sh
    Code:
    #!/bin/bash
    if [ ! -d /var/scripts/prod ]; then
      mkdir -p /var/scripts/prod
    fi
    if [ ! -d /var/scripts/common ]; then
      mkdir -p /var/scripts/common
    fi
    if [ ! -d /var/scripts/data ]; then
      mkdir -p /var/scripts/data
    fi
    chown root:root -R /var/scripts
    chmod 0755 -R /var/scripts
    setup-script-qa.sh
    Code:
    #!/bin/bash
    if [ ! -d /var/scripts/qa ]; then
      mkdir -p /var/scripts/qa
    fi
    if [ ! -d /var/scripts/common ]; then
      mkdir -p /var/scripts/common
    fi
    if [ ! -d /var/scripts/data ]; then
      mkdir -p /var/scripts/data
    fi
    chown root:root -R /var/scripts
    chmod 0777 -R /var/scripts
    setup-script-test.sh
    Code:
    #!/bin/bash
    if [ ! -d /var/scripts/test ]; then
      mkdir -p /var/scripts/test
    fi
    if [ ! -d /var/scripts/common ]; then
      mkdir -p /var/scripts/common
    fi
    if [ ! -d /var/scripts/data ]; then
      mkdir -p /var/scripts/data
    fi
    chown root:root -R /var/scripts
    chmod 0777 -R /var/scripts
    Last edited by LHammonds; June 26th, 2012 at 08:08 PM.

  8. #8
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    Check Storage Space

    In favor of managing by exception, this script that can be scheduled to run daily to check the file systems to see if they are getting close to filling up and will automatically expand them a little bit and give you an email notice. Everything is done at the megabyte level. If you do not want the script to perform the increase, simply add a pound sign in front of the resize2fs command on line 62 to comment it out. Might also want to modify the log and email messages so it does not look like it actually "performed" the resize but instead is telling YOU how to perform the resize.

    Here are the lines added to the root crontab schedule which will check each file system.

    The script check the specified file system and see if the amount of space free is less than the threshold (e.g. 100 MB). If the file system has free space that is less than the threshold, it will attempt to add the specified amount (e.g. 50 MB).

    crontab
    Code:
    0 1 * * * /var/scripts/prod/check-storage.sh root 500 100 > /dev/null 2>&1
    15 1 * * * /var/scripts/prod/check-storage.sh home 100 50 > /dev/null 2>&1
    30 1 * * * /var/scripts/prod/check-storage.sh tmp 100 50 > /dev/null 2>&1
    45 1 * * * /var/scripts/prod/check-storage.sh usr 100 50 > /dev/null 2>&1
    0 2 * * * /var/scripts/prod/check-storage.sh var 100 50 > /dev/null 2>&1
    15 2 * * * /var/scripts/prod/check-storage.sh srv 100 50 > /dev/null 2>&1
    30 2 * * * /var/scripts/prod/check-storage.sh opt 100 50 > /dev/null 2>&1
    45 2 * * * /var/scripts/prod/check-storage.sh bak 100 50 > /dev/null 2>&1
    /var/scripts/prod/check-storage.sh
    Code:
    #!/bin/bash
    #############################################
    ## Name          : check-storage.sh
    ## Version       : 1.0
    ## Date          : 2012-05-11
    ## Author        : LHammonds
    ## Purpose       : Check available space for a file system and expand if necessary.
    ## Compatibility : Verified on Ubuntu Server 12.04 LTS
    ## Requirements  : None
    ## Run Frequency : Recommend once per day for each FS to monitor.
    ## Parameters    :
    ##    1 = (Required) File System name (e.g. var)
    ##    2 = (Required) File System Threshold in MB (e.g. 100)
    ##    3 = (Required) Amount to increase File System in MB (e.g. 50)
    ## Exit Codes    :
    ##    0 = Success (either nothing was done or FS expanded without error)
    ##    1 = ERROR: Missing or incorrect parameter(s)
    ##    2 = ERROR: Invalid parameter value(s)
    ##    4 = ERROR: Lock file detected
    ##    8 = ERROR: Resize2fs error
    ##   16 = SEVERE: No room to expand
    ##   32 = ERROR: Script not run by root user
    ################ CHANGE LOG #################
    ## DATE       WHO WHAT WAS CHANGED
    ## ---------- --- ----------------------------
    ## 2012-05-11 LTH Created script.
    #############################################
    
    ## Import standard variables and functions. ##
    source /var/scripts/common/standard.conf
    
    ## Define local variables.
    LOGFILE="${LOGDIR}/check-storage.log"
    LOCKFILE="${TEMPDIR}/check-storage.lock"
    ErrorFlag=0
    ReturnCode=0
    
    #######################################
    ##            FUNCTIONS              ##
    #######################################
    
    function f_cleanup()
    {
      if [ -f ${LOCKFILE} ];then
        ## Remove lock file so other check space jobs can run.
        rm ${LOCKFILE} 1>/dev/null 2>&1
      fi
      exit ${ErrorFlag}
    }
    
    function f_showhelp()
    {
      echo -e "\nUsage : ${SCRIPTNAME} FileSystemName ThresholdSizeInMB AmountToIncreaseByInMB\n"
      echo -e "\nExample: ${SCRIPTNAME} var 50 50\n"
    }
    
    function f_auto-increment()
    {
      let RoomInLV=${LVSize}-${FSSize}
      if [[ ${RoomInLV} -gt ${FSIncreaseBy} ]]; then
        ## There is room in the LV to increase space to the FS.
        resize2fs ${FSVol} ${NewFSSize}M
        ReturnCode=$?
        echo "`date +%Y-%m-%d_%H:%M:%S` --- resize2fs ${FSVol} ${NewFSSize}M, ReturnCode=${ReturnCode}" | tee -a ${LOGFILE}
        if [[ ${ReturnCode} -ne 0 ]]; then
          ## There was an error in resize2fs.
          return ${ReturnCode}
        fi
      else
        ## There is not enough room in the LV to increase space in the FS.
        return 50
      fi
      return 0
    }
    
    #######################################
    ##           MAIN PROGRAM            ##
    #######################################
    
    if [ -f ${LOCKFILE} ]; then
      # Lock file detected.  Abort script.
      echo "Check space script aborted"
      echo "This script tried to run but detected the lock file: ${LOCKFILE}"
      echo "Please check to make sure the file does not remain when check space is not actually running."
      f_sendmail "ERROR: check storage script aborted" "This script tried to run but detected the lock file: ${LOCKFILE}\n\nPlease check to make sure the file does not remain when check space is not actually running.\n\nIf you find that the script is not running/hung, you can remove it by typing 'rm ${LOCKFILE}'"
      ErrorFlag=4
      f_cleanup
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` ${SCRIPTNAME}" > ${LOCKFILE}
    fi
    
    ## Requirement Check: Script must run as root user.
    if [ "$(id -u)" != "0" ]; then
      ## FATAL ERROR DETECTED: Document problem and terminate script.
      echo "ERROR: Root user required to run this script."
      echo ""
      ErrorFlag=32
      f_cleanup
    fi
    
    ## Check existance of required command-line parameters.
    case "$1" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSName=$1
        ;;
    esac
    case "$2" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSThreshold=$2
        ;;
    esac
    case "$3" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSIncreaseBy=$3
        ;;
    esac
    
    ## Check validity of File System name.
    case "${FSName}" in
      "root")
        FSVol="/dev/LVG/root"
        FSMap="/dev/mapper/LVG-root"
        ;;
      "home")
        FSVol="/dev/LVG/home"
        FSMap="/dev/mapper/LVG-home"
        ;;
      "tmp")
        FSVol="/dev/LVG/tmp"
        FSMap="/dev/mapper/LVG-tmp"
        ;;
      "usr")
        FSVol="/dev/LVG/usr"
        FSMap="/dev/mapper/LVG-usr"
        ;;
      "var")
        FSVol="/dev/LVG/var"
        FSMap="/dev/mapper/LVG-var"
        ;;
      "srv")
        FSVol="/dev/LVG/srv"
        FSMap="/dev/mapper/LVG-srv"
        ;;
      "opt")
        FSVol="/dev/LVG/opt"
        FSMap="/dev/mapper/LVG-opt"
        ;;
      "bak")
        FSVol="/dev/LVG/bak"
        FSMap="/dev/mapper/LVG-bak"
        ;;
      *)
        echo "ERROR: ${FSName} does not match a known file system defined in this script."
        f_showhelp
        ErrorFlag=2
        f_cleanup
        ;;
    esac
    
    ## Check validity of threshold value.
    test ${FSThreshold} -eq 0 1>/dev/null 2>&1
    if [[ $? -eq 2 ]]; then
      ## Threshold parameter is not an integer.
      echo "ERROR: ${FSThreshold} is not an integer."
      f_showhelp
      ErrorFlag=2
      f_cleanup
    fi
    
    ## Check validity of increment value.
    test ${FSIncreaseBy} -eq 0 1>/dev/null 2>&1
    if [[ $? -eq 2 ]]; then
      ## FSIncreaseBy parameter is not an integer.
      echo "ERROR: ${FSIncreaseBy} is not an integer."
      f_showhelp
      ErrorFlag=2
      f_cleanup
    fi
    
    ## Get available space for the file system.
    FSAvailable="`df --block-size=m ${FSMap} | awk '{ print $4 }' | tail -n 1 | sed 's/M//'`"
    
    ## Get the current size of the File System.
    FSSize="`df --block-size=m ${FSMap} | awk '{ print $2 }' | tail -n 1 | sed 's/M//'`"
    
    ## Get the current size of the Logical Volume for the File System
    LVSize="`lvs --noheadings --nosuffix --units=m ${FSMap} | awk '{ print $4}' | sed 's/[.].*//'`"
    
    ## Calculate the new size of the FS in case we need it.
    let NewFSSize=${FSSize}+${FSIncreaseBy}
    
    if [[ ${FSAvailable} -lt ${FSThreshold} ]]; then
      echo "`date +%Y-%m-%d_%H:%M:%S` - Starting expansion of ${FSVol}" | tee -a ${LOGFILE}
      echo "`date +%Y-%m-%d_%H:%M:%S` --- LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvail=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB" | tee -a ${LOGFILE}
      ## Run the auto-expansion function.
      f_auto-increment
      ReturnCode=$?
      case ${ReturnCode} in
      0)
        f_sendmail "NOTICE: File System Expanded" "${FSVol} was expanded because it was nearing max capacity.  Please review disk space usage and plan appropriately. LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB"
        ;;
      50)
        echo "`date +%Y-%m-%d_%H:%M:%S` - SEVERE: No room to expand ${FSVol}" | tee -a ${LOGFILE}
        ErrorFlag=16
        f_sendmail "SEVERE: No room to expand ${FSVol}" "There is not enough room in the Logical Volume to expand the ${FSVol} File System.  Immediate action is required.  Make sure there is free space in the Volume Group 'LVG' and then expand the Logical Volume...then expand the File System.\n\nLVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB.\n\nType 'vgs' to see if there is any free space in the Volume Group which can be given to the Logical Volume.\n\nType 'lvs' to see the current sizes of the LVs.\n\nType 'lvdisplay' to see a list of Logical Volumes so you can get the LV Name which is used in the lvextend and resize2fs commands.\n\nType 'lvextend -L+50M /dev/LVG/var' if you want to extend the var Logical Volume by 50 megabytes (assuming there is 50MB available in the Volume Group).\n\nType 'df --block-size=m' to see a list of file systems and their associated size and available space.\n\nType 'resize2fs /dev/LVG/var ${NewFSSize}M' to set the size of var to ${NewFSSize} megabytes. Make sure you set the size to the desired end-result which should be LARGER than the current FS size so you do not lose data."
        ;;
      *)
        echo "`date +%Y-%m-%d_%H:%M:%S` - ERROR: Expansion failure for ${FSVol}" | tee -a ${LOGFILE}
        ErrorFlag=8
        f_sendmail "ERROR: File System Expansion Failed" "${FSVol} Expansion failed with return code of ${ReturnCode}.  LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB"
        ;;
      esac
      echo "`date +%Y-%m-%d_%H:%M:%S` - Finished expansion of ${FSVol}" | tee -a ${LOGFILE}
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` - ${FSVol} ${FSAvailable}M>${FSThreshold}M No action required." | tee -a ${LOGFILE}
    fi
    
    ## Perform cleanup routine.
    f_cleanup
    Here is the typical output when it does not have to increase the FS:

    /var/log/check-storage.log
    Code:
    2012-05-01_01:00:00 - /dev/LVG/root 1377M>500M No action required.
    2012-05-01_01:15:00 - /dev/LVG/home 454M>100M No action required.
    2012-05-01_01:30:00 - /dev/LVG/tmp 776M>100M No action required.
    2012-05-01_01:45:00 - /dev/LVG/usr 1126M>100M No action required.
    2012-05-01_02:00:00 - /dev/LVG/var 1417M>100M No action required.
    2012-05-01_02:15:00 - /dev/LVG/srv 935M>100M No action required.
    2012-05-01_02:30:00 - /dev/LVG/opt 935M>100M No action required.
    2012-05-01_02:45:00 - /dev/LVG/bak 1871M>100M No action required.
    2012-05-02_01:00:00 - /dev/LVG/root 1377M>500M No action required.
    2012-05-02_01:15:00 - /dev/LVG/home 454M>100M No action required.
    2012-05-02_01:30:00 - /dev/LVG/tmp 776M>100M No action required.
    2012-05-02_01:45:00 - /dev/LVG/usr 1126M>100M No action required.
    2012-05-02_02:00:00 - /dev/LVG/var 1417M>100M No action required.
    2012-05-02_02:15:00 - /dev/LVG/srv 935M>100M No action required.
    2012-05-02_02:30:00 - /dev/LVG/opt 935M>100M No action required.
    2012-05-02_02:45:00 - /dev/LVG/bak 1871M>100M No action required.
    Here is a sample of what the log will look like when it performs increases:

    /var/log/check-storage.log
    Code:
    2012-05-02_01:30:00 - Starting expansion of /dev/LVG/tmp
    2012-05-02_01:30:00 --- LVSize=2048MB, FSSize=1004MB, FSAvail=93MB, FSThreshold=100MB, IncreaseBy=50MB
    2012-05-02_01:30:00 --- resize2fs /dev/LVG/temp 1054, ReturnCode=0
    2012-05-02_01:30:00 - Finished expansion of /dev/LVG/tmp
    2012-05-02_02:00:00 - Starting expansion of /dev/LVG/var
    2012-05-02_02:00:00 --- LVSize=3072MB, FSSize=1901MB, FSAvail=95MB, FSThreshold=100MB, IncreaseBy=50MB
    2012-05-02_02:00:00 --- resize2fs /dev/LVG/var 1951, ReturnCode=0
    2012-05-02_02:00:00 - Finished expansion of /dev/LVG/var
    2012-05-02_02:45:00 - Starting expansion of /dev/LVG/bak
    2012-05-02_02:45:00 --- LVSize=4096MB, FSSize=1996MB, FSAvail=91MB, FSThreshold=100MB, IncreaseBy=50MB
    2012-05-02_02:45:00 --- resize2fs /dev/LVG/bak 2044, ReturnCode=0
    2012-05-02_02:45:00 - Finished expansion of /dev/LVG/bak

  9. #9
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,123
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    This is good stuff, and I'm sure will be helpful to many users. Thank you for taking the time to write all of this down. If I may ask, is there a reason you're still using ESXi 4.1 instead of 5?

  10. #10
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    551
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to Install and Configure an Ubuntu Server 12.04 LTS

    APT Upgrade

    This script that can be scheduled to run daily to check for updates and then install them if available.

    The following is an example of a crontab entry to schedule the script to run once per day @ 3am.

    /var/scripts/data/crontab.root
    Code:
    0 3 * * * /var/scripts/prod/apt-upgrade.sh > /dev/null 2>&1
    /var/scripts/prod/apt-upgrade.sh
    Code:
    #!/bin/bash
    #############################################
    ## Name          : apt-upgrade.sh
    ## Version       : 1.0
    ## Date          : 2012-06-01
    ## Author        : LHammonds
    ## Purpose       : Keep system updated (rather than use unattended-upgrades)
    ## Compatibility : Verified on Ubuntu Server 12.04 LTS
    ## Requirements  : Sendemail, run as root
    ## Run Frequency : Recommend once per day.
    ## Parameters    : None
    ## Exit Codes    :
    ##    0 = Success
    ##    1 = ERROR: Lock file detected.
    ##    2 = ERROR: Not run as root user.
    ##    4 = ERROR: Aptitude update Error.
    ##    8 = ERROR: Aptitude safe-upgrade Error.
    ##   16 = ERROR: Aptitude autoclean Error.
    ################ CHANGE LOG #################
    ## DATE       WHO WHAT WAS CHANGED
    ## ---------- --- ----------------------------
    ## 2012-06-01 LTH Created script.
    #############################################
    
    ## Import standard variables and functions. ##
    source /var/scripts/common/standard.conf
    
    ## Define local variables.
    LOGFILE="${LOGDIR}/apt-upgrade.log"
    LOCKFILE="${TEMPDIR}/apt-upgrade.lock"
    ErrorFlag=0
    ReturnCode=0
    APTCMD="$(which aptitude)"
    
    #######################################
    ##            FUNCTIONS              ##
    #######################################
    
    function f_cleanup()
    {
      if [ -f ${LOCKFILE} ];then
        ## Remove lock file so subsequent jobs can run.
        rm ${LOCKFILE} 1>/dev/null 2>&1
      fi
      exit ${ErrorFlag}
    }
    
    #######################################
    ##           MAIN PROGRAM            ##
    #######################################
    
    if [ -f ${LOCKFILE} ]; then
      # Lock file detected.  Abort script.
      echo "** Script aborted **"
      echo "This script tried to run but detected the lock file: ${LOCKFILE}"
      echo "Please check to make sure the file does not remain when check space is not actually running."
      f_sendmail "ERROR: Script aborted" "This script tried to run but detected the lock file: ${LOCKFILE}\n\nPlease check to make sure the file does not remain when check space is not actually running.\n\nIf you find that the script is not running/hung, you can remove it by typing 'rm ${LOCKFILE}'"
      ErrorFlag=1
      f_cleanup
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` ${SCRIPTNAME}" > ${LOCKFILE}
    fi
    
    ## Requirement Check: Script must run as root user.
    if [ "$(id -u)" != "0" ]; then
      ## FATAL ERROR DETECTED: Document problem and terminate script.
      echo -e "ERROR: Root user required to run this script.\n"
      ErrorFlag=2
      f_cleanup
    fi
    
    echo "`date +%Y-%m-%d_%H:%M:%S` - Begin script." >> ${LOGFILE}
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Aptitude Update" >> ${LOGFILE}
    ${APTCMD} update > /dev/null 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorFlag=4
      f_cleanup
    fi
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Aptitude Safe-Upgrade" >> ${LOGFILE}
    echo "--------------------------------------------------" >> ${LOGFILE}
    ${APTCMD} safe-upgrade --assume-yes --target-release `lsb_release -cs`-security >> ${LOGFILE} 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorFlag=8
      f_cleanup
    fi
    echo "--------------------------------------------------" >> ${LOGFILE}
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Aptitude Autoclean" >> ${LOGFILE}
    echo "--------------------------------------------------" >> ${LOGFILE}
    ${APTCMD} autoclean >> ${LOGFILE} 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorFlag=16
      f_cleanup
    fi
    echo "--------------------------------------------------" >> ${LOGFILE}
    echo "`date +%Y-%m-%d_%H:%M:%S` - End script." >> ${LOGFILE}
    
    ## Perform cleanup routine.
    f_cleanup
    Here is the typical output:

    /var/log/apt-upgrade.log
    Code:
    2012-06-01_09:31:19 - Begin script.
    2012-06-01_09:31:19 --- Aptitude Update
    2012-06-01_09:32:01 --- Aptitude Safe-Upgrade
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    No packages will be installed, upgraded, or removed.
    0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    Need to get 0 B of archives. After unpacking 0 B will be used.
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    --------------------------------------------------
    2012-06-01_09:32:03 --- Aptitude Autoclean
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    Freed 0 B of disk space
    --------------------------------------------------
    2012-06-01_09:32:04 - End script.
    2012-06-02_03:00:01 - Begin script.
    2012-06-02_03:00:01 --- Aptitude Update
    2012-06-02_03:00:26 --- Aptitude Safe-Upgrade
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    The following packages will be upgraded:
      grub-common grub-pc grub-pc-bin grub2-common libcups2 libgcrypt11
    6 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    Need to get 3,611 kB of archives. After unpacking 59.4 kB will be freed.
    Writing extended state information...
    Get: 1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libgcrypt11 amd64 1.5.0-3ubuntu0.1 [280 kB]
    Get: 2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libcups2 amd64 1.5.3-0ubuntu1 [171 kB]
    Get: 3 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main grub-pc amd64 1.99-21ubuntu3.1 [140 kB]
    Get: 4 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main grub-pc-bin amd64 1.99-21ubuntu3.1 [861 kB]
    Get: 5 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main grub2-common amd64 1.99-21ubuntu3.1 [94.3 kB]
    Get: 6 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main grub-common amd64 1.99-21ubuntu3.1 [2,066 kB]
    Fetched 3,611 kB in 3s (941 kB/s)
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (This frontend requires a controlling tty.)
    debconf: falling back to frontend: Teletype
    dpkg-preconfigure: unable to re-open stdin:
    (Reading database ... 61584 files and directories currently installed.)
    Preparing to replace libgcrypt11 1.5.0-3 (using .../libgcrypt11_1.5.0-3ubuntu0.1_amd64.deb) ...
    Unpacking replacement libgcrypt11 ...
    Preparing to replace libcups2 1.5.2-9ubuntu1 (using .../libcups2_1.5.3-0ubuntu1_amd64.deb) ...
    Unpacking replacement libcups2 ...
    Preparing to replace grub-pc 1.99-21ubuntu3 (using .../grub-pc_1.99-21ubuntu3.1_amd64.deb) ...
    Unpacking replacement grub-pc ...
    Preparing to replace grub-pc-bin 1.99-21ubuntu3 (using .../grub-pc-bin_1.99-21ubuntu3.1_amd64.deb) ...
    Unpacking replacement grub-pc-bin ...
    Preparing to replace grub2-common 1.99-21ubuntu3 (using .../grub2-common_1.99-21ubuntu3.1_amd64.deb) ...
    Unpacking replacement grub2-common ...
    Preparing to replace grub-common 1.99-21ubuntu3 (using .../grub-common_1.99-21ubuntu3.1_amd64.deb) ...
    Unpacking replacement grub-common ...
    Processing triggers for man-db ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (This frontend requires a controlling tty.)
    debconf: falling back to frontend: Teletype
    Processing triggers for install-info ...
    Processing triggers for ureadahead ...
    Setting up libgcrypt11 (1.5.0-3ubuntu0.1) ...
    Setting up libcups2 (1.5.3-0ubuntu1) ...
    Setting up grub-common (1.99-21ubuntu3.1) ...
    Installing new version of config file /etc/grub.d/10_linux ...
    Setting up grub2-common (1.99-21ubuntu3.1) ...
    Setting up grub-pc-bin (1.99-21ubuntu3.1) ...
    Setting up grub-pc (1.99-21ubuntu3.1) ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (This frontend requires a controlling tty.)
    debconf: falling back to frontend: Teletype
    Installation finished. No error reported.
    Generating grub.cfg ...
    Found linux image: /boot/vmlinuz-3.2.0-24-generic
    Found initrd image: /boot/initrd.img-3.2.0-24-generic
    Found linux image: /boot/vmlinuz-3.2.0-23-generic
    Found initrd image: /boot/initrd.img-3.2.0-23-generic
    Found memtest86+ image: /memtest86+.bin
    done
    Processing triggers for libc-bin ...
    ldconfig deferred processing now taking place
    ldconfig deferred processing now taking place
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    --------------------------------------------------
    2012-06-02_03:00:43 --- Aptitude Autoclean
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    Freed 0 B of disk space
    --------------------------------------------------
    2012-06-02_03:00:44 - End script.
    Last edited by LHammonds; June 26th, 2012 at 08:24 PM.

Page 1 of 4 123 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •