Showing posts with label howto. Show all posts
Showing posts with label howto. Show all posts

Thursday, 5 April 2018

Basic Ansible in 10 mins


  • "site.yml" file
    • playbook containing
      • "roles" that will be applied to individual host groups / "hosts"
      • how the hosts will be accessed
        • and by what user to run as
      • Puppet equivalent is "nodes.pp"
  • "hosts" file
    • use real/local DNS hostname to define which hosts are in which hostgroups
      • example: webserver1, webserver2, haproxy1, haproxy2, mongo1, mongo2
      • some variables like "port" can be added too
  • "group-vars" directory
    • key/value pairs to use when generating output from template files
    • files named identically to hostgroup names defined in "hosts" file
    • these are more in-line in Puppet, and less controllable/flexible
  • "roles" directory
    • Puppet equivalents are "modules"/"classes"
    • directories arbitrarily named to match "roles" in site.yml
    • e.g. "tomcat", "common", "mongod"
    • "templates" directory
      • files with variables that are resolved using "group-vars" key/values
      • moved on to target systems using task keyword "template"
      • same name is used in Puppet
    • "files"
      • raw files to be moved into place on the target filesystems
      • used by tasks with keyword "file"
      • same name used in Puppet
    • "handlers"
      • "main.yml"
      • control system services on target systems
        • "service" keyword
        • "state", e.g. "restarted"
        • in Puppet, these are not broken out from other "resources"
    • "tasks"
      • this is the core list of actions to perform on target systems
      • Puppet equivalents are "includes"/"classes", maybe "modules" as well
      • "main.yml"
        • collection of tasks
        • uses yml structure
          • "name" is arbitrary reference for developers
          • ansible keyword to perform some action on the system
            • ansible keywords: "file", "template", "command"
              • puppet equivalents are called "resources"
          • conditionals/dependencies: "when", "notify", "wait_for"


Tuesday, 24 January 2017

Docker: simple example, fast

See github link for instructions on how to run.

docker-compose.yml

version: '2'
services:
    app:
        build:
            context: ./
            dockerfile: app.docker
        ports:
            - "80:80"

app.docker

FROM silintl/ubuntu:16.04

RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get update
RUN apt-get install -y apache2

WORKDIR /var/www/humankind

RUN echo " \n\
 \n\
    ServerName humankind \n\
    DocumentRoot /var/www/humankind \n\
 \n\
" >> /etc/apache2/sites-available/humankind.conf

RUN a2dissite 000-default.conf && a2ensite humankind.conf

RUN echo "Automation for the People" > /var/www/humankind/index.html

EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]

See: https://github.com/pcleddy/mini001

Thursday, 29 December 2016

simple angularjs 1.x webapp

Here's a very simple app using AngularJS 1.x.

Hints:

  • Ignore how the first couple of lines in app.js work, and just use as is.
  • Anything in index.html that starts with "ng-" is a "angular directive", fancy term for a placeholder. Angular repeatly scans the DOM for these, gulps them up and runs them. Sometimes it is just a div, sometimes the whole body. You decide how much of the DOM a directive needs to control. Try to keep it as small as possible.

Code: https://github.com/pcleddy/wordcounter
Live app: http://bit.ly/2iiEuoY (I hope)

Maybe try to play with app.js to see if you can add some functionality using m_words.

Wednesday, 23 April 2014

gnupg

  1. create
    1. gpg --gen-key
      1. if entropy taking too long
        1. sudo apt-get install rng-tools
      2. note your key ID from output
        1.  pub   4096R/B110C232 2014-04-23
        2. here it is: B110C232
  2.  push
    1. gpg --send-keys --keyserver keyserver.ubuntu.com B110C232
      1. replace B110C232 with the key ID output from above
  3. more to come

Monday, 13 May 2013

Put stuff on your Nexus 4


  1. apt-get install gmtp
  2. Make sure your "Storage" is in MTP mode
P.S. Or, if you have access to a Mac: "Android File Transfer"

Sunday, 3 February 2013

Fix jEdit fonts for MacBook Pro with Retina display


From: https://bugs.eclipse.org/bugs/show_bug.cgi?id=382972#c4
Assumptions: jEdit was installed into /Applications directory.


  1. Close any running jEdit
  2. Edit /Applications/jEdit.app/Contents/Info.plist
    1. At end of file, add the top two lines below above the bottom two lines, and save
  3. Drag jEdit to desktop
  4. Start jEdit and see if fonts fixed
  5. If fixed, drag jEdit back to /Applications, and retest.

<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>

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...