Top Banner
SYSTEMS ADMINISTRATION FOR CODERS Hints & tips to increase reliability & reduce maintenance time.
27

Systems administration for coders presentation

Jul 30, 2015

Download

Technology

Matt Willsher
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Systems administration for coders presentation

SYSTEMS ADMINISTRATION FOR

CODERSHints & tips to increase reliability & reduce

maintenance time.

Page 2: Systems administration for coders presentation

WHAT IS A SYSTEM?An assemblage or combination of things or parts

forming a complex or unitary whole.

Imported Author
Part forming a whole.Key part is ‘whole’
Page 3: Systems administration for coders presentation

WHAT DOES A SYSTEMS ADMINISTRATOR DO?

• Introduces new technologies into an environment

• Analyses system logs and identifies potential issues with a system.

• Plans and performs routine maintenance

• Performs and maintains backups

• Installs and configures new software and hardware

Page 4: Systems administration for coders presentation

WHAT DOES A SYSTEMS ADMINISTRATOR DO?

• Manages user accounts

• Responsibility for security

• Responsibility for documentation of the system

• Plans systems upgrades and outages to apply upgrades

• Troubleshooting reported problems

• Deals with, often frustrated, system users...  ... etc. etc.

Page 5: Systems administration for coders presentation

A COMPUTER SYSTEM• Many components working together - software (application, web server, OS), hardware (disks, RAM, CPU) & others (networking equipment, switches, routers, load balancers)

• Provides stability and maintainability that underpins the entire application.

• Supports your software for its lifetime.

• Can provide parts of your application. Sometimes a problem has already been solved by some other software.

Page 6: Systems administration for coders presentation

START AT BEGINNING

• Start sysadmin tasks at the beginning of the project.

• Write tools to aid deployment.

• Write tools to set up environments.

• Iterate over these tools and stabilise for production

Imported Author
Easier at the beginningScriptsConfig management
Page 7: Systems administration for coders presentation

ENVIRONMENTS

• Dev, QA, Live

• Dev, Test, QA, UAT, Live ~~ Dev, Test, QA, UAT, Staging, Live

• The nearer they get to live, the closer the should resemble live.

• Dev environment should at least be the same major versions, preferably OS version.

• Vagrant is a useful tool for this.

Page 8: Systems administration for coders presentation

SSH

• Probably the most frequently used tool

• Forwarding SSH agent to allow key use remotely (e.g. git, hopping between servers)

• Tunnels for access to remote resources

• Reverse tunnels for remote access to local resource

• Easy to configure the client

Page 9: Systems administration for coders presentation

SSH-AGENT

• Generate keys >2048 bits (e.g. ssh-keygen -b 4096)

• ssh-add to load default key (~/.ssh/id_rsa)

• ssh-copy-id <server> to copy to remote server

• ssh -A <server> to forward agent back to local instance.

• Agent runs at login for modern Linux desktop, Mac OS.

Imported Author
Key is effectively a large password.Public key goes on the server to authenticate the user
Page 10: Systems administration for coders presentation

SSH-TUNNELS

• Local access to remote: ssh -L3307:localhost:3306 <server>

• Remote access to local: ssh -R:3307:localhost:3306 <server>

• SOCKS proxy: ssh -D5050 <server>

Imported Author
1st example - mysql -h localhost:3307 to connect on local machine2nd example - same, remote end* What’s allow is controlled by the server
Page 11: Systems administration for coders presentation

SSH CLIENT CONFIGURATION

• Per user configuration: ~/.ssh/config

• Config options can be set per host or via wild card, e.g. User, ForwardAgent, Hostname & many more

• manpage: ssh_config

Page 12: Systems administration for coders presentation

UNIX/LINUX PRINCIPLES• Most things in Linux & UNIX are text.

• Each command line tools does one task and does it well.

• Command line tools process text with relative ease.

• Much of the text is separated into fields - especially logs, or as key = value pairs.

• There are standard locations for many types of file.

Imported Author
Different to powershell where everything is an object
Page 13: Systems administration for coders presentation

BASIC TOOLS

• cat - display text

• grep - find text

• awk - field processing (and more)

• sed - search and replace text

• wc - count

• cut - simple field processing

• head, tail - print first and last lines of text

• sort - sort text

Imported Author
Live demo time :D
Page 14: Systems administration for coders presentation

LOCATION, LOCATION, LOCATION

• /etc - configuration

• /usr - read-only user data

• /var - variable length files (caches, logs, temporary files)

• /home - users' home directories

• /opt - optional applications

• /srv - served site specific data

• See the Filesystem Hierarchy Standard. Same across most distros

Page 15: Systems administration for coders presentation

VARIABLE LENGTH FILES

• /var/log - Logs go here

• /var/cache - Cached files

• Watch your permissions

• During normal operation, /usr, /opt should be able to be mounted read only

Imported Author
Permissions - security sensitive dataWatch you umask
Page 16: Systems administration for coders presentation

SOFTWARE DEPLOYMENT

• Use vendor supplied packages whenever possible:

• Reduces risk of misconfigurations

• Easier to seek help

• Usually well tested

• Easier upgrades, timely security fixes

• Building from source will take a fair amount of time, CPU

• Ruby may be an exception. PHP isn't

Page 17: Systems administration for coders presentation

CHOICE OF LINUX DISTRIBUTION

• Two main camps - Debian and RedHat

• Red Hat Enterprise Linux is rock solid but expensive & packages tend to be older. CentOS is Enterprise Linux recompiled from the same source RPMs.

• Debian stable is rock solid but packages tend to be old. Community/3rd party support only.

• Ubuntu LTS is pretty solid, packages are more recent than EL. Well supported in the Cloud - AWS, OpenStack especially.

Page 18: Systems administration for coders presentation

SOURCE OF PACKAGES

• Use as stable, well testing packages as much possible

• Ubuntu main, Debian stable ideally

• For EL distros, EPEL augments core packages well

• For EL, IUS provide recent versions of MySQL, PHP but is less well tested.

• Avoid one person repos, PPAs if at all possible.

Page 19: Systems administration for coders presentation

BUILDING FROM SOURCE

• Do not build on live servers. Deploy only compiled code.

• Ideally produce a package.

• Avoid if possible. Increased risk of problems - more moving parts.

Imported Author
CPU usage, RAM usage, Disk IO costsServers should be using their resource for serving
Page 20: Systems administration for coders presentation

DIAGNOSTICS

• Check disk space: df -h 100% full is bad.

• Check logs: /var/log, /var/log/syslog, /var/log/messages - get to know your logs.

• dmesg for hardware information.

• Check RAM (free -m) and CPU usage with top.

• Install sysstat package early on - sar will gather data. Also gives you iostat, vmstat, mpstat.

Imported Author
Demo top & free -m
Page 21: Systems administration for coders presentation

SECURITY

• Install denyhosts/fail2ban to help protect SSH.

• Disable SSH in as root, use SSH keys.

• Use host based firewalls, AWS security groups.

• Don’t run your servers as root. Try to split them over different users with clear paths between them. One user nginx, one. php-fpm

• Audit trials are useful.

Imported Author
Security is big area. Lots written on it
Page 22: Systems administration for coders presentation

BACKUPS

• Databases: Dump the DB, don’t take hot copies of the DB files,

• Make use of your hosting providers backup services.

• Make sure you can restore. Test regularly.

Page 23: Systems administration for coders presentation

PROCESS• Repeat manual tasks often

• Try to use the same deployment system across stages

• Get live up early, treat it as UAT and deploy to it regularly. Avoid 'big bang' deployment

• Use what suits - don't blindly follow trends, assess risks as suits the type of project.

• Small steps, iterative improvement. Agile, Kanban, Lean etc.

Imported Author
e.g compliling from source is probably fine for a low traffic blog.
Page 24: Systems administration for coders presentation

AUTOMATION• CFEngine, Puppet, Chef can get you quick wins. They can quickly become hard to manage. Learning curves are steep.

• Ansible is simple to get going on. Can be hacked at and still get good results. Data driven. Pretty new, but growing fast.

• Nothing wrong with shell/Python/Ruby/Perl scripts. Configuration management tools are not essential.

• Packaging gets you out of a lot of automation tasks.

Page 25: Systems administration for coders presentation

THAT’S A LOT OF STUFF!

• Not touched on DR, monitoring, OS provisioning, storage, networking...

• Hire a sys-admin :)

• A good sys-admin will work with you...

• ...to let you get on with the job you enjoy.