Tag Archives: Ubuntu

Getting Started with Docker

Docker logo horizontal spacing

Docker Allows you to run tiny containers inside your linux machine . These containers can be compared to Virtual Machines, but there are some differences that makes them easy and portable. In a user perspective, they are damn fast to start (and kill) compared to VMs and also very portable. I am trying to describe how to install and run containers with Docker on a ubuntu 14 ( trusty) machine.

Installation

Installation is fairly easy with the follwing command. It will ask your sudo password when needed.

wget -qO- https://get.docker.com/ | sh

It adds a apt repo and does the installation of the latest docker version on your machine. Verify the installation by running ‘docker -v’ command. It will show you the version of docker installed.

Pull and Run

Now, we need to pull a basic container and run it to see the magic.

$docker pull ubuntu:14.04
14.04: Pulling from ubuntu
e9e06b06e14c: Extracting [=======================> ] 62.95 MB/65.77 MB
a82efea989f9: Download complete 
37bea4ee0c81: Download complete 
......
$docker run -ti ubuntu:14.04 /bin/bash
root@c419ad172b0f:/#

What has happened just now is that you have downloaded the latest docker ubuntu 14.04 image from the docker registry and ran it. The ‘root@c419ad172b0f#’ prompt you see is the container running the bash shell. You can now work on it as you would in any other normal ubuntu machine, when you exit the shell, it would stop the container as well.  Enjoy !

Maintenance

Everytime you exit a container, it does not actually delete it. It is left in the filesystem so that you can restart it if needed. Let’s take a look at how we can see the images we pulled, and see the containers we started and also how to work with them.

$docker images
REPOSITORY                                           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu                                               14.04               07f8e8c5e660        2 weeks ago         188.3 MB

As you can see, it lists all images you have downloaded from internet. To remove a image , run ‘docker rmi ubuntu:14.04’

$docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c419ad172b0f ubuntu:14.04 "/bin/bash" 24 minutes ago Exited (0) 2 minutes ago hopeful_thing

This is the container that just got stopped in the previous step. Notice the CONTAINER_ID c419ad172b0f is the same as the hostname of the container we had when we ran the first container. Each time you start a container , it creates a unique ID . You can start a stopped container and attach shell to it using the commands below.

$docker start c419ad172b0f
c419ad172b0f
$docker attach c419ad172b0f
root@c419ad172b0f:/# echo Hello
Hello
root@c419ad172b0f:/# exit
exit
$

Now let’s take a look at how to remove a container.

$docker rm c419ad172b0f

Customized Images

You can also create customized images for your use. For example, I want to have a image that includes ‘screen’ package on top of the basic ubuntu image.  It is easy to prepare a ‘Dockerfile’ and let docker create (build) a new image for you. Create a file named ‘Dockerfile’ inside a empty folder. Content is given below.

FROM ubuntu:14.04
MAINTAINER ksraju007@gmail.com

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update ; apt-get -y install screen ;
CMD "/bin/bash"

Now build the image. Notice that we are giving it a new name called u14screen using the -t option.

docker build -t u14screen --rm .
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu:14.04 
 ---> 07f8e8c5e660
Step 1 : MAINTAINER ksraju007@gmail.com
 ---> Using cache
 ---> 52fe481915f0
Step 2 : ENV DEBIAN_FRONTEND noninteractive
 ---> Running in 7d802e182f91
 ---> ffd0cd910a16
Removing intermediate container 7d802e182f91
Step 3 : RUN apt-get update ; apt-get -y install screen ;
 ---> Running in 6574afc3a441
....
Processing triggers for ureadahead (0.100.0-16) ...
 ---> 76433af5559b
Removing intermediate container 6574afc3a441
Step 4 : CMD "/bin/bash"
 ---> Running in 8933a2b86e12
 ---> ce468a62539a
Removing intermediate container 8933a2b86e12
Successfully built ce468a62539a
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
u14screen latest ce468a62539a About a minute ago 210.9 MB

Hurray ! You have just built your own docker image. Try running it.

$docker run -ti u14screen
root@95d2c547e113:/# screen -v
Screen version 4.01.00devel (GNU) 2-May-06
root@95d2c547e113:/# exit
exit
$

Since we have mentioned the CMD parameter in Dockerfile to start /bin/bash automatically, you do not need to specify that anymore during ‘docker run’ for your image. For more information about advanced docker options and Dockerfile parameters, see https://docs.docker.com/

The best thing about having Dockerfile is that now you can send the Dockerfile to your friends and they can build exactly the same image on their computer too. This makes it extremely easy to replicate work environments across people, not to mention that you are not copying lots of data too.. it is a simple text file.

Enjoy your docker experiments !  🙂

Setting up Bugzilla in Ubuntu 14.04 ( trusty )

buggie
Setting up Bugzilla is fairly easy . This blog post is specific to Ubuntu 14.04  ( though it might work with older versions too )

In order to get Bugzilla up and running in Ubuntu 14.04, we are going to install Apache webserver ( SSL enabled ) , MySQL database server and also some tools that are required to  install and configure Bugzilla.

Login to the machine as a user that can do “sudo” commands. Here is the command you need to install required packages.
sudo apt-get install apache2 mysql-server libapache2-mod-perl2
libapache2-mod-perl2-dev libapache2-mod-perl2-doc perl postfix make gcc g++

Answer the questions asked by MySQL and postfix .

Setting up MySQL

Login with root access to MySQL and create a DB for Bugzilla. Change “secret_password” to anything you want. You will need it later when configuring Bugzilla too.


mysql -u root -p
password:
mysql > create database bugs;
mysql > GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, LOCK TABLES, CREATE TEMPORARY TABLES, DROP, REFERENCES ON bugs.* TO bugs@localhost IDENTIFIED BY ‘secret_password’;
mysql > flush privileges ;
mysql > quit

Setting up Apache

Now , we need to enable CGI and SSL for Apache. Since this is a in-house project, we are ok with a self-signed certificate.
sudo mkdir /etc/apache2/ssl
sudo a2enmod ssl
sudo a2enmod cgi
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

The last command will ask you to enter a few information about the country and email address etc. Now we have the certificate in /etc/apache2/ssl/apache.crt and the Key file in /etc/apache2/ssl/apache.key . Modify the /etc/apache2/sites-available/default-ssl.conf to properly mark these files.
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

Now to make the SSL site run, sudo a2ensite default-ssl.conf” Restart apache to make the changes effective. You can already test it with your browser pointing to https://your_server_ip/ .

Setting up Bugzilla – Stage 1

Download and extract the latest tar file from the internet. As of this writing , latest stable version is 4.4.5.
cd /var/www/html
sudo wget http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-4.4.5.tar.gz
sudo tar zxvf bugzilla-4.4.5.tar.gz
sudo mv bugzilla-4.4.5 bugzilla

Now we have Bugzilla extracted, let’s use a script provided by the developers to do further configurations.
cd /var/www/html/bugzilla
sudo ./checksetup.pl --check-modules

This will tell you most probably , there are lot of perl modules missing. Do not worry, you can install all of them with the below command.

cd /var/www/html/bugzilla
sudo perl install-module.pl --all

This will take some time to download and install all dependancies. Run the checksetup.pl –check-modules command again to verify there are nothing left.

Next step, run the checksetup.pl command without –check-modules option. This will generate a file called “localconfig” in the /var/www/html/bugzilla directory. Edit that file and include the following minimum things.

$webservergroup = 'www-data'
$db_pass = 'secret_password'

We will also create a local user account to run Bugzilla.

sudo useradd -d /home/bugs -m bugs
sudo passwd bugs

Now , run the sudo checksetup.pl again. It will connect to DB and also install proper files and permissions. If everything goes fine, it will ask for a Administrator user email and password. This is what you will use to setup more details in Bugzilla later.

Configure Apache to properly understand and execute scripts in Bugzilla , by adding the following to /etc/apache2/apache2.conf file.

<Directory "/var/www/html/bugzilla">
AddHandler cgi-script cgi
DirectoryIndex index.cgi
Options +Indexes +ExecCGI -MultiViews +SymLinksIfOwnerMatch +FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

Now, restart apache ( sudo service apache2 restart ) and connect to https://server_ip/bugzilla .

Setting up Bugzilla – Stage 2

After you have successfully completed stage 1, you can now login to Bugzilla using the Administrator email and password you mentioned while running checksetup.pl.

You will be greeted with a special configuration page. You will need to go to parameters and set at least urlbase  as http://server_ip/bugzilla/ and cookie_path as /bugzilla/ . Also there is possibility to force SSL connections in that same page.

Now you need to got to “Administration” and configure Product, milestones, users, authentication, preferences etc. There are so many things you can configure from the “Administration” link , that is beyond the scope of this blog post. More information can be found here : http://www.bugzilla.org/docs/

Enjoy your very own Bugzilla !

 

Adobe Reader on Ubuntu 13.10 (Saucy Salamander) 64 Bit

I will try to keep this short and simple. Adobe reader is needed only if you need to do forms and such advanced things in PDF files. Otherwise, Ubuntu comes with default tools such as evince to do all kind of usual reading of PDF files. If your system is a very old one, you can even try installing xpdf package.

That being said, let’s go ahead and install Adobe reader. First, download the .bin file from adobe website : http://get.adobe.com/reader/ . Once the file is downloaded, issue the following commands to install it.

Inside a terminal :

chmod a+x acro...bin
./acro...bin

and follow on-screen instructions.

If you are running a 64 Bit version of Ubuntu, you might need to install a few 32 bit libraries to get it working. Specially if you are facing errors like : “acroread: error while loading shared libraries: libgdk_pixbuf_xlib-2.0.so.0: cannot open shared object file: No such file or directory

sudo aptitude install libgdk-pixbuf2.0-0:i386
sudo aptitude install libgtk2.0-0:i386

Adobe Reader should work fine now. Enjoy 🙂

SNMP Monitoring using Nagios

Nagios is very good and commonly used monitoring tool for systems and network equipments. It can monitor and report availability statistics as well as provide alerts in case of host or service incidents. I am going to discuss on how to use the SNMP capabilities of Nagios and GNU/Linux to enable monitoring without special agents installed on the hosts.

Usually, Nagios will need you to install NRPE addons to report disk space and so many other updates about the system that need to be monitored. This needs you to install additional software on the target machines which is not always possible/recommended practice. Instead, we are going to use the SNMP software that comes as part of the GNU/Linux OS to provide information for Nagios. I am not going to brief about how to install Nagios and Plugins. You could read that in a beautiful how-to here : http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html

There are two steps in enabling SNMP Monitoring.

Configure SNMP in the host to be monitored.

  • Edit /etc/snmp/snmpd.conf and add one line. ( rocommunity public )
  • Restart snmpd service ( sudo /etc/init.d/snmpd restart )

Configure Nagios to check free RAM in the host via SNMP .
First, add a host entry like this to your .cfg file.

define host {
use linux-server
host_name linuxserver01
alias MyLinuxServer
address 192.168.1.24
}

Now we will add a service to check free RAM

define service{
use generic-service
host_name linuxserver01
service_description Free RAM
check_command snmp_freeram_linux
}

Next, we will define the snmp_freeram_linux command to use snmp_check plugin that comes as part of Nagios Plugins installation.

define command{
command_name  snmp_freeram_linux
command_line /usr/local/nagios/libexec/check_snmp -H $HOSTNAME$ -C public -o .1.3.6.1.4.1.2021.4.11.0
}

After this, restart Nagios. ( sudo /etc/init.d/nagios restart )

You should be now able to see a new service added to host and SNMP getting the data. With some efforts, you would be able to configure SNMP for other operating systems and network equipments too. If you have queries, please let me know. 🙂

Making Ubuntu Better !

Here’s a few things I do just after installing Ubuntu Linux. While this step is not mandatory, it sure makes a lot of good additions to the experience. With these few simple commands, your new Ubuntu system will get lot of additional things that is going to make it feature packed, shinier and a pleasure to use.

Before we start
Having a internet connection is necessary to do these tricks. Before we start, update your system by running the following commands one by one.

sudo apt-get update 
sudo apt-get upgrade

Multimedia
Adding VLC Player, Lots of different codecs for playing variety of Media formats like MP3, MP4 etc is so easy. This command will also install some of the fonts used commonly in Microsoft Office Documents for compatibility. avidemux is a simple but capable Video Editor.

sudo apt-get install vlc ubuntu-restricted-extras avidemux

Graphics Applications
Scribus is a Desktop Publishing Software. InkScape is a Vector Graphics application just like Corel Draw. Gimp could compete well with Photoshop.

sudo apt-get install gimp scribus inkscape

Windows Programs
You want to run Windows Programs in Ubuntu ? Sure. Let’s install Wine. After installing wine, you could just double click any .exe files just like you did earlier to run them. You could even install Windows Software packages on Ubuntu. They will appear under Applications -> Wine -> Programs Menu after installation.

sudo apt-get install wine

Sun Java Support
If any of your programs are not running because Sun Java is not installed or the OpenJDK is not able to run them, install Sun Java.

sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

Skype, Acrobat Reader, Flash and lot more..
You want to customize it further and add lots of more softwares like Skype, Acrobat Reader, Google Chrome and much more ? Install Ubuntu Tweak. Download the package and double click on the file to install. Once installed, this tool appears under the Applications menu. There are a huge number of things you could do with this very handy application. For example, if you dont like the “close” button on the left side of your windows, this tool will help you to change it back to the right corner..

For GUI Lovers
All the above apt-get commands can be done via GUI using applications -> software center. Just search for the package name and click install. Like I always say, it’s all about choice. 🙂

Side Note : Some of these commands actually makes you install non-open-source applications or libraries to your system. You have been warned. 🙂