Wednesday 30 October 2013

Latest aws cli tools on Redhat

  1. wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
  2. unzip awscli-bundle.zip
  3. sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
 Result is in /usr/local/bin, so set up your PATH accordingly.

Wednesday 23 October 2013

aws cli run-instances block-device-mappings ephemeral encrypted

aws --version => aws-cli/1.1.1 Python/2.6.8 Linux/3.4.43-43.43.amzn1.x86_64
  1. aws ec2 run-instances 
    1. --image-id 
      1. ami-eeff1122 
    2. --instance-type 
      1. m2.2xlarge 
    3. --security-group-ids 
      1. sg-eeff1122
    4. --subnet-id 
      1. subnet-eeff1122
    5. --private-ip-address 
      1. 10.0.0.2
    6. --user-data 
      1. file://meta_myserver.txt 
    7. --block-device-mappings 
      1. '[{ "DeviceName":"/dev/sdb", "VirtualName":"ephemeral0" }]'
For 50G EBS attached on boot (auto-deleted on terminate unless you override), block device mapping becomes:
  1.  '[{ "DeviceName":"/dev/sdb", "VirtualName":"ephemeral0" },{"DeviceName":"/dev/sdc","Ebs":{"VolumeSize":50}}]'
WARNING: "Ebs" is very case sensitive here.

To encrypt the Ebs volume, add "Encrypted": true to the device params like so:
  1.  {"DeviceName":"/dev/sdc","Ebs":{"VolumeSize":50,"Encrypted": true}}


Tuesday 15 October 2013

Use rvm in cron

  1. rvm list
    1. find what looks like your gems set, e.g
        1. ruby-1.9.3-p194
  2. echo $rvm_path/bin, e.g.
    1. /usr/lib/rvm/bin
  3. tack on the output of #1 to the output of #2, e.g.
    1. /usr/lib/rvm/bin/ruby-1.9.3-p194
  4. your cron entry should be the result of #3 followed by your ruby script, e.g.
    1. 0 0 * * * /usr/lib/rvm/bin/ruby-1.9.3-p194 /optt/mydir/myscript.rb

Test exim from CLI without "mail" command

If you don't have "mail" on the CLI for whatever, weird (Redhat-based) reasons, circumvent like so:
  1. /path/to/exim -v 'user@domain'
  2. type a multi-line message here ending with blank line
  3. hit ^D to end message and send
  4. you should be returned to shell
Taken: http://atmail.com/kb/2008/testing-email-with-exim/

Saturday 5 October 2013

Edit files on a remote server via your Mac using ssh, sshfs and brew


  1. install latest xcode
  2. install brew
  3. install sshfs using brew
    1. make sure to change any permissions specified
  4. mkdir mytmpdir
  5. sshfs -o uid=<your local numerical id> root@<remote server>:<remote dir> mytmpdir
    1. e.g. sshfs -o uid=501 root@10.1.0.100:images mytmpdir
  6. edit files that appear in tmpdir, and when you save them, the remote files will be updated
Unmount
  1. umount mytmpdir

Friday 4 October 2013

Simple unbound upstart script

  1. put below in /var/tmp/unbound.conf
  2. pkill unbound
  3. lsof -nP -i :53
  4. pgrep unbound
  5. cp -v /var/tmp/unbound.conf /etc/init/
  6. start unbound
  7. status unbound
  8. status unbound
  9. start unbound
start on runlevel [3]
expect fork
exec unbound

Thursday 3 October 2013

Sanity of growing a stripped LVM volume

Quote:

However, with LVM you can easily grow a logical volume. But, you cannot use stripe mapping to add a drive to an existing striped logical volume because you can’t interleave the existing stripes with the new stripes. This link explains it fairly concisely.

    “In LVM 2, striped LVs can be extended by concatenating another set of devices onto the end of the first set. So you can get into a situation where your LV is a 2 stripe set concatenated with a linear set concatenated with a 4 stripe set.”

Taken: Pick Your Pleasure: RAID-0 mdadm Striping or LVM Striping?

Tuesday 1 October 2013

Create isolated bucket on S3

  1. setup
    1. create IAM group
      1. add simple, custom policy below
      2.  do not add any other policies to group
    1. create IAM user and put in above IAM group
      1. create and download key and secret for user
    2. create bucket "mybucket01" in S3
      1. you don't have to touch perms of bucket itself
  2. client
    1. install s3fox addon for Firefox from www.s3fox.net
      1. older versions FAIL! get it only at www.s3fox.net
    2. open s3fox addon
      1. Firefox -> Tools -> S3 Organizer
    3. add only one user to "Manage Accounts" using user key and secret
    4. in right-hand window of s3fox add "/mybucket01" NOT "/"
      1. "/" will give you "Access Denied"
        1. because user does not have perms to list root buckets, only itself
{
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "arn:aws:s3:::mybucket01"
        },
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::mybucket01",
                "arn:aws:s3:::mybucket01/*"
            ]
        }
    ]
}   

Snapshot AWS instance store as AMI

  1. install api-tools
  2. install ami-tools
  3. generate key / cert
  4. create IAM user 
  5. upload cert
  6. java install / export JAVA_HOME
  7. export key and secret
  8. ec2-bundle-vol 
    1. --user  <AWS acct #> 
    2. --privatekey /myhome/my-key.pem
    3. --cert /myhome/my-cert.pem
    4. --arch x86_64
    5. --destination /var/tmp
    6. --exclude
      1. /backup,
      2. /mnt,
      3. /swapfile
  9. ec2-upload-bundle
    1. --manifest /var/tmp/image.manifest.xml
    2. --bucket mybucket/hostname
    3. --access-key <AWS Key>
    4. --secret-key <AWS Secret>
    5. --location EU
  10. ec2-register
    1. --region eu-west-1
    2. --name "myaminame"
    3. --description "Backing up hostname"
    4. mybucket/hostname/image.manifest.xml
Taken:
  1. http://www.dowdandassociates.com/content/howto-create-an-instance-store-backed-amazon-ec2-ami/
  2. http://www.dowdandassociates.com/content/howto-install-aws-cli-amazon-elastic-compute-cloud-ec2-ami-tools/
  3. http://www.dowdandassociates.com/content/howto-install-aws-cli-amazon-elastic-compute-cloud-ec2-api-tools/
NOTE: the above link's content has typos in very essential parts, proof all steps

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