Introduction to System Configuration

Outline

  • Filesystem Hierarchy Standard
  • General System Configuration
  • Network Configuration
  • Syslog System

Filesystem Hierarchy Standard

Why FHS?

  • To make developer/user/manager have consistent environment.

  • Try the following command to see directory hierarchy

$ tree / -L <depth> 

Directory tree

Unix Software Resource (usr)

$(prefix)/bin        # binary files
$(prefix)/sbin       # system-usage binary files
$(prefix)/lib        # library file, object file (lib*.a, lib*.so, lib*.dylib, ...)                
$(prefix)/share      # reference file (manpage, example, ...)
$(prefix)/include    # library header file (*.h, *.hpp...)
$(prefix)/src        # software source code
$(prefix)/etc        # software configuration file
  • prefix
    • / : boot related
    • /usr : global user usage, package manager, admin level ... (apt-get, aptitude, yum ...)
    • /usr/local : developing usage, user level ... (software compiled by yourself)
    • /opt : some strange software... XD

Variable file

/var/cache     # process cache
/var/lib       # process data storage (e.g. database)
/var/lock      # process resource lock
/var/log       # process log message
/var/spool     # some queuing message (e.g. email)
/var/run       # process information (usually linking to /run)

Others

/boot                # For boot usage (grub configs are in /boot/grub/)                   
/dev                 # Computer Device
/run                 # process information (e.g. pid)
/media, /mnt         # Mounted filesystem (e.g. CD or USB ...)
/root, /home/$(user)
/tmp                 # Temporary file

# On Memory
/lost+found    # ext2/ext3 usage
/proc          # device info, process info (pid, openfile,...)
/sys           # system loaded module

General system configure files

  • Normally most system config file are located on /etc
    • file format and setting depend on OS/distribution/version
  • Naming
    • XXX.conf
    • XXX.d/
    • XXXrc

Account System

  • /etc/passwd

    [Format]
        account:password:uid:gid:userInfo:homeDirectory:loginShell                
    [Example]
    root:x:0:0:root:/root:/bin/bash
    math120908:x:41701:200:math120908:/home/dept/ta/math120908:/bin/bash
  • /etc/shadow

    [Example]
    root:$6$hOwDoyoUtUrNtHISOn:16184:0:99999:7:::

Account System (cont)

  • /etc/group
[Format]
    group:password:gid:userList
[Example]
root:x:0:
linuxadmin:*:62001:tmt514,tmtS14,TwT514,ta221,ta217,ta204,ta219,ta223
  • You can use following command to see specified entry

    $ getent passwd [username]
    $ getent group [groupname]

sysctl

  • Kernel dynamic module setting
    • Memory/file/network limits
  • sysctl tool

    $ sysctl -a                         # show all variables
    $ sysctl [variable]                 # read some variable
    $ sysctl -w [variable[=value] ...]  # write some variable                  

sudo

  • Run command as another user
    • Controlled by /etc/sudoers
    • Verify using your password
    • Give people limited superuser access
  • Different from su (change to another user)

Time

  • Timezone setting on /etc/timezone
  • Sync with NTP server configured on /etc/ntp.conf

Language (global)

  • Available language setting file
    • old: /etc/locale.gen
    • new: /var/lib/locales/supported.d/*
  • Use locale-gen to regenerate language file.
  • Use locale-gen <newlanguage> to add new language.

Language (user)

$ locale
LANG=zh_TW.Big5
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

Language (user)

  • Identity: language_zone.charset
  • Priority: LC_ALL > LC_* > LANG > LANGUAGE
  • Difference between LANG & LANGUAGE
    • LANG - Specifies the default locale for all unset locale variables
    • LANGUAGE - Most programs use this for the language of its interface
  • See referenceGNU gettext

Network configuration

Hostname

  • /etc/hostname
    • Set during boot
    • Stored in kernel
    • Not FQDN (w/o domain name)

Hostname Lookup

  • /etc/hosts
    • Static lookup table
    • All OS have it (even Windows)
    • Format: IP Hostname Alias

      140.112.30.46  linux15.csie.ntu.edu.tw linux15
  • /etc/resolv.conf
    • DNS Resolver (Name servers)
    • resolvconf package
      • Read DNS config from network config
      • Write settings to /etc/resolv.conf

/etc/network/interfaces

  • static

    auto eth0
    iface eth0 inet static
       address 140.112.30.46
       netmask 255.255.255.0
       network 140.112.30.0
       broadcast 140.112.30.255
       gateway 140.112.30.254
       dns-nameservers 140.112.30.21 140.112.254.4 140.112.2.2
       dns-search csie.ntu.edu.tw
       #up route add -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2                   
       #down route del -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
  • DHCP

    auto eth0
    iface eth0 inet dhcp
  • See details by man interfaces

Sytem Log Configuration

/var/log

  • Most Logs are stored in /var/log
  • Format: <time> <hostname> <process> <message>
  • Example:

General /var/log

  • System Level log

    dmesg          # Boot message log
    syslog         # Almost all log collected here
    messages       # Leave some error message
    auth.log       # Authendication Log
    wtmp, faillog  # User Logging Information
  • Application logs (Especially for daemon)

    [Example] mail.X, apt, apache, cups ...

Syslog configuration

  • Controlled by daemon syslogd
  • /etc/syslog.conf
  • Debian/Ubuntu moved to /etc/rsyslog.conf and /etc/rsyslog.d/
  • Example

Syslog configuration (explain)

  • Service Name

    auth, cron, daemon, kern, lpr, mail, news, syslog,       
    user, uucp, local0 ~ local7
    # local0 = postgresql
    # local2 = sudo
    # local3 = SpamAssassin
    # local4 = slapd

Syslog configuration (explain)

  • Level (priority)

    \* (all) > emerg (panic) > alert > crit > err (error) >           
    warn (warning) > notice > info > debug > none (nothing)
  • Format

    <service>.<level>    <logfile> # log service msgs >= level into logfile
    <service>.=<level>   <logfile> # log service msgs == level
    <service>.!<level>   <logfile> # log service msgs != level
    # logfile can be file, pipe, user, remote, ...etc 
    # note: hyphen before <logfile> means async to disk.
  • See manpage man rsyslog.conf or other reference for detail

Log Rotation

  • Why log rotate?
    • Archive
    • Categorize for search conveniently
    • Compress log to reduce disk usage
    • Drop too old logs

configuration

  • Files on /etc/logrotate.conf and /etc/logrotate.d/*
  • Example

    /var/log/syslog
    {
       rotate 7
       daily
       missingok
       notifempty
       delaycompress
       compress
       postrotate
          invoke-rc.d rsyslog rotate > /dev/null
       endscript
    }
  • See the parameter details by man logrotate

Command

  • Show logrotate procedure

    logrotate -v /etc/logrotate.conf             
  • Force logrotate

    logrotate -fv /etc/logrotate.conf            
  • Peform logrotate into file rotation -> savelog