Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Monday, March 20, 2017

Ensure EC2 auto-recovery by rebuilding AMI with Packer

Problem: Amazon EC2 auto recovery fails if machine image has ephemeral block device mappings defined (even when no instance store volumes are attached).

Solutions:
  1. Specify custom block device mapping during instance launch.
  2. Rebuild Ubuntu AMI (with automation).
This post shows how to achieve the later using Packer by HashiCorp.

Saturday, October 16, 2010

Reduce number of virtual terminals (TTYs) in Lucid

CLI

Most Linux distributions come with several (usually six) virtual consoles enabled by default. Think of it as having six terminal windows you can flip through using (CTRL)+ALT+F[1-6] keys. Sometimes you don't need or want to have that many TTYs. Let's say you have very little RAM, or want to shave a fraction of a second from your boot time, or simply want to strip all that isn't necessary from your installation. Here's how you do it in Ubuntu 10.04 Lucid Lynx.

Let's say you want to leave only two virtual consoles, tty1 and tty2. simply go to /etc/init/ directory and delete, or better yet move to safe location, files tty3.conf, tty4.conf, tty5.conf and tty6.conf

$ cd /etc/init/
$ sudo rm tty[3-6].conf

Next time you boot, only first two TTYs will be present. Note, that this will also shift your X session to where tty3 would normally be, so you can access it by typing ALT+F3 instead of ALT+F7.

Tuesday, October 5, 2010

Read a random line of text from file in Linux

CLI

There are many ways to achieve this, but this is probably the simplest since you most likely already have all the necessary components installed.

On Ubuntu it's the "shuf" command from "coreutils" package. It's original purpose is to shuffle the lines passed to it, or as its description says: "write a random permutation of the input lines to standard output". However, with one of the arguments you can limit the number of lines it returns, so if all you need is a single line from a given text file, juts run:

$ shuf –n 1 list.txt

where argument –n tells shuf to print only one random line from file list.txt

Thursday, September 30, 2010

Auto login Ubuntu user from CLI

CLI

There are a lot of recipes out there on how to automatically login into a given Linux user's account on start up, but most of them rely on some sort of graphical environment or display manager to be present. It took me quite a bit of digging to find a way to auto login in Ubuntu with nothing but CLI. I'm sure others will find this tip useful.

To auto login user "bob" on first console terminal (tty1) edit file /etc/init/tty1.conf and replace last line:

exec /sbin/getty -8 38400 tty1

with this:

exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1

and Robert's your father's brother, next time you boot your machine bob will automatically log into his account on tty1.

Tuesday, September 28, 2010

Automatically update Transmission's block list


My favourite BitTorrent client Transmission supports bluetack-formatted blocklists. In computing, a blacklist or block list is a basic access control mechanism that allows everyone access, except for the members of the black list (i.e. list of denied accesses). Transmission utilizes a blocklist of known anti-P2P IPs, to prevent them from connecting and possibly interfering with transfers.
When you press the "Update Blocklist" button in the Transmission GUI, a new copy of blocklist is downloaded from a Transmission mirror that's updated twice daily. Since transmission-daemon on my headless server does not have such button I have to download the blocklist by hand, uncompress it, and place the uncompressed file in the daemon's blocklists folder.
Here's how to do it manually:

Wednesday, September 22, 2010

Convert .png to .gd2 for Nagios status map

nagios-150x150

If you ever tried to make Nagios web interface look a little nicer by adding some custom host or service icons, you have probably came across collections of icon packs at Nagios Exchange. You have also noticed an unusual .gd2 extension on some of the images and realized that without this format icons don't display properly on Status Map. I was doing exactly that the other day and couldn't find the icons I needed, so I ended up creating some myself. Here's how to convert a PNG image into .gd2 (GD Graphics Library format).

On Ubuntu install libgd-tools package, it will contain a pngtogd2 app. To convert file.png to file.gd2 use:

$ pngtogd2 file.png file.gd2 0 1

Once you have your .png or .gif and .gd2 images, I tend to use 40x40x8bit images with transparent background, place them in your /usr/local/nagios/share/images/logos/ directory (if you installed Nagios from source) and add these properties to your host or service definition:

define host{
        ...
        icon_image              ubuntu.png
        statusmap_image         ubuntu.gd2
        ...
        }

Monday, August 9, 2010

Enabling apache_* Munin plug-ins in Ubuntu

munin-apache-150

There are three Munin plug-ins for Apache monitoring bundled with Ubuntu's munin-node package:

  • apache_accesses - monitors the number of accesses to Apache servers
  • apache_processes - monitors the number of apache-processes running on the machine, and (in addition to a simple process count), separate then into "busy" or "idle" servers
  • apache_volume - monitors the volume of data sent from Apache servers

First of all, make sure that the libwww-perl package is installed on your system, or you might notice an error like this when you're executing these plug-ins directly from /usr/share/munin/plugins:

Can't locate object method "new" via package "LWP::UserAgent" at ./apache_volume line 127

In addition, apache_accesses and apache_volume require ExtendedStatus support to be enabled as well as mod_status module.

Status module can be enabled by running:

$ sudo a2enmod status
$ sudo /etc/init.d/apache2 restart

To enable ExtendedStatus support create a /etc/apache2/conf.d/extendedstatus file containing the following directives:

<IfModule mod_status.c>
   ExtendedStatus On
</IfModule>

Now create symbolic links to plug-ins in /etc/munin/plugins directory:

$ cd /etc/munin/plugins
$ sudo ln -s /usr/share/munin/plugins/apache_accesses
$ sudo ln -s /usr/share/munin/plugins/apache_processes
$ sudo ln -s /usr/share/munin/plugins/apache_volume

Reload Apache and restart munin-node:

$ sudo /etc/init.d/apache2 reload
$ sudo /etc/init.d/munin-node restart

Friday, July 9, 2010

BitTorrent and zsync FTW

My current favourite (and it seems almost everyone else's) Linux distro is Ubuntu. I use it on my home server, on virtual machines at work, I even carry it on my USB stick. I find that the easiest, and probably the fastest, way to download Ubuntu is via BitTorrent. Using BitTorrent to download Open Source software is also a nice way to show your appreciation - you reduce project's bandwidth costs and help creators to distribute their product. This is especially true during the stable release time, when everyone rushes to get the latest release and direct downloads slow down to a crawl. This is the perfect time to use P2P, since hundreds of people already have the file you want and are willing to share it with you.

BitTorrent is not a silver bullet, however. It's only good when the file you want is a popular one. For example here's a some tracker stats for two Ubuntu releases, 10.04 is a stable release from a couple months back and maverick is the latest alpha:

File Seeders Leechers
ubuntu-10.04-dvd-i386.iso 1391 123
ubuntu-10.04-server-i386.iso 968 20
maverick-dvd-i386.iso 8 5
maverick-server-i386.iso 10 0

Not a lot of people care about the alpha release, so there are very few seeders and leechers. Since number of peers is low, P2P download will be slow and you might be better off just downloading the file directly. In Ubuntu's case there is a better solution - zsync.

Friday, March 26, 2010

Disable power button on Ubuntu server

Power button

My little daughter loves to press buttons. Some of her favourite toys are my spare mouse and keyboard. I think she's going to be a computer geek, like her daddy. Unfortunately, my small headless Ubuntu server (and its glowing green power button) is also within her reach. Couple times during this week I've received a message from Monit that it was going down, a rare event, unless your kid just shutdown your entire server, again…

Fortunately, this problem is quite easy to fix. On Ubuntu and other Debians all you have to do is edit /etc/acpi/powerbtn.sh script (part of the acpid package) and comment out one line, like so:

#/sbin/shutdown -h now "Power button pressed"

This would prevent the triggered ACPI power button event from calling  shutdown command.

Sunday, March 21, 2010

Creating video DVD iso file using Linux CLI

dvd-150

Recently I had to create a video DVD iso image from a bunch .VOB files using Linux command line. I found this extensive tutorial on both how to create and burn an image file using command line. Here is a quick summary.

First, create VIDEO_TS and AUDIO_TS folders, if you don't already have them. Apparently some DVD players will not play a DVD if it doesn't have this particular directory structure.

In my case I had just .VOB, .IFO and .BUP files with no directory structure, so I copied all files to VIDEO_TS folder and left AUDIO_TS empty.

To create ISO I used a mkisofs command like so:

$ mkisofs -dvd-video -o mydvd.iso -udf /path/to/filedir/

Where "mydvd.iso" is the name of my future ISO file and "/path/to/filedir/" is the directory containing my VIDEO_TS and AUDIO_TS folders.

Just a little while later my ISO image file was ready. Just in case I checked to make sure that VIDEO_TS.IFO file had the lowest sector number like so:

$ isoinfo -i mydvd.iso -l

Now burn!

Wednesday, February 3, 2010

Transmission now supports magnet links

My choice BitTorrent client for headless Linux NAS server - Transmission has recently got a nice feature upgrade. Transmission already had most features you want from a BitTorrent client: encryption, a web interface, peer exchange, DHT, UPnP and NAT-PMP port forwarding, web seed support, watch directories, tracker editing, global and per-torrent speed limits, and more. Now it finally supports magnet links, and for users switching from Mac desktop client - the dearly missed "turtle mode" in Web UI!

Wednesday, September 23, 2009

Installing multi-site Drupal from CVS using Drush

These are my prettified notes on installing multi-site Drupal setup, using swiss army knife for all things Drupal - drush (DRUpal SHell) on Ubuntu 9.04 (Jaunty). This post will cover quick LAMP, CVS and phpMyAdmin installation and then show how easy it is to get latest stable Drupal, plus over a dozen of modules, up and running with drush. If you care, just follow along.

Wednesday, September 9, 2009

Transmission on headless Ubuntu 9.04 (Part 1)

In my earlier post I have compared several BitTorrent clients for Linux and decided that Transmission was the best option for me.

In this series of posts I'll try to document installation and configuration of Transmission on my headless Ubuntu 9.04 NAS.

Installation

Transmission is already included in Ubuntu repository, in fact it's the default BT client for this distro, unfortunately the version in Jaunty (1.61) is a bit old and lacks a few useful new features such as DHT. Luckily, there was an up to date package (1.74) at Launchpad, and that's what I'm going to use.

Saturday, August 8, 2009

Apt-mirror vs. apt-cacher-ng

After playing around with apt-mirror and some more research I decided to replace it with apt-cacher-ng.

Problems with apt-mirror:
  • It uses up a lot of space, most of it for packages we will never use
  • It needs just as much space for every additional architecture or release of Ubuntu/Debian
  • Because we don't use majority of the packages apt-mirror downloads, more bandwidth is wasted than necessary
  • It is necessary to modify apt's sources file to force clients to use apt-mirror, this becomes more difficult when some clients use different repositories
  • Requires installation of a separate web server
Alternative solution is to use a special caching proxy that will fetch packages that we actually use and cache them for future requests.

Benefits of apt-cacher-ng:
  • It uses fraction of the space, especially since cache is automatically cleansed of old packages that are no longer requested
  • It downloads each package only once, thus reducing bandwidth consumption
  • It reduces download time for all but the first request (Gigabit LAN speeds, baby)
  • Makes it easier to configure clients: instead of changing repository URLs we only change the address of the proxy
  • Single package install, no additional web server needed
  • Minimal server side configuration, in fact almost zero configuration in our case

Thursday, August 6, 2009

Setting up apt-mirror behind http proxy

Had a bit of brain teaser at work today. I was setting up a mirror for Ubuntu package repository, to reduce bandwidth usage and package download time for our hundred+ virtual machines. We mostly use Ubuntu 8.04 (Hardy) and almost exclusively 32bit.

This seemed like a pretty simple exercise:
  1. Install apt-mirror package
  2. Specify which repositories should be mirrored
  3. Download content from repositories (the long step)
  4. Serve mirrored directory via Apache or Lighttpd
  5. Tell all VMs to use local repository