Thursday 31 January 2013

Vagrant: how to set vm memory and force gui mode


# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|

  config.vm.define :zenoss do |zenoss_config|
      zenoss_config.vm.box  = "quantal64"
      zenoss_config.vm.network :hostonly, "10.66.66.10"
      zenoss_config.vm.forward_port 80, 8885
      zenoss_config.vm.customize ["modifyvm", :id, "--memory", 1024]
  end

  config.vm.define :desktop do |desktop_config|
      desktop_config.vm.box  = "quantal64"
      desktop_config.vm.network :hostonly, "10.66.66.20"
      desktop_config.vm.boot_mode = :gui
  end

end

Friday 25 January 2013

How to convert encryption keys: RSA to PEM



  1. RSA to PEM
    1. ssh-keygen -t rsa
    2. openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem

Thursday 17 January 2013

Asterisk pre-reqs for compiling on Debian/Ubuntu

apt-get -y install make libncurses-dev libxml2-dev sqlite3 libsqlite3-dev libiksemel-dev libssl-dev  subversion

Thursday 10 January 2013

Redirection on CLI: greater-thans, ampersands and numbers

  1. myCLIapp > /dev/null 2>&1
    1. Order is important, don't reverse the redirects
      1. See below
    2. First redirect sends STDOUT to kernel's blackhole equivalent
      1. result:  STDOUT is forgotten, never shown
      2. STDOUT is implied when no number before '>'
    3. Second redirect sends STDERR to where STDOUT points
      1. STDERR goes where STDOUT goes
      2. So STDERR ends up in blackhole too
      3. The amphersand is necessary
        1. to specify this is a "file handle" 
        2. and not a filename
  2. Reverse mistake
    1. myCLIapp 2>&1 > /dev/null 
      1. Read left to right
      2. 2>&1
        1. Would 1st send STDERR to where STDOUT is pointing currently
          1. Which is STDOUT so far
      3. > /dev/null
        1. STDOUT is implied since no number before '>'
        2. Send STDOUT to /dev/null
      4. Result is
        1. STDERR being displayed
        2. STDOUT being sent to blackhole
  3. Remember
    1. if no number given before '>', them implied is STDOUT
http://www.tldp.org/LDP/abs/html/io-redirection.html

Tuesday 8 January 2013

Quick start howto for divish on Debian

  1. Prep
    1. Here, there is one backup server and two client servers that need to be backed up
    2. Make sure root user on backup server can ssh to mybox01.mydomain.net and mybox02.mydomain.net without password
      1. Later, much later, see online for better, more secure ways
    3. install dirvish and rsync on server, rsync on clients
      1. apt-get install dirvish
      2. apt-get install rsync
  2. Clients
    1. The below are just example directories, use your own, the ones you want backed up
    2. mkdir -p /data/backups/
    3. mkdir -p /data/backups/etc
    4. mkdir -p /data/backups/var/log
    5. rsync -av /etc/ /data/backups/etc/
    6. rsync -av /opt/ /data/backups/opt/
    7. Make a cron job to do the rsyncs above nightly
  3. Server
    1. mkdir -p /backup/dirvish/mybox01/dirvish
    2. mkdir -p /backup/dirvish/mybox02/dirvish
    3. vi /backup/dirvish/mybox01/dirvish/default.conf
      1. get contents below
    4. vi /backup/dirvish/mybox02/dirvish/default.conf
      1. get contents below
    5. dirvish --vault mybox01 --init
    6. dirvish --vault mybox02 --init
  4. Verify
    1. Backed up files should now be under /backups/dirvish on backup server
      1. tree /backup/ -d -L 3
      2. find /backup/dirvish -ls | less
  5. Tell dirvish to do nightly pull
    1. vi  /etc/dirvish/master.conf.mybackup
      1. get contents below
  6. Tomorrow, verify the pull worked, and next week too
  7. Exclusion and expire options
    1. Research options one can add to master.conf.mybackup
Server files

/etc/dirvish/master.conf

bank:
    /backup/dirvish

Exclude:
    lost+found/


/etc/dirvish/master.conf.mybackup

Runall:
    mybox01
    mybox02

/backup/dirvish/mybox01/dirvish/default.conf

client: mybox01.mydomain.net
tree: /data/backups

xdev: true
index: gzip


/backup/dirvish/mybox02/dirvish/default.conf

client: mybox02.mydomain.net
tree: /data/backups

xdev: true
index: gzip



Friday 4 January 2013

Install lex on Debian

sudo apt-get install byacc flex

Thursday 3 January 2013

Quick start how-to graphite base install on Debian

UPDATE: Also see Latest Graphite on Amazon Linux at AWS.

This only gets graphite working on your local Linux box. Left to user to translate to remote server installation thereafter.

NOTE: Do everything as root user

  1. make sure apache2 is installed and working with wsgi
    1. apt-get install apache2 -y
    2. apt-get install libapache2-mod-wsgi -y
    3. a2enmod wsgi
    4. wsgi needs a place for its sockets
      1. mkdir /etc/apache2/run
      2. mkdir /var/run/wsgi
      3. chmod 777 /etc/apache2/run /var/run/wsgi
      4. this seems undocumented, thanks!
  2. Install dependencies
    1. apt-get install -y libapache2-mod-wsgi python-twisted python-memcache python-pysqlite2 python-simplejson
    2. apt-get install -y python2.6 python-pip python-cairo python-django python-django-tagging
  3. Install graphite elements
    1. mkdir -p /root/graphite-install
    2. cd /root/graphite-install
    3. git clone https://github.com/graphite-project/graphite-web.git
    4. git clone https://github.com/graphite-project/carbon.git
    5. git clone https://github.com/graphite-project/whisper.git
    6. git clone https://github.com/graphite-project/ceres
    7. cd /root/graphite-install/whisper
    8. git checkout 0.9.x
    9. python setup.py install
    10. cd /root/graphite-install/ceres
    11. python setup.py install
    12. cd /root/graphite-install/carbon
    13. git checkout 0.9.x
    14. python setup.py install
    15. cd /root/graphite-install/graphite-web
    16. git checkout 0.9.x
    17. python check-dependencies.py
      1. fix any missing dependencies
      2. ignore warnings if certain you don't need a feature
    18. python setup.py install
  4. Setup configuration files and permissions
    1. cp -v /opt/graphite/conf/carbon.conf.example /opt/graphite/conf/carbon.conf
    2. cp -v /opt/graphite/conf/storage-schemas.conf.example /opt/graphite/conf/storage-schemas.conf
    3. Create Django database
      1. cp -v /opt/graphite/webapp/graphite/local_settings.py.example /opt/graphite/webapp/graphite/local_settings.py
        1. Edit this file by uncommenting the entire DATABASES section
          1. Otherwise next commands may fail with bizarre error
      2. cd /opt/graphite/webapp/graphite
      3. python manage.py syncdb
        1. Make sure NO errors
        2. Create a user/pass you'll never forget
    4. chown -Rv www-data:www-data /opt/graphite/storage/
      1. EXTREMELY IMPORTANT
  5. Apache
    1. Add below Apache configuration as a virtual host (details not covered here)
      1. Or do this and struggle to make it work
        1. cp -v /opt/graphite/examples/example-graphite-vhost.conf /etc/apache2/sites-available/graphite
    2. Every "directory" and "location" in the virtual hosts file need these entries, or you'll get permission denied errors
      1. apache versions before 2.4
        1. Order deny,allow
        2. Allow from all
      2. apache versions 2.4 and after
        1. Require all granted
    3. a2ensite graphite
    4. cp -v /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi
    5. apache2ctl -S
      1. Check all is OK
    6. service apache2 stop
    7. service apache2 start
    8. If you have trouble check permissions under this directory and/or run this again
      1. chown -Rv www-data:www-data /opt/graphite/storage/
      2. Seems some files are created by root that should be created by www-data user maybe
  6. Start carbon daemon
    1. cd /opt/graphite
    2. /opt/graphite/bin/carbon-cache.py start
      1. verify with:
        1. lsof -nP -i :2003
      2. TASK: automate this to start on reboot somehow
  7. Add to /etc/hosts
    1. 127.0.1.3 graphite
  8. tail -F /opt/graphite/storage/log/webapp/error.log
  9. python /opt/graphite/examples/example-client.py
  10. Hit http://graphite
    1. Should show initial graphite interface
  11. View results
    1. Click down into "system" -> loadavg_5min
    2. Find "Select Recent Data" icon in upper-left toolbar
      1. Set to 10 mins
    3. You should see lines appearing as script runs and feed data to Graphite via Carbon
  12. Check out giraffe once you get some stats to shove in it
    1. https://github.com/kenhub/giraffe
    2. Just dump the files you get from the git clone into a directory under you default Apache install and tweedle with dashboard.js until you see something
  13. Try this a few times on the CLI of your graphite server every few minutes
    1. echo "system.logs.changed_last10 `find /var/log -mmin -10 | wc -l` `date +%s`" | nc -w 1 localhost 2003
    2. Try similar commands to pass in other stats
      1. echo must output a single integer.

WSGISocketPrefix /var/run/wsgi

<VirtualHost *:80>
    ServerName graphite
    DocumentRoot "/opt/graphite/webapp"
    ErrorLog /opt/graphite/storage/log/webapp/error.log
    CustomLog /opt/graphite/storage/log/webapp/access.log common
    
    WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120
    WSGIProcessGroup graphite
    WSGIApplicationGroup %{GLOBAL}
    WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL}
    WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi 

    Alias /content/ /opt/graphite/webapp/content/
    <Location "/content/">
        SetHandler None
    </Location>
    
    Alias /media/ "@DJANGO_ROOT@/contrib/admin/media/"
    <Location "/media/">
        SetHandler None
    </Location>
    
    <Directory /opt/graphite/conf/>
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...