Monday, April 9, 2012

SA class 6





periodic process                 #    do things at right time automatically

cron deamon
    wakes up every minute and reads the cron table and executes command on time
    /etc/rc.c/cron               # FreeBSD
    /etc/cron.d                  # Linux
    portaudit


crontab (cron table)
    "user's" cron
    named the uid
    under /var/cron/tabs         # FreeBSD
    /etc/crontab                 # system cron


configution                      # use crontab -e
    ignored blank lines or leading spaces and tabs
    comments start with '#'

    env setting                  # important
        name=value
        LOGNAME
        SHELL
        PATH                     # full pathname is better
        HOME
        MAILTO                   # to record outputs and send to your mailbox

    format
        min hour day month weekday command
            minute      0 .. 59
            hour        0 .. 23
            day         1 .. 31
            month       1 .. 12
            weekday     0 ..  6  # 0 for Sunday

        matche rules
            * everything
            - matches ranges
            , listed value
            / skips of the number's value through the range

            special strings
                @reboot          # once at startup
                @yearly          # once a year         0 0 1 1 *
                @annually        # the same
                @monthly         # once a month        0 0 1 * *
                @weekly          # once a week         0 0 * * 0
                @daily           # once a day          0 0 * * *
                @midnight        # the same
                @hourly          # once an hour        0 * * * *


'crontab' command
    crontab -e
        edit user's cron with your editer such as 'vim'

    crontab -l
        list the crontab

     crontab -r
        remove the crontab

    crontab filename
        install filename as your crontab

    to allow and deny users
        /var/cron/{allow,deny}

system crontab
    /etc/crontab
    min hour mday month wday who command
                             ^^^
    control the permission as who

periodic
    in /etc/crontab

    periodic daily
             weekly
             monthly
    /etc/defaults/periodic.conf
    /usr/ports/ports-mgmt/portaudit


'at' command
    12:15am root@satest # at -t 201110200016
    echo Hello world
    ^D
    Job 2 will be executed using /bin/sh
    12:15am root@satest # atq
    Date                            Owner           Queue   Job#
    2011年10月20日 周四 00時16分00秒 CST    root            c       2

'atq'
    run jubs queueed by 'at'
    'atrun'  run per 5 min  see /etc/crontab
    /var/at/at.{allow,deny}
    batch exec commands when system load drops then 1.

===========================================

drivers and kernel

UNIX system
    user level programers
    kernel
    hardware

    kernel manages and resourtces
        CPU process managemant
        memory managemant
        I/O devices managemant

    kernel provides methods for
        IPC inter-process communication
        process request resources
            system call

                      user applications
          +-- Kernel ---------- | ---------------------+
          |            syscall interface               |
          |            |               |               |
          |            V               V               |
          |      filesystem        process control     |
          |           |            IPC, scheduler      |
          |      device drivers    memory managemant   |
          |               |            |               |
          |               hardware control             |
          +------------------- |  ---------------------+
                            hardware




kernel-wide design approaches
    monolithic kernels
        kernel space, shared memorym fast
        Linux, BSD, M$ 9x- ...

    microkernels
        user space, message passing, slow
        Mac OS X, GNU Mach

    Hybrid
        Monolithic + Micro
        M$ NT+

    other
        Nanokernels
        Exokernels


FreeBSD kernel
        monolithic -> modular
        cannot be dynamical loadable

    customized VS GENERIC
        fast boot time
        lower memory usage
        additional hardware support
        fine-tune system performance


finding system hardware
    dmesg
        cat /var/run/dmesg.boot
        pciconf -lv
    kldstate
    kldload
        /boot/kernel/*.ko
        xx_xxx_load="YES"
    kldunload


building FreeBSD source tree
    sysinstall
        configure -> disrtiburion -> src -> all


customized kernel comfiguration file
    sample files
    /usr/src/sys/<ARCH>/conf     # <ARCH> for i386 or amd64
        GENERIC, NOTES, LINT (generated by 'make LINT') <--- to find drivers
    /usr/src/sys/conf/NOTES      # for arch independent options


customized file
    cp GENERIC /usr/local/etc/KERNEL5566
    ln -s /usr/local/etc/KERNEL5566 /usr/src/sys/<ARCH>/conf


building a kernal
    cd /usr/src
    make buildkernel KERNCONF=KERNEL5566
    make installkernel KERNCONF=KERNEL5566
    make kernel = make buildkernel + make installkernel

    kernel locatinos
        /boot/kernel/kernel
        /boot/kernel -> /boot/kernel.old

    when somethings goes wrong
        config failed            # typo
        make failed              # fucking errors code 123
                                 # look over your configuration
                                 # or send mails for FreeBSD question mailing
list
        boot failed
            ok mode              # it means your kernel is not ok
                boot kernel.old
                unload kernel && load/boot/kernel.old && boot

            ps failed
                recompile and install a word

        sysctl command
            dynamically set or get kernel parameters


        /etc/sysctl.conf
        /boot/loader.conf

================================

disk
    interface
    geometry
    add new dicks
        install procedure
        filesystem check
        add a disk using 'sysintall'
    RAID
        GEOM


disk interface
    SCSI                         # expensive
    IDE / ATA
    SATA
    SAS
    USB


disk geometry
    secrot
        indivifual data block
    track
        circle
    cylinder
        circle on all platters
    posision
        CHS
        cylinder, head, sector


disk installation procedure
    connecting the disk
        IDE : master/slave
        SATA
        SCSI : ID, terminator
        power!                   # the most important

    creating device files
        auto created by 'devfs'

    formatting
        low-level
        manufacturer diagnostic utility

    partition and lable
        allow the disk to be treated as a group of independent data
            Ex. root, home, swap partition

        suggestion
            /var, /tmp => separate partition
        establishing logical volumes
        compine multiple partitions into a logical volume
            software RAID
                GEOM
                ZFS

        'newfs' command
            superblock contents  # before i-list
                inode table's size and location
                disk block map
                usage information
                other filesystem’s parameters

        'sync'

        mount
        Ex.
            mount /dev/ad1s1e /home2

        automount at boot time
            write it in /etc/fstab

       swap
            swapon, swapoff, swapctl
            swapinfo, pstat

        'fsck'
            system crash will cause
                inconsistency between memory image and disk contents
         fsck
            examine all local filesystem listed in /etc/fstab at boot time.
(fsck -p)
            automatically correct the following damages:
                unreferenced inodes
                inexplicably large link counts
                unused data blocks not recorded in block maps
                data blocks listed as free but used in file
                incorrect summary information in the superblock



RAID                             # redundant array of inexpensive disks
                                 # combine several physical hard drives into a
logical unit
    features
        fault tolerance
        higher throughput
        real-time recovery
    level
        0~6
        hierarchicak RAID (0 + 1)

    hardware RAID

    software RAID


level
    RAID 0
        500 + 500 = 1000
        stripped data intro several disks
        minimum numbers of drivers: 2
        advantage
            performance
        disadvantage
            no fault tolerance

    RAID 1
        500 + 500 = min (500, 500) = 500
        minimum numbers of drivers: 2

        advantage
            100% redundary of data
        disadvantage
            100% storage overage
            slow write performance

        Hardware and software
            GEOM, ZFS

    RAID 2
        Hamming Code ECC each bit data word

    RAID3 and RAID 4
        blocks by blocks
        bytes by bytes
        parallel transfer with Parity
        minimum number of drives: 3

        advantages:
            very high data transfer rate

        disadvantages:
            transaction rate equal to that of a single disk drive at best

    RAID 5 and RAID 6
        independent Disk with distributed parity blocks
        minimum number of drives: 3/4

        advantage:
            highest read data rate
            medium write data rate

        disadvantage:
            disk failure has a medium impact on throughput
            complex controller design
            when one disk failed, you have to rebuild the RAID array
            "write hole" problem

you will see

    0,           1,    5,        6
    performance, safe, average , more safer than 5



GEOM
    ELI
    JURNAL
    LABEL
    MIRROR
    SRIPE


major RAID control utilities
kernel modules
    /boot/kernel/geom_*


kernel support
    {glabel,gmirror,gstripe,g*} load/unload
    device GEOM_* in kernel config
    geom_*_enable=“YES” in /boot/loader.conf


LABLE
    for GEOM provider labelization
    kernel
        device GEOM_LABEL
        geom_label_load=“YES”
    'glable' command
        # glabel label -v usr da2
        # newfs /dev/label/usr
        # mount /dev/label/usr /usr
        # glabel stop usr
        # glabel clear da2


MIRROR  # for RAID 1
    kernel
        device GEOM_MIRROR
        geom_mirror_load=“YES”
    'gmirror' command
        # gmirror label -v -b round-robin data da0
        # newfs /dev/mirror/data
        # mount /dev/mirror/data /mnt
        # gmirror insert data da1
        # gmirror forget data                <---- this is so funny
        # gmirror insert data da1
        # gmirror stop data
        # gmirror clear da0


SRIPTE # for RAID0
    kernel
        device GEOM_STRIPE
        geom_stripe_load=“YES”
    'gstripe' command
        # gstripe label -v -s 131072 data da0 da1 da2 da3
        # newfs /dev/stripe/data
        # mount /dev/stripe/data /mnt
        # gstripe stop data
        # gstripe clear da0

No comments:

Post a Comment