x2q dot net

open source, ubuntu, ruby, and payments

Howto: Install MariaDB on Debian 7/Wheezy

MariaDB is a fork of MySQL, which is true open source and community maintained. MariaDB is a binary drop in replacement for MySQL. It includes the XtraDB storage engine as a replacement for InnoDB. Its lead developer is Michael Widenius (also known as “Monty”), the founder of MySQL.

Recently, many popular Linux distributions replaced MySQL with MariaDB as default database server. Fedora version => 19, Archlinux and OpenSuse. Moreover Wikipedia moved to MariaDB and Mozilla also uses MariaDB.

Famous distributions often used in server environments such as Debian and Centos have not replaced MySQL with MariaDB yet, but they’ll probaly soon migrate as well.

Why switch to MariaDB

Well, MySQL development has basically stopped, since Oracle acquired MySQL, whereas the MariaDB development is progessing at full speed.

Performance and licensing are the often the most predominant reasons to make a switch from MySQL to MariaDB.

Regarding performance - here is what Wikipedia experienced, when they compared MariaDB to the Facebook fork of MySQL 5.1.

Many query types were 4-15% faster with MariaDB 5.5.30
under production load, a few were 5% slower, and nothing
appeared aberrant beyond those bounds.

Install MariaDB on Debian Wheezy

MariaDB packages are not yet available in official Debian repositories. MariaDB provides repositories for almost every popular os here:

https://downloads.mariadb.org/mariadb/repositories/

Add the following to your /etc/apt/sources.list

1
deb http://ftp.osuosl.org/pub/mariadb/repo/5.5/debian wheezy main

and then

1
2
3
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
sudo apt-get update
sudo apt-get install mariadb-server-5.5 libmysqlclient18=5.5.30-mariadb1~wheezy

The libmysqlclient18=5.5.30-mariadb1~wheezy is needed as a work-around to this bug.

This should result is something like this…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmariadbclient18 libnet-daemon-perl libplrpc-perl mariadb-client-5.5
  mariadb-client-core-5.5 mariadb-common mariadb-server-core-5.5 mysql-common psmisc
Suggested packages:
  libipc-sharedcache-perl tinyca mailx mariadb-test
The following NEW packages will be installed:
  libaio1 libdbd-mysql-perl libdbi-perl libhtml-template-perl libmariadbclient18 libmysqlclient18 libnet-daemon-perl libplrpc-perl
  mariadb-client-5.5 mariadb-client-core-5.5 mariadb-common mariadb-server-5.5 mariadb-server-core-5.5 mysql-common psmisc
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.3 MB of archives.
After this operation, 111 MB of additional disk space will be used.
Do you want to continue [Y/n]? 

You are now ready to use MariaDB.

OS X Performance Tweaks

Update to Latest OS X

Upgrade to the latest version of OS X.

If you are upgrading from Lion to Mountain Lion, then tere’s no need to visit a store and fetch a box, and install a bunch of discs. Just click the Mac App Store icon on your Mac. Buy OS X Mountain Lion. And your Mac does the rest.

Follow this Apple guide for more info

Clean System and User Caches etc. Using OnyX

OnyX is an utility for Mac OS X which allows you to run system maintenance, to configure some hidden parameters of the Finder, Dock, QuickTime, Safari, Mail, iTunes, login window, Spotlight, and many of Apple’s applications, to delete caches, to remove a certain number of files and folders that may become cumbersome, and more.

Download OnyZ and install it.

Clean System Cache

Clean User Cache

Clean Internet abd Network related Caches

Empty Log Files

Clean Misc OS X Stuff

Empty Trash For All Users

Remove Startup Items in System Preferences

If you are tired of applications launching automatically when you start your Mac, then you can actually remove those Startup items from launching and slow down your performance.

Startup items are quite easy to remove with a few clicks and tweaks in the System Preferences.

Navigate to System Preferences > Users & Groups. Now select you click your username, and then click on the Login Items tab.

Here you are able to see all items launched at startup.

Ubuntu: Optimize for Speed

This easy little guide will help you with simple optimization tips for speeding up Ubuntu (12.04, 12.10, and 13.04) and other Ubuntu-based systems such as Linux Mint. The tips come in very handy for those using older computers with low RAM who need to boost their computer for better speed and performance and if you are just want a really fast and snappy computer on some regular hardware.

Removing Ubuntu One client

Saves >100 MB ram.

The following steps can be followed to completely remove the Ubuntu One client software.

1
2
3
4
5
killall ubuntuone-login ubuntuone-preferences ubuntuone-syncdaemon
sudo rm -rf ~/.local/share/ubuntuone
rm -rf ~/.cache/ubuntuone
rm -rf ~/.config/ubuntuone
rm ~/Ubuntu\ One
1
sudo apt-get purge ubuntuone-client python-ubuntuone-storage*

Remove unused Unity lenses

1
2
3
4
5
6
7
sudo apt-get purge \
unity-lens-friends \
unity-lens-music \
unity-lens-photos \
unity-lens-shopping \
unity-lens-video \
unity-lens-radios

Optimize mount options

Ubuntu use the relatime flag for updating file metadata when files are accessed. All these updates involve writes to the disk. We can avoid this with the noatime and nodiratime parameters. This means that access time to files and directories won’t be tracked at all.

Use tmpfs for /tmp and /var etc.

Add a section like this tmpfs section to /etc/fstab

Move browser cache to tmpfs

1
2
rm -rf ~/.cache/google-chrome
ln -s /tmp ~/.cache/google-chrome

Move browser profile to memory using Profile-sync-daemon

Profile-sync-daemon (psd) is a diminutive pseudo-daemon designed to manage your browser’s profile in tmpfs and to periodically sync it back to your physical disc (HDD/SSD). This is accomplished via a symlinking step and an innovative use of rsync to maintain back-up and synchronization between the two. One of the major design goals of psd is a completely transparent user experience.

Running this daemon is beneficial for two reasons: * Reduced wear to physical discs * Speed

1
2
3
sudo add-apt-repository ppa:graysky/utils
sudo apt-get update
sudo apt-get install profile-sync-daemon

Adjust /etc/psd.conf to match your setup and then restart the Profile-sync-daemon. Your browser(s) needs to be closed before restart of the Profile-sync-daemon.

1
sudo /etc/init.d/psd restart

Remove orphaned libraries

Over time most Ubuntu/Debian installations acquire packages which are no longer required - they’ve just been pulled in to satisfy dependencies of software you’ve since removed - deborphan package is probably the simplest way to get rid of orphaned and unused packages.

1
2
sudo apt-get install deborphan
sudo apt-get remove --purge `deborphan`; sudo apt-get autoremove

Clean browsers cache etc and vacuum browser databases.

1
2
3
4
sudo apt-get install bleachbit
bleachbit -c `bleachbit -l | grep cache`
bleachbit -c `bleachbit -l | grep tmp`
bleachbit -c `bleachbit -l | grep vacuum`

Clean rotated log files

1
sudo bleachbit -c system.rotated_logs

Clean temp and backup files

First do a dry-run and check that everything is good to go.

1
bleachbit -p deepscan.*

and then do the real one

1
bleachbit -c deepscan.*

Disable unnecessary services and applications

Use BUM, which is a runlevel configuration tool with GUI that allows Ubuntu users to edit and configure init services that are started when the system is booting up or restarting. With this tool, you will be displayed with all running and disabled services in which you can turn them on/off.

1
2
sudo apt-get install bum
sudo bum

To remove applications from startup go to Dash > and type Startup Applications.

Disable automatic startup of any services that are not needed (or even remove the package completely).

Increases performance using zRam

zRam is a module of the Linux kernel. It was previously called “compcache”. zRam increases performance by avoiding paging on disk and instead uses a compressed block device in RAM in which paging takes place until it is necessary to use the swap space on the hard disk drive. Since using RAM is faster than using disks, zRam allows Linux to make more use of RAM when swapping/paging is required, especially on older computers with less RAM installed.

FYI: Google uses zRAM for Chrome OS

Enable zRam on Ubuntu:

1
sudo apt-get install zram-config

Howto Install Memcached Gem on Ubuntu/Debian

Memcached is a general-purpose distributed memory caching system used by many sites around. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read. Memcached runs on Unix, Linux, Windows and Mac OS X.

The memcached gem requires the following development libraries to be installed

1
sudo apt-get install libmemcached-dev libsasl2-dev

and then

1
sudo gem install memcached

Chrome Built-in User-Agent Switcher

You may need to quickly switch between user-agent strings on the fly - when developing websites that need to work on both mobile browsers and desktop browsers user-agent switcing is a must-have.

And some times you’ll expirence some archaic site blocking you because you’re not using Netscape or Internet Explorer (in an ancient version e.g. version 6).

Chrome got a built-in user-agent switcher. All you need to do is to open the developer tools panel (use Ctrl+Shift+I shortcut) and click the wrench button (lower right corner) and click Overrides, and enable override user agent and elect the browser or device you want to emulate and reload the page.

There is user-agent switchers and methods available for most browsers:

Chrome

Safari

Firefox

Internet Explorer

You can always check your current user agent string by visting e.g. http://whatsmyuseragent.com/

My current user agent string is:

1
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31

Howto Install Office 2010 Using Wine

Microsoft Office 2010 is the most recent version of the Microsoft Office productivity suite. Formerly known as Office 14 in the initial stages of its beta cycle, it was released to customers in 2010.

This howto assume that you got an ISO image of the installation media.

If you are on Debian/Ubuntu you can install wine, winetricks, and winbind using

1
sudo apt-get install wine1.5 winetricks winbind

In order to install you’ll need the following native Microsoft Windows libraries (dll files)

1
WINEARCH=win32 winetricks riched20 winhttp

Then mount and install

1
2
sudo mount -o loop -o unhide Microsoft-Office-2010.iso /mnt
WINEARCH=win32 wine /mnt/setup.exe

Test Excel

1
WINEARCH=win32 wine ~/.wine/drive_c/Program\ Files/Microsoft\ Office/Office14/EXCEL.EXE

Howto Backup WD MyBook Live to Amazon S3 and Glacier

Recently I helped a photographer to backup a large photo collection (several terabytes) from a Western Digital (WD) personal NAS MyBook Live.

The My Book Live Edition NAS was released by Western Digital in 2011. They range in storage capacity from 1 to 4 TB. My Book Live features a 1 GHz ARM processor, 256 MB of RAM, and 1000 Mbit/s ethernet connectivity. Contrary to previous My Book Live versions it now features a fully fledged Debian linux distribution, whichs makes the My Book Live easy to customize and adapt to different needs.

Backup your My Book Live to Amazon S3 and Glacier

This assumes that you got SSH access to your My Book Live. If you haven’t got SSH, then do the following to enable SSH access.

Enable SSH via hidden menu on WD My Book Live

Go to http://mybooklive/UI/ssh (case sensitive) replace “mybooklive” if you have renamed your My Book Live to something else, or replace it with its IP address. It’s a hidden UI menu to enable SSH.

Now you are able to ssh to your My Book Live via putty or another ssh client.

Install the backup tool Duplicity etc.

  $ apt-get install python-boto duplicity util-linux trickle

I used the following Bash script as a cron job. The script features:

  • exclusive locking using flock - ensures that only instance is actice at the time. This is useful, when your backup might run for several days.
  • bandwidth / upload limit using trickle.
  • custom temp and cache folders - this is required on a WD My Book Live as it got limited space on the root file system

Now it is time to make the script run every night. Edit your crontab:

    $ crontab -e

Add the following line

    # m h  dom mon dow   command 
    42  22  *   *   *    /root/wd-live-s3-backup.sh

Then be sure to check your log files and do restore to check that everything is good.

Adjust S3 lifecycle rule

Amazon supports archiving of Amazon S3 Data to Amazon Glacier using lifecycle rules.

I use the following lifecycle rule for Amazon S3 and Glacier.

Howto Run Netflix on Ubuntu Linux

Netflix is finally working on Linux - not native, but with a patched Wine build, you can now use Netflix under Linux.

For those who are not familiar with Netflix, it is an American provider of on-demand Internet streaming media available to both North and South America, the Caribbean, United Kingdom, Ireland, Sweden, Denmark, Norway, Finland.

How to install

  $ sudo apt-add-repository ppa:ehoover/compholio
  $ sudo apt-get update
  $ sudo apt-get install netflix-desktop

The Netflix Desktop package installs all of the components necessary to run Netflix Watch Instantly under Wine, including the Windows version of Mozilla Firefox and Microsoft Silverlight v4. The package also includes some convience settings to integrate Netflix into Firefox in such a way that everything feels like a native application.

Run Netflix

You can launch the Netflix Desktop web app through desktop Dash menu. The Netflix Desktop application runs in full screen, but you can exit full screen mode by pressing F11 (just like any other browser).

Use it for websites that require Silverlight / PlayReady DRM

Start the Netflix Desktop web app and then press F11 (to exit full screen mode), then press ALT + v and then the menu occurs, now enable the Menu Bar and Navigation Toolbar.

Now you are able to navigate to http://web.sldrm.video.msn.com/ or http://www.filmstriben.dk/.

Howto Use Amazon RDS From Heroku

Heroku is quite popular for lightweight webservice and like projects. Until recently Heroku only offered PostgreSQL-based database backend providers, but now Heroku offers a quite large range of database backend providers; among them Amazon RDS.

This is a short run-down on how I managed to get a Heroku-based application to connect to a Amazon RDS-based database.

  • Install the Amazon RDS command line tools

    $ sudo apt-get install rdscli
    
  • Create a AWS Credential File (~/.aws/AwsCredentials.properties)

  • Create a RDS db in the us-east region (if not run in this region, Heroku isn’t able to connect to it)

     $ rds-create-db-instance --db-instance-identifier [name]\
       --allocated-storage 5 \
       --db-instance-class db.m1.small  \
       --engine MySQL5.1 \
       --master-username [user] \
       --master-user-password [pass] \
       --db-name [db-name] \
       --region us-east
       --headers \
       --aws-credential-file ~/.aws/AwsCredentials.properties
    
  • Now authorize access from your public ip to the Amazon RDS instance

     $ rds-authorize-db-security-group-ingress default --cidr-ip 87.1.1.1/32 \
     --aws-credential-file ~/.aws/AwsCredentials.properties
    
  • Test MySQL connectivy from your local machine to the Amazon RDS instance

     $ mysql -u root -p -h <your-amazon-rds-hostname>
    
  • Now authorize access from the Heroku ip group ranges to the Amazon RDS instance

     $ rds-authorize-db-security-group-ingress --db-security-group-name default \
     --ec2-security-group-name default --ec2-security-group-owner-id 098166147350 \
     --aws-credential-file ~/.aws/AwsCredentials.properties
    
  • Enabled the Amazon RDS plugin using the Heroku console toolbelt

    $ heroku addons:add amazon_rds url=mysql://<user>:<pass>@<your-amazon-rds-hostname>/<db-name>
    

Howto Setup PDF Printer on Linux

Installing a pdf-printer on Windows is crap, but in Linux/Ubuntu/Debian it is quite easy.

$ sudo apt-get install cups-pdf

Then restart your cups daemon

$ sudo service cups restart

And you are ready to print to pdf files.