Clone wiki

devoops / Home

Dev...oops!

Ansible

How to install Ansible to Ubuntu 14.04 LTS:

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

Azure

  1. Azure SQL Database Monitoring

Monitoring Azure services

Monitoring Linux VM

Azure VM Extension IaaSDiagnostics (Azure Diagnostics Extension) is not yet supported in Linux VMs.

Azure management portal supports alert rules that send email alerts on following KPIs:

  • Network In (Bytes)
  • Network Out (Bytes)
  • CPU Percentage (%)
  • Disk Write Bytes/sec (Bytes/s)
  • Disk Read Bytes/sec (Bytes/s)

Select the cloud service the virtual machine belongs to: monitor-tab > add metrics and then add rule.

Azure Cross-Platform Command-Line Interface (xplat-cli)

Instructions how to install and run xplat-cli in Ubuntu 14.04 LTS with bash.

Installation

xplat-cli runs on node.js platform so install node.js first.

sudo apt-get install nodejs-legacy npm

Install bash completion too:

sudo apt-get install bash-completion

Install xplat-cli and configure bash completion:

sudo npm install -g azure-cli
# bash completion
azure --completion >> ~/azure.completion.sh
sudo mv ~/azure.completion.sh /etc/bash_completion.d/azure
sudo chown root.root /etc/bash_completion.d/azure
sudo chmod 0644 /etc/bash_completion.d/azure

Update

Later you'll need to update xplat-cli:

sudo npm update -g azure-cli

Update the bash completion too.

Login with account based authentication

Account based authentication relies on tokens that will expire at some point so re-authentication will be required. Two different types of accounts can be used:

Login with Microsoft account requires one to open a web page where one have to enter an authentication code provided by the azure login command.

Note that you can log in to multiple accounts at the same time.

# 1. login/logout with Azure organizational account
azure login -u <USERNAME>
azure logout -u <USERNAME>
# 2. login/logout with Microsoft account
azure login <USERNAME>
azure logout <USERNAME>
# list the imported subscriptions
azure account list
# show subscription details
azure account show [SUBSCRIPTION]
# Set the current subscription
account set <SUBSCRIPTION>

Login with a certificate

Earlier known also as a publishsettings file.

The certificate never expires.

Set Mode

Use Azure Resource Manager (ARM). Resource Manager overview. The ARM is not the default mode.

# set Azure Resource Management (ARM) mode
azure config mode arm

Create Azure Linux VM

Useful resources:

List available VM images:

# all images
azure vm image list
# Ubuntu 14.04 LTS images
azure vm image list | grep -ie 'ubuntu-14_04.*lts'

List available VM locations:

azure vm location list

List your virtual machines:

azure vm list

Generate certificate:

# generate an X509 certificate with a 2048-bit RSA keypair
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myPrivateKey.key -out myCert.pem
# secure the private key
chmod 600 myPrivateKey.key
  • myPrivateKey.key is the private key that have to be kept secret
  • myCert.pem is the public key

Create a virtual machine:

azure vm create --userName <USERNAME> --location <LOCATION> --vm-size Small --ssh 323 --ssh-cert <CERT_FILE> --no-ssh-password <DNS_NAME> <IMAGE>
# example:
# azure vm create --userName devoops --location "West Europe" --vm-size Small --ssh 323 --ssh-cert /tmp/myCert.pem --no-ssh-password devoops-1 b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20141125-en-us-30GB

Add SSH endpoint ACL:

azure vm endpoint acl-rule create --vm-name <NAME> --endpoint-name <NAME> --order <ORDER> --action <ACTION> --remote-subnet <SUBNET> --description <DESCRIPTION>
# example:
# azure vm endpoint acl-rule create --vm-name devoops-1 --endpoint-name ssh --order 1 --action permit --remote-subnet 88.123.174.67/32 --description 'home office'

Export VM role file the can be used later with vm create-from to re-create the VM. See also Exporting and Importing VM settings with the Azure Command-Line Tools.

azure vm export <VM_NAME> <ROLE_FILE>
# example:
# azure vm export devoops-1 devoops-1.json
azure vm delete <VM_NAME>
# example:
# azure vm delete devoops-1
azure vm create-from --location <LOCATION> --ssh-cert <CERT_FILE> <VM_NAME> <ROLE_FILE>
# example:
# azure vm create-from --location "West Europe" --ssh-cert devoops-1.pem devoops-1 devoops-1.json

Create Azure Blob Storage

Useful tools:

The storage URL is in format:

https://<STORAGE_ACCOUNT_NAME>.blob.core.windows.net/<CONTAINER>/<BLOB>

Note that there is really only one container level-hierarchy. If the URL seems to have more containers they are in fact part of the blob name.

Create new storage account and set the access key:

# list accounts
azure storage account list
# create new account
azure storage account create --label <LABEL> --description <DESCRIPTION> --location <LOCATION> --type <TYPE> <STORAGE_ACCOUNT_NAME>
# example:
azure storage account create --label devoops --description 'Devoops files.' --location 'North Europe' --type LRS devoops
# list account keys
azure storage account keys list <STORAGE_ACCOUNT_NAME>
# set environment access variables so that the credentials have not to be given every time with storage commands 
export AZURE_STORAGE_ACCOUNT=devoops
export AZURE_STORAGE_ACCESS_KEY=<ACCESS_KEY>

Create new container:

# list containers
azure storage container list
# create new container
azure storage container create --permission <PERMISSION> <CONTAINER>
# example:
azure storage container create --permission Container vagrant

List blobs in container:

azure storage blob list <CONTAINER>

Docker

  1. Docker Get Started

SSH

Configuration file: ~/.ssh/config

# default identity
IdentityFile <PATH_TO_PRIVATE_KEY>
HashKnownHosts yes
IdentitiesOnly yes

Host <HOSTNAME>
  IdentityFile <PATH_TO_PRIVATE_KEY>
  Port <PORT>
  User <USERNAME>

Generate ssh-keys:

$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/foo -C 'me@example.com'
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/<USER>/.ssh/foo.
Your public key has been saved in /home/<USER>/.ssh/foo.pub.
The key fingerprint is:
77:b8:84:59:f8:74:21:66:bf:b2:fd:24:85:3c:cc:d2 me@example.com
The key's randomart image is:
+--[ RSA 4096]----+
|          + .    |
|         + o .   |
|        . o o    |
|         * B o   |
|        S B E .  |
|         o B o   |
|          o o .  |
|             +   |
|              .  |
+-----------------+
$

See also: https://help.github.com/articles/generating-ssh-keys/

SSH agent:

# start the agent
$ eval $(ssh-agent -s)
# add keys
$ ssh-add
# list loaded keys
$ ssh-add -l

SSL Certificates

Get server certificates:

echo -n | openssl s_client -connect <HOST>:443 -showcerts

Save server certificate (1st in the chain) to a file (PEM/DER). Note the other certificates in the chain are ignored:

# PEM
echo -n | openssl s_client -connect <HOST>:443 -showcerts | openssl x509 -out cert.pem​
# DER
echo -n | openssl s_client -connect <HOST>:443 -showcerts | openssl x509 -outform der -out cert.der

Show certificate information:

openssl x509 -in cert.pem -noout -text

Certificate fingerprints:

openssl x509 -in cert.pem -noout -sha256 -fingerprint
openssl x509 -in cert.pem -noout -sha1 -fingerprint
openssl x509 -in cert.pem -noout -md5 -fingerprint

Subversion

Use -R option for recursion.

svn propset svn:ignore -F .svnignore .
svn proplist -v
svn propget svn:ignore
svn propdel svn:ignore .

Linux

CentOS

# become root
$ sudo su -
# update packages
$ yum check-update
$ yum update

Ubuntu

  1. How To Find The Configure Options Used To Build An Ubuntu Package
  2. How To Find An Installed Ubuntu Package Version
  3. How To Find Ubuntu Version
  4. How To Connect Azure SQL Database From Ubuntu

Replace A String In File

perl -pi.bak -e 's/<OLD>/<NEW>/g' <FILE>

Random String

openssl rand -base64 32

Vagrant

TODO

Troubleshooting ssh configuration:

# vagrant ssh configuration
vagrant ssh-config
# print debugging messages 
vagrant ssh -- -v

Updated