Archive

Archive for August, 2015

Create public/private key

August 28, 2015 Leave a comment

To Generate your public/private keys

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/rodnee/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/rodnee/.ssh/id_rsa.
Your public key has been saved in /home/rodnee/.ssh/id_rsa.pub.

Go ahead and share your public key with the other party.

Categories: bash Tags: ,

Whiptail – Site with examples

August 28, 2015 Leave a comment

Working with Redis

August 27, 2015 Leave a comment

What is Redis?

Redis is an open source, BSD licensed, advanced key-value cache and store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs.

Download from http://redis.io/download and follow the installation instructions.

1. Start up the server

$ ./redis-server

                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.0.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 17983
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

17983:M 27 Aug 09:29:46.683 # Server started, Redis version 3.0.3
17983:M 27 Aug 09:29:46.683 * DB loaded from disk: 0.000 seconds
17983:M 27 Aug 09:29:46.683 * The server is now ready to accept connections on port 6379

2. Connect to the server using the commandline interface.

$ ./redis-cli
127.0.0.1:6379> set "HLR:34" "{bar:'rab', foo:'oof'}"
OK
127.0.0.1:6379> get "HLR:34"
"{bar:'rab', foo:'oof'}"

# To clear the database.
127.0.0.1:6379> flushdb
OK

# To quit.
127.0.0.1:6379> quit

Source:
redis.io

Advanced Json manipulation with python

August 27, 2015 Leave a comment

Working with json:

[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> produce = {"mangoes": 4, "oranges": 1, "bananas": 5}
>>> json.loads(produce)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer

>>> json_string = json.dumps(produce)
>>> json.loads(json_string)
{u'mangoes': u'4', u'bananas': u'5', u'oranges': u'1'}

Source:

http://www.yilmazhuseyin.com/blog/dev/advanced_json_manipulation_with_python/

Graphite

August 27, 2015 Leave a comment
Categories: Interesting

Crash Tolerant Data Storage

August 26, 2015 Leave a comment
Categories: Interesting

Ubuntu – Changing locale settings

August 25, 2015 Leave a comment

Problem:
I kept on seeing the below perl warnings when running apt-get install on my virtual machine. (Ubuntu Trusty 64 bit)


perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US",
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Running locale shows some errors

vagrant@vagrant-ubuntu-trusty-64:~$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Running dpkg-reconfigure locales also has some errors

$ sudo dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US",
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Generating locales...
en_US.UTF-8... up-to-date
Generation complete.

The following two commands did not solve the issue for me either.

$ sudo local-gen “en_US.UTF-8”

OR

$ sudo apt-get install language-pack-UTF-8

Solution:
What finally worked for me adding the following three lines to /etc/environment file.

LANG="en_US.UTF-8"
LANGUAGE="en_US"
LC_ALL="en_US.UTF-8"

Save the change, logout and reboot virtual machine.

To check to see if errors have gone away I re-ran ‘locale’ and ‘sudo dpkg-reconfigure locales’ commands

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

sudo dpkg-reconfigure locales
Generating locales...
en_US.UTF-8... up-to-date
Generation complete.

Update 3rd May 2016
I still keep on seeing the below errors when installing some other programs. This happens if I log out of a vagrant box and then come back later. So that means I have done a vagrant halt then a vagrant up.

perl: warning: Please check that your locale settings:
LANGUAGE = “en_US”,
LC_ALL = (unset),
LC_CTYPE = “UTF-8”,
LANG = “en_US.UTF-8”
are supported and installed on your system.

So I had to “fix” this problem again.

This time what I had to do on top of the previous steps was to add this to my ~/.bash_profile file.

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Source:
http://askubuntu.com/questions/162391/how-do-i-fix-my-locale-issue
http://askubuntu.com/questions/463209/how-to-fix-locale-error

pip install MySQL-python fails

August 25, 2015 Leave a comment

Problem:
I was trying to install MySQLdb for python on an Ubuntu box (Virtual Machine). But pip fails with below error.

vagrant@vagrant-ubuntu-trusty-64:~$ sudo pip install MySQL-python
Downloading/unpacking MySQL-python
  Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
  Running setup.py (path:/tmp/pip_build_root/MySQL-python/setup.py) egg_info for package MySQL-python
    sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_root/MySQL-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: 1: mysql_config: not found

Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_root/MySQL-python/setup.py", line 17, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 25, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/MySQL-python
Storing debug log for failure in /home/vagrant/.pip/pip.log

Solution:

vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install python-dev libmysqlclient-dev
vagrant@vagrant-ubuntu-trusty-64:~$ sudo pip install MySQL-python
Downloading/unpacking MySQL-python
  Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
  Running setup.py (path:/tmp/pip_build_root/MySQL-python/setup.py) egg_info for package MySQL-python

Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python
...
...
Successfully installed MySQL-python
Cleaning up...
vagrant@vagrant-ubuntu-trusty-64:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> exit()
vagrant@vagrant-ubuntu-trusty-64:~$


Source:

http://stackoverflow.com/questions/25865270/how-to-install-python-mysqldb-module-using-pip

Categories: MySQL, python Tags:

Vagrant – Setting up an Ubuntu box on Mac OS X

August 21, 2015 Leave a comment

Problem:
Needed to have an Ubuntu Box on Mac OS X Yosemite.

Solution:
Vagrant + Ubuntu + Virtual Box

$ vagrant init ubuntu/trusty64

$ vagrant up --provider virtualbox

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.10
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => /Users/rodnee/local_trusty
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.


$ vagrant ssh

Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-62-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Aug 21 09:36:29 UTC 2015

  System load:  0.16              Processes:           92
  Usage of /:   2.9% of 39.34GB   Users logged in:     0
  Memory usage: 18%               IP address for eth0: 10.0.2.15
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud


Last login: Fri Aug 21 09:04:39 2015 from 10.0.2.2
-bash: warning: setlocale: LC_ALL: cannot change locale (en.US): No such file or directory

vagrant@vagrant-ubuntu-trusty-64:~$ exit
logout
Connection to 127.0.0.1 closed.

$ vagrant halt

==> default: Attempting graceful shutdown of VM...

Other commands:
1. To view the boxes that you have on your machine.


$ vagrant box list
ubuntu/trusty64     (virtualbox, 20150817.0.0)
ubuntu64box         (vmware_fusion, 0)

$ vagrant box remove ubuntu64box --provider vmware_fusion
Removing box 'ubuntu64box' (v0) with provider 'vmware_fusion'...

Assumptions:
1. You have VirtualBox installed on your machine.
2. You have Vagrant installed on your machine.

Source:
https://atlas.hashicorp.com/boxes/search?provider=virtualbox
Creating Development Environments with Vagrant by Michael Peacock

Webserver Optimization

August 13, 2015 Leave a comment

Interesting

whiscardz collection

Problem

Given a webserver experiencing high loads, how would you optimize current resources before throwing more hardware at the problem?

Good Place to Start is:

Measure: When trying to improve something, it is essential to find a way to measure it first. How can you be sure there was any improvement if there is no metric to prove it? Trying to improve something without metrics is most of the time just random and wasted work, and even at best only application of old knowledge. Metrics enables also the persons doing the measurement to learn from each iteration and perhaps discover something new and take the world one small step forward.

Since the world is going mobile, PageSpeed recommends that a user should be served with a page within atleast 1 second of a request. Excluding the network overhead leaves the provider with about 400ms optimization leg room ( This is time…

View original post 88 more words

Categories: Interesting