Sie sind auf Seite 1von 62

We Are All DevOps

Everything is a file
Finding Disks
/dev/sdX

/dev/sdX{i}

/dev/disk/by-uuid/98affd0e-9d3e-49c1-
bb66-a60119642462

/dev/disk/by-path/pci-0000:00:07.1-
scsi-0:0:0:0
Special Files
/dev/zero

/dev/null

/dev/(u)random

/dev/dsp
Poking The Kernel With ProcFS
root@keyserver:~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family: 6
model : 15
model name: Intel(R) Xeon(R) CPU E7440 @ 2.40GHz
stepping: 1
cpu MHz : 2400.070
cache size: 16384 KB
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx lm
constant_tsc up arch_perfmon pebs bts rep_good pni ssse3 cx16 lahf_lm
bogomips: 4813.70
clflush size: 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
root@keyserver:~# cat /proc/meminfo

MemTotal: 253072 kB
MemFree: 7448 kB
Buffers: 25804 kB
Cached: 52552 kB
SwapCached: 4696 kB
Active: 156728 kB
Inactive: 25292 kB
SwapTotal: 522216 kB
SwapFree: 494832 kB
http://www.redhat.com/advice/tips/meminfo.htm
Set Swappyness
echo 0 > /proc/sys/vm/swappiness

echo "vm/swappiness=0" >>


/etc/sysctl.conf
Hotadd CPU
echo 1 > /sys/devices/system/cpucpu2/online
Getting By On The CLI
Don't Know A Command? - Apropos
How Apropos
Use Screen
● Survive disconnects
● Multiple sessions
● Split screen
● Share Screens
Get Bash Completion
tomh$ brew install bash-completion

# ~/.bash_profile

if [ -f `brew --prefix`/etc/bash_completion ]; then


. `brew --prefix`/etc/bash_completion
fi

tomh$ ln -s `brew
--prefix`/Library/Contributions/brew_bash_completion.sh `brew
--prefix`/etc/bash_completion.d/
Using It
Performance Tools
top
iostat
vmstat
free
Finding Files
Find – Old Files
find /path/to/files* -mtime +NUMDAYS
Find – Big Files
find / -type f -size +200M
Found it? Do stuff to it
find / -type f -size +200M -exec ls -lh {} \;
locate
xargs
ps ax | grep apache | awk '{ print $1 }' | xargs kill
Sed and Awk

● Can do lots with them


● By lots I mean anything
● You probably don't want to write a Energy Price
Comparison site in them
Files and File Handles
Make a file
root@ubuntu-vm:/home/tom# mkdir /mnt/1G
root@ubuntu-vm:/home/tom# mount /dev/sdb /mnt/1G/
root@ubuntu-vm:/home/tom# cd /mnt/1G/
root@ubuntu-vm:/mnt/1G# dd if=/dev/urandom of=500M bs=1M
count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 100.04 s, 5.2 MB/s
Some App Uses It
>>> f = open('/mnt/1G/500M')
You Remove It
root@ubuntu-vm:/mnt/1G# rm 500M
root@ubuntu-vm:/mnt/1G# ls
.lost+found
du is blind
root@ubuntu-vm:/mnt/1G# du -hs .
20K .
df can see
root@ubuntu-vm:/mnt/1G# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 3.0G 15G 17% /
none 243M 208K 243M 1% /dev
none 249M 168K 249M 1% /dev/shm
none 249M 108K 249M 1% /var/run
none 249M 0 249M 0% /var/lock
/dev/sdb 1008M 534M 424M 56% /mnt/1G
lsof to the rescue
root@ubuntu-vm:/mnt/1G# lsof | grep /mnt/1G
bash 1857 root cwd DIR 8,16 4096 2 /mnt/1G
bash 1946 tom cwd DIR 8,16 4096 2 /mnt/1G
bash 1985 tom cwd DIR 8,16 4096 2 /mnt/1G
python 2007 tom cwd DIR 8,16 4096 2 /mnt/1G
python 2007 tom 3r REG 8,16 524288000 12
/mnt/1G/500M (deleted)
su 2011 root cwd DIR 8,16 4096 2 /mnt/1G
bash 2020 root cwd DIR 8,16 4096 2 /mnt/1G
lsof 2176 root cwd DIR 8,16 4096 2 /mnt/1G
grep 2177 root cwd DIR 8,16 4096 2 /mnt/1G
lsof 2178 root cwd DIR 8,16 4096 2 /mnt/1G
logrotate
Send A Signal
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid`
endscript
}
CopyTruncate
/path/to/any/app/*log {
missingok
notifempty
sharedscripts
copytruncate
}
nginx does it right
You can too
Signal.trap("USR1") {DO_STUFF}
Dont kill -9
Don't rescue Exception
Scheduling Things
Cron
/etc/cron.daily/
/etc/cron.hourly/
/etc/cron.monthly/
/etc/cron.weekly/

Puppet

sudo gem install cronedit


Using upstart to manage processes
root@ubuntu-vm:/etc/init# cat vmware-tools.conf
description "VMware Tools services"
author "VMware, Inc."

# Be sure to block the display managers until our job has


completed. This
# is to make sure our kernel services are running before
vmware-user
# may launch.
start on runlevel [235] or starting gdm or starting kdm or
starting prefdm
stop on runlevel [06]

pre-start exec /etc/vmware-tools/services.sh start


post-stop exec /etc/vmware-tools/services.sh stop
start on runlevel [2345]
stop on runlevel [06]

respawn
expect fork

script
export HOME="/home/deploy"
export JAVA_HOME="/usr/lib/jvm/java-6-sun"
export HIVE_HOME="/usr/lib/hive"
export HADOOP_HOME="/usr/lib/hadoop"

HIVE_PORT=10001 $HIVE_HOME/bin/hive --service hiveserver&


HIVE_PORT=10002 $HIVE_HOME/bin/hive --service hiveserver&
HIVE_PORT=10003 $HIVE_HOME/bin/hive --service hiveserver&
HIVE_PORT=10004 $HIVE_HOME/bin/hive --service hiveserver&
HIVE_PORT=10005 $HIVE_HOME/bin/hive --service hiveserver&
end script
Stopping Processes Running Amok
nice
nice <INCREMENT> <COMMAND>

renice <INCREMENT> <PID>


ionice
ionice -c {1/2/3} <COMMAND>

ionice -c {1/2/3} -p <PID>

1: real time
2: for best-effort
3: for idle
Installing Applications
● Use system .debs where possible
● Author debs
● PPA
● Compile
● Make own .debs
● Be the PPA
Waxing Philosophical
There is one system, not a collection of systems.
The desired state of the system should be a known
quantity.
The "known quantity" must be machine parseable.
The actual state of the system must self-correct to the
desired state.
The only authoritative source for the actual state of the
system is the system.
The entire system must be deployable using source media
and text files
Hate SPOF

● 10th Floor Test

● Big Red Bus


Global Ownership
Ops
● Its the network
● It's the storage
● It's the virtualisation
● It's the DB

Dev
● It's the JS
● It's the DB
Nirvana
● There are no Ops
● Puppet is probably involved
Links
● http://aperiodic.net/screen/quick_reference
● http://www.planetdevops.net/
● http://blog.websages.com/2010/12/10/jameswhite-manifesto
● http://video2010.scottishrubyconference.com/show_video/6