KEMBAR78
Linux Administration for Developers | PDF
Linux Administration for Developers
                by
         Mahmoud Said
Outline

●   Why
●   Linux Basics
●   Servers
●   WTF
●   More monitoring tools




                                 2
Why

●   Free
●   Hosting Open Source web apps
●   Developing Open Source apps
●   Robustness
●   Development by Community




                                   3
Why




Admin   Common
        Knowledge   Developer




                                4
Linux Basics




               5
Filesystem

“Everything is a file”        ●   Regular files
                              ●   Directories
                              ●   Symbolic links
                              ●   Hard links
                              ●   Devices
                              ●   Sockets




                                                   6
Filesystem - Filenames

●   Case sensitive
●   Can contain any character except “/”
●   Extensions are only used for user convenience
●   Examples:
    README       .bashrc    index.html
    My World     conf.old    database.yml.bak




                                                    7
Filesystem – File pathes

●   Sequence with nested directories ending with or
    without a file
●   Relative: config/database.yml
●   Absolute: /etc/nginx/nginx.conf
●   Special pathes:
      ~/     #home of current user
      /      # root
      ..     # parent directory


                                                      8
Shells

●   Interface to execute user commands
●   Hide the details of the OS
●   Text based Commands
●   Can be scripted




                                         9
Famous Shells

●   sh The Bourne shell (obsolete)
    Traditional, basic shell found on Unix systems, by Steve
    Bourne.
●   csh The C shell (obsolete)
    Once popular shell with a C-like syntax
●   bash The Bourne Again shell (most popular)
    An improved implementation of sh with lots of added features.




                                                                    10
Scripting

●   Commands to the shell can be scripted
●   The script can be passed to the interpreter, or it can be
    executed by specifying the interpreter at the beginning

bash init.sh.old                       #!/bin/bash
./init.sh.old                          echo “bash script...”


ruby setup.rb                          #!/usr/bin/ruby
./setup.rb                             puts “ruby script...”


                                                                11
Common bash commands

pwd           cat       find
ls            less      sort
cp            more      wc
cd            vim       alias
man           nano      echo
mkdir         tail      ln
mv            head      chmod
rm            grep      chown
rmdir         crontab


                                12
Bash Keyboard commands

●   TAB        # auto completion
●   CTRL+R     # search commands history
●   CTRL+D     # exit the current shell
●   CTRL+P     # previous command (also “up”)
●   CTRL+N     # next command         (also “down”)
●   CTRL+L     # clear screen




                                                      13
Standard I/O & piping

●   Redirect output to a file using “>”
●   Append output to a file using “>>”
●   Obrain input from a file using “<”
●   Redirect output as input to another process (piping) “|”




                                                           14
Servers




          15
ssh access

●   Using password
●   Public/private key pair
    ssh user@35.231.23.120 -p5022   ( default 22)




                                                    16
Important paths

/usr/local/project   Root directory (capistrano convension)
/var/log/            all important logs
/etc/                system configuration files
/etc/init.d/         startup scripts




                                                              17
Uploading/Downloading files

●   scp scr_file user@server.com:/dst_path/
●   wget http://www.akhbarak.net/traces.log.gz




                                                 18
Server Anatomy


   Web server

                     Memcache

Application server


                      Indexer

    Database




                                19
WTF!!




        20
WTF

●   Something wrong
●   Too few details
●   Admin/dev related




                              21
Identifying the problem

●   Browser/Firebug
●   Isolating the request
●   Logs
        –   Application logs
        –   Web server logs
        –   Other logs
●   Rails console


                                       22
System status

●   System load/CPU   (top)
●   IO                (iotop)
●   Memory            (free -m, top)
●   Check processes   (ps aux | grep ruby)
●   ….




                                             23
Monitoring Tools




                   24
Newrelic.com

●   Multiple technologies
●   Performance analysis
●   Server monitoring
●   Traces of errors & slow requests




                                       25
Thank You




            26

Linux Administration for Developers

  • 1.
    Linux Administration forDevelopers by Mahmoud Said
  • 2.
    Outline ● Why ● Linux Basics ● Servers ● WTF ● More monitoring tools 2
  • 3.
    Why ● Free ● Hosting Open Source web apps ● Developing Open Source apps ● Robustness ● Development by Community 3
  • 4.
    Why Admin Common Knowledge Developer 4
  • 5.
  • 6.
    Filesystem “Everything is afile” ● Regular files ● Directories ● Symbolic links ● Hard links ● Devices ● Sockets 6
  • 7.
    Filesystem - Filenames ● Case sensitive ● Can contain any character except “/” ● Extensions are only used for user convenience ● Examples: README .bashrc index.html My World conf.old database.yml.bak 7
  • 8.
    Filesystem – Filepathes ● Sequence with nested directories ending with or without a file ● Relative: config/database.yml ● Absolute: /etc/nginx/nginx.conf ● Special pathes: ~/ #home of current user / # root .. # parent directory 8
  • 9.
    Shells ● Interface to execute user commands ● Hide the details of the OS ● Text based Commands ● Can be scripted 9
  • 10.
    Famous Shells ● sh The Bourne shell (obsolete) Traditional, basic shell found on Unix systems, by Steve Bourne. ● csh The C shell (obsolete) Once popular shell with a C-like syntax ● bash The Bourne Again shell (most popular) An improved implementation of sh with lots of added features. 10
  • 11.
    Scripting ● Commands to the shell can be scripted ● The script can be passed to the interpreter, or it can be executed by specifying the interpreter at the beginning bash init.sh.old #!/bin/bash ./init.sh.old echo “bash script...” ruby setup.rb #!/usr/bin/ruby ./setup.rb puts “ruby script...” 11
  • 12.
    Common bash commands pwd cat find ls less sort cp more wc cd vim alias man nano echo mkdir tail ln mv head chmod rm grep chown rmdir crontab 12
  • 13.
    Bash Keyboard commands ● TAB # auto completion ● CTRL+R # search commands history ● CTRL+D # exit the current shell ● CTRL+P # previous command (also “up”) ● CTRL+N # next command (also “down”) ● CTRL+L # clear screen 13
  • 14.
    Standard I/O &piping ● Redirect output to a file using “>” ● Append output to a file using “>>” ● Obrain input from a file using “<” ● Redirect output as input to another process (piping) “|” 14
  • 15.
  • 16.
    ssh access ● Using password ● Public/private key pair ssh user@35.231.23.120 -p5022 ( default 22) 16
  • 17.
    Important paths /usr/local/project Root directory (capistrano convension) /var/log/ all important logs /etc/ system configuration files /etc/init.d/ startup scripts 17
  • 18.
    Uploading/Downloading files ● scp scr_file user@server.com:/dst_path/ ● wget http://www.akhbarak.net/traces.log.gz 18
  • 19.
    Server Anatomy Web server Memcache Application server Indexer Database 19
  • 20.
  • 21.
    WTF ● Something wrong ● Too few details ● Admin/dev related 21
  • 22.
    Identifying the problem ● Browser/Firebug ● Isolating the request ● Logs – Application logs – Web server logs – Other logs ● Rails console 22
  • 23.
    System status ● System load/CPU (top) ● IO (iotop) ● Memory (free -m, top) ● Check processes (ps aux | grep ruby) ● …. 23
  • 24.
  • 25.
    Newrelic.com ● Multiple technologies ● Performance analysis ● Server monitoring ● Traces of errors & slow requests 25
  • 26.