Thursday, September 24, 2015

Configure sysstat on Antergos Linux

Installation

Install sysstat

pacman -S sysstat

Install a cron implementation

pacman -S cronie


Configuration

Configure crontab

Run crontab -e to open the crontab editor, and enter the following to setup automatic sysstat collection:

# Run system activity accounting tool every 10 minutes
*/10 * * * * /usr/lib/sa/sa1 1 1
# Generate a daily summary of process accounting at 23:53
53 23 * * * /usr/lib/sa/sa2 -A

Save and exit the crontab editor.

Configure cronie.service

touch /etc/crontab
systemctl enable cronie.service
systemctl start cronie.service

Verification

To check that historic syststat collection is working run:
ls -l /var/log/sa
and verify that a new file is created with the name san, where n is the numeric representation of the current day of the month. For instance, if you did this on September 24th, the file would be called /var/log/sa/sa24. Please note that it could take up to 10 minutes for this file to be created.

Troubleshooting

If the /var/log/sa directory is still empty, it is probably something wrong with the crontab or the cronie.service.

Check cronie.service

systemctl status cronie.service -l

Check system journal

journalctl -xn

Wednesday, September 23, 2015

The story of my journey to Linux

The journey

While I have been working on both Windows, UNIX and Linux since 1997, it was only a few years ago that I started using Linux as my primary operating system at home.

During my professional career I have worked on both HP Compaq Tru64, IBM AIX, HP/UX, Sun Solaris (both Sparc and Intel), SuSE Linux, Red Hat Enterprise Linux, CentOS and Oracle Linux.

My first encounter with computers was when a few of my friends got an Amiga 500 in the late 80'es. About the same time I got a Commodore 64, and while these machines were mainly used for gaming, it was also my first encounter with programming. In BASIC.

Around 1990 my father purchased an Atari 1040ST, which is used to create music. He also owned a PC AT where I learned word processing. 

In 1993 I took a few classes at an engineering college, where one of the perks was your own personal shell account. I do not know which version of UNIX it was, and I mainly used it for email and accessing Bulletin Board Systems. Either the same year, or the year after, I bought my first PC. It was an Olivetti with Windows 3.1. I do not recall what happened to it, but I did not have it for a long time. 

In 1996 I got a shell account at the university, and as far as I can remember they were running Sun Solaris. The same year I bought my second PC, which was assembled by a PC builder hobbyist. It came with a boot virus, so I got a crash course in the format and fdisk commands before I finally got the problem solved and Windows 95 reinstalled. This ordeal made me look for other options, and during the next few weeks I obtained copies of both OS/2 and Red Hat Linux. The former was never able to run stable on my machine, but the latter had potential as I was already used to working in the shell. In the end though, I installed Windows 95 yet again.

Since the late 90'es I have been using the Internet regularly. At first it was through a modem 28.8 kbps and then through ISDN 64 kbps or bundled up to 128 kbps. Finally around 2002-2003 I got a DSL connection, and then it occurred to me that I could host a server at home. At that time I always had a few spare computers, so I bought a bundle with SuSE Linux and written documentation. While SuSE worked fine, I was more comfortable with Red Hat, because most my professional encounters with Linux was with Red Hat Linux. In 2003, Red Hat had discontinued their free Red Hat Linux distribution, and only offered a paid option. Instead they started the Fedora Core project based on the source code from Red Hat Linux 9.

For the next 5 years I was running Fedora Linux on my home server(s), while keeping Windows on the desktop. The only reason I kept Windows was because I enjoyed playing a few computer games that only would run on Windows. 

In 2008 I did not longer have time to manage home servers, and I had also begun taking an interest in OS X. First I bought a cheap Mac Mini to check if OS X was anything for me. I really liked it, so I bought a iMac to replace my aging desktop PC. Later the same year I also bought a Macbook Pro. 

Between 2009 and 2011 I was using Windows on my gaming computer and OS X for surfing, programming and word processing. 

By 2012 I was no longer playing computer games, and I had given away my gaming computer to a friend of the family. The aging Macbook Pro was still catering for my surfing and word processing needs, and since I was quite satisfied with OS X, I saw no reason so use Linux at home during these years.

In 2014 my Macbook Pro was now 6 years old, and beginning to feel slow. The question was if I should buy a new Macbook Pro, or get a cheaper PC and install Fedora Linux on it. Having a PC with Windows 8 was no option for me. I do have a few gadgets, mainly HR watches, which only have drivers and software for Windows and OS X. In the end I decided to buy a Lenovo Thinkpad E540. I installed Windows XP in VirtualBox to cater for my gadgets.

I have always been a huge fan of the Red Hat family of Linux distributions. For many years I have enjoyed using Fedora because it is a leading edge, while still managing to be quite stable. As I have grown older and have gotten less time to spend in front of the computer, I wished I did not have to upgrade my Fedora installation twice a year, or do a reinstall. So I started looking for options. I know quite a few people that uses Linux Mint, and they are very happy with it, since both Cinnamon, XFCE and KDE uses "classic" menus similar to the Start button menu in Windows. As Gnome3 user I found Ubuntu 14.04 LTS with Unity more welcoming. I also ran into several technical issues with Linux Mint which I never had with neither Fedora or Ubuntu. Wifi instability being the major issue. 

I have been very satisfied with Ubuntu 14.04 LTS. It has been very stable without any technical issues at all. Pretty much all  the software I have needed have been available in the official repositories, including audio and video playback support. I can recommend Ubuntu to others. It just works. At least on my hardware :)

It was more a philosophical issue that I kept looking for an alternative. I wanted to use a distro that "just works", was community driven, active development, was leading edge but without a need to reinstall, and that had Gnome3 as an official desktop environment. Manjaro seemed like an obvious choice. While Gnome3 was not an official DE, it could either be installed as a community edition, through the repositories in the offical editions. Manjoro is a really beautiful and polished distro, and I would have chosen it, if it hadn't been that I discovered Antergos.

Antergos Linux is a rolling release distro based on Arch. It is leading edge, and supports several of the leading desktop environments including Gnome3. It also looks great as it is using Numix icons. I installed it, and instantly fell in love. I had several technical issues with the LightDM display manager, in particular when awakening from hibernate. I believe this issue was caused by my hardware, so after failing to get LightDM to work properly, I simply disabled and uninstalled LightDM and installed and enabled GDM instead.

I am now caught between Antergos Linux and Fedora. Antergos Linux has it's lightweight and rolling appeal, but Fedora is part of the Red Hat family that I love so much. Linux offers great diversity, and I embrase it.

Wednesday, August 12, 2015

Customize Docker storage

I have been playing around with Docker lately. It is a very interesting piece of technology, which let you build relatively small and lightweight containers with a complete server environment with its own file system. Instead of running as a virtualized platform, it runs on top of your host operating systems kernel. You can pull some pre-made images from the public Docker repository, and customize them to your likings.

When learning how to use Docker, I have used CentOS 7 running in VirtualBox 5 as the host operating system. During my first tries with Docker, I often found various parts of my disks running out of space. Either the / partition or the Docker specific LVM logical volume docker-pool ran out of space. This is because Docker by default will store it's metadata and temporary data in /var/lib/docker on the root partition, and store the Docker images in the docker-pool logical volume.

When playing with Docker now, I always start out with adding new storage before installing and starting Docker.

Disclaimer

Some of the commands in this article can be destructive to your system if running on the wrong disk device. Don't run any of the commands unless you know exactly what the command will do to your system.

Adding a new disk device

Through the VirtualBox console I have added a new 100G VDI file to contain my new disk device. After starting CentOS 7 up, I can find this disk by running the lvmdiskscan command:
[root@localhost ~]# lvmdiskscan
  /dev/centos/root [       9,78 GiB]
  /dev/sda1        [     500,00 MiB]
  /dev/centos/swap [       1,20 GiB]
  /dev/sda2        [      11,51 GiB] LVM physical volume
  /dev/sdb         [     100,00 GiB]
  3 disks
  1 partition
  0 LVM physical volume whole disks
  1 LVM physical volume

From the above output we can see that the new 100GB disk is the /dev/sdb decive. On your environment it might be a different device. The rest of this post assumes the device is called /dev/sdb. 

# Ensure no disk partitions on /dev/sdb:

[root@localhost ~]# parted /dev/sdb print
Error: /dev/sdb: unrecognised disk label
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

Please notice that it reported the disk to be 107GB large. We will need that information later when we create the partition.

# Create a disk partition using the entire 107GB:

[root@localhost ~]# parted /dev/sdb mklabel msdos
Information: You may need to update /etc/fstab.

[root@localhost ~]# parted /dev/sdb mkpart primary 1 107g
Information: You may need to update /etc/fstab.

[root@localhost ~]# parted /dev/sdb print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  107GB  107GB  primary

The lvmdiskscan command will verify that your new partition is called /dev/sdb1:
 [root@localhost ~]# lvmdiskscan
  /dev/centos/root [       9,78 GiB]
  /dev/sda1        [     500,00 MiB]
  /dev/centos/swap [       1,20 GiB]
  /dev/sda2        [      11,51 GiB] LVM physical volume
  /dev/sdb1        [     100,00 GiB]
  2 disks
  2 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume

# Initialize the new disk:

[root@localhost ~]# pvcreate -v /dev/sdb1
    Set up physical volume for "/dev/sdb1" with 209713152 available sectors
    Zeroing start of device /dev/sdb1
    Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created

# Create a LVM volume group:

[root@localhost ~]# vgcreate docker-vg00 /dev/sdb1 -v
    Adding physical volume '/dev/sdb1' to volume group 'docker-vg00'
    Archiving volume group "docker-vg00" metadata (seqno 0).
    Creating volume group backup "/etc/lvm/backup/docker-vg00" (seqno 1).
Volume group "docker-vg00" successfully created

# Create a logical volume to contain the Docker metadata and temporary files as well as any storage you will share between your host and the Docker containers:

[root@localhost ~]# lvcreate -L 25g -n docker-storage docker-vg00
  Logical volume "docker-storage" created.

# Create and mount file system

[root@localhost ~]# mkfs.xfs /dev/docker-vg00/docker-storage
[root@localhost ~]# mkdir /docker
[root@localhost ~]# echo "/dev/docker-vg00/docker-storage /docker  xfs     defaults        0 0" >> /etc/fstab
[root@localhost ~]# mount /dev/docker-vg00/docker-storage /docker
[root@localhost ~]# mkdir -p /docker/data
[root@localhost ~]# mkdir -p /docker/sharedfs
[root@localhost ~]# chmod 777 /docker/sharedfs

# Verify that the /docker mount point was mounted:

[root@localhost ~]# df -h
Filesystem                                Size  Used Avail Use% Mounted on
/dev/mapper/centos-root                    11G  3,7G  6,6G  36% /
devtmpfs                                  911M     0  911M   0% /dev
tmpfs                                     921M     0  921M   0% /dev/shm
tmpfs                                     921M  8,4M  912M   1% /run
tmpfs                                     921M     0  921M   0% /sys/fs/cgroup
/dev/sda1                                 497M  244M  254M  50% /boot
/dev/mapper/docker--vg00-docker--storage   25G   33M   25G   1% /docker

# Docker installation

[root@localhost ~]# yum install -y docker
[root@localhost ~]# yum update -y

# Take a backup of the Docker configuration file and the Docker storage creation file

[root@localhost ~]# NOW=$(date +"%Y-%m-%d_%H-%M")
[root@localhost ~]# cp /etc/sysconfig/docker /etc/sysconfig/docker.BACKUP.${NOW}
[root@localhost ~]# cp /bin/docker-storage-setup /bin/docker-storage-setup.BACKUP.${NOW}}

# Configure Docker to use the mount point /docker for metadata and temporary data

[root@localhost ~]# sed -i "s#OPTIONS\='--selinux-enabled'#\#OPTIONS\='--selinux-enabled'\nOPTIONS\='--selinux-enabled -g /docker/data -p /var/run/docker.pid'#" /etc/sysconfig/docker

# Configure the docker-pool to use the new LVM volume group we created, which should have 82GB left:

[root@localhost ~]# sed -i "s#\/bin\/bash#\/bin\/bash\n\nVG\=docker-vg00#" /bin/docker-storage-setup

# Start and enable the Docker service

The docker.service relies on docker-storage-setup.service, which will create the docker-pool logical volume based on the information in /bin/docker-storage-setup, which we have already customized to use the new volume group docker-vg00.
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker

# Verify that docker-pool has been created

[root@localhost ~]# lvs docker-vg00
  LV             VG          Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  docker-pool    docker-vg00 twi-a-t--- 44,93g             0,04   0,06
  docker-storage docker-vg00 -wi-ao---- 25,00g

# Pull a ready Docker image from the public repository:

[root@localhost ~]# docker pull ubuntu:14.04
14.04: Pulling from docker.io/ubuntu
6071b4945dcf: Pull complete
5bff21ba5409: Pull complete
e5855facec0b: Pull complete
8251da35e7a7: Pull complete
Digest: sha256:fb00a642c029fdd339cd7ed5d46ec4ace045c595123a56fc9ba331675ec9da08
Status: Downloaded newer image for docker.io/ubuntu:14.04

# Show all your Docker images. Currently it should only be the Ubuntu image you just downloaded:

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/ubuntu    14.04               8251da35e7a7        4 days ago          188.3 MB

# Run the downloaded Ubuntu image in an interactive Bourne Again shell

[root@localhost ~]# 
docker run -ti ubuntu:14.04 /bin/bash