Wiki
Clone wikidevoops / Home
Dev...oops!
Ansible
How to install Ansible to Ubuntu 14.04 LTS:
#!bash
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
Azure
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
- Install and Configure the Azure Cross-Platform Command-Line Interface
- Sources in GitHub
- Release notes
- Azure command-line tool for Mac and Linux
xplat-cli runs on node.js platform so install node.js first.
#!bash
sudo apt-get install nodejs-legacy npm
Install bash completion too:
#!bash
sudo apt-get install bash-completion
Install xplat-cli and configure bash completion:
#!bash 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:
#!bash
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:
- Microsoft account
- Azure organizational accounts
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.
#!bash # 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.
#!bash # set Azure Resource Management (ARM) mode azure config mode arm
Create Azure Linux VM
Useful resources:
- Introduction to Linux on Azure
- Create a Virtual Machine Running Linux
- Endorsed Linux distributions on Azure
List available VM images:
#!bash # 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:
#!bash
azure vm location list
List your virtual machines:
#!bash
azure vm list
Generate certificate:
#!bash # 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 secretmyCert.pem
is the public key
Create a virtual machine:
#!bash 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:
#!bash 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.
#!bash azure vm export <VM_NAME> <ROLE_FILE> # example: # azure vm export devoops-1 devoops-1.json
#!bash azure vm delete <VM_NAME> # example: # azure vm delete devoops-1
#!bash 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:
- https://cyberduck.io/
- https://duck.sh/
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:
#!bash # 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:
#!bash # 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:
#!bash
azure storage blob list <CONTAINER>
Docker
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:
#!bash $ 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:
#!bash # start the agent $ eval $(ssh-agent -s) # add keys $ ssh-add # list loaded keys $ ssh-add -l
SSH local port forwarding:
#!bash # LOCALPORT will be forwarded to <REMOTEHOST>:<REMOTEPORT> via <JUMPHOST> $ ssh -fN -L <LOCALPORT>:<REMOTEHOST>:<REMOTEPORT> <USER>@<JUMPHOST>
SSH key based authentication:
#!bash # $ man -f ssh-copy-id ssh-copy-id (1) - install your public key in a remote machine's authorized_keys $ ssh-copy-id <USER>@<HOST>
sshd
essential configuration (/etc/ssh/sshd_config
):
PasswordAuthentication no PermitRootLogin no
Restart sshd
in CentOS7: systemctl restart sshd.service
Subversion
Use -R
option for recursion.
#!bash
svn propset svn:ignore -F .svnignore .
svn proplist -v
svn propget svn:ignore
svn propdel svn:ignore .
Linux
CentOS
#!bash # become root $ sudo su - # update packages $ yum check-update $ yum update
Ubuntu
- How To Find The Configure Options Used To Build An Ubuntu Package
- How To Find An Installed Ubuntu Package Version
- How To Find Ubuntu Version
- How To Connect Azure SQL Database From Ubuntu
Replace A String In File
#!bash perl -pi.bak -e 's/<OLD>/<NEW>/g' <FILE>
Random String
#!bash openssl rand -base64 32
Vagrant
TODO
- My Vagrant Base Boxes
- Box search
- https://www.vagrantup.com/
- https://atlas.hashicorp.com/
- Keep VirtualBox guest additions up-to-date with https://github.com/dotless-de/vagrant-vbguest
Troubleshooting ssh configuration:
#!bash # vagrant ssh configuration vagrant ssh-config # print debugging messages vagrant ssh -- -v
Updated