Linux Fundamental (For ICT)

Course Objectives Understand basic about Linux System Install Linux Can work with most of Linux commands, including basic administration tips for network service and Apache, Mysql, Oracle ) Has basic background to study more if you want to become an expert At the end of this course, you can Understand basic about Linux System Install Linux Can work with most of Linux commands, including basic administration tips for network service and Apache, Mysql, Oracle ) Has basic background to study more if you want to become an ex

pdf101 trang | Chia sẻ: tlsuongmuoi | Lượt xem: 2429 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Linux Fundamental (For ICT), để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Linux Fundamental (For ICT) By : ICT/BA Date : Aug, 2008 Duration: 3 hours Revision : 1.0 17/09/2009 Confidential 2 Course Objectives At the end of this course, you can Understand basic about Linux System Install Linux Can work with most of Linux commands, including basic administration tips for network service and Apache, Mysql, Oracle … ) Has basic background to study more if you want to become an expert t t f t is rs , rst sic t Li x yst I st ll Li x rk it st f Li x c s, i cl i sic i istr ti ti s f r t rk s rvic c , ys l, r cl ) s sic ck r t st y r if y t t c x rt 17/09/2009 Confidential 3 Course Outline Introduction Basic concepts Installation Linux System Construction Boot sequence File system Basic Administration Basic commands Install/uninstall software Enable/disable services Linux in practice References Introduction Basic concepts Installation Linux Syste onstruction Boot sequence File syste Basic d inistration Basic co ands Install/uninstall soft are Enable/disable services Linux in practice eferences 17/09/2009 Confidential 4 Acronyms • GNU: General Public License • KDE: K Desktop Environment • GNOME: GNU Network Object Model Environment • FS: File System • CLI: Command Line Interface • LILO: Linux Loader • GRUB: Grand Unified Bootloader • : r l lic ic s • : skt ir t • : t rk j ct l vir t • : il yst • I: i I t rf c • I : i x r • : r ifi tl r Supplementary Slide 17/09/2009 Confidential 5 Section 1: Introduction Unix and Unix-based OS Unix is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs Unix-based OS: Solaris(Sun), HP-Unix(HP), BSD… Refer to References number 1 for Unix history What is linux? Unix-like system Linux was initially developed by Linus Torvalds in 1991 Linux family: refer to References number 5 detail of Linux distributions. Here, talk about: Debian, Red Hat, Fedora, Ubuntu … i i - s ix is c t r r ti syst ri i lly v l i y r f l y s t ll L s ix- s : l ris( ), - ix( ), f r t f r c s r f r ix ist ry t is li ix-lik syst Li x s i iti lly v l y Li s rv l s i Li x f ily: r f r t f r c s r t il f Li x istri ti s. r , t lk t: i , t, r , buntu 17/09/2009 Confidential 6 Basic Concepts 17/09/2009 Confidential 7 Basic Concepts Kernel: Central component of most computer operating systems (OS). Manage system's resources and communication between hardware and software components. Shell: interface for users access to services of a kernel. Graphical (GUI) shell • GNOME • KDE Text shell (CLI: Command line interpreter) • sh • Ksh: Korn Shell • Bash: Bourne-again shell r l: tr l c t f st c t r r ti syst s ( ). syst 's r s rc s c ic ti t r r s ft r c ts. ll: i t rf f r s rs ss t s r i s f r l. r ic l ( I) s ll • E • E xt s ll ( LI: li i t r r t r) • sh • sh: orn Shell • ash: ourne-again shell 17/09/2009 Confidential 8 Installation Prepare installation CD. Download .iso files: Burn CDs. BIOS boot: CD first. Installation by CDs. Swap partition: at least, should equal RAM (flexible). Boot partition. Root partition: mounted to main hard disk. Select components. Install and setup right things for IP address, domain,… r r i st ll ti . l .is fil s: tt ://r t. l .f r r j ct. r / /f r /li x/c r / tt :// . i . r / / tt :// .s .c /s ft r /s l ris/ t.js r s. I t: first. I st ll ti s. rtiti : t l st, s l l (fl xi l ). t rtiti . t rtiti : t t i r isk. l ct c ts. I st ll s t ri t t i s f r I r ss, i , 17/09/2009 Confidential 9 Boot sequence BIOS Master Boot Record (MBR) Boot loader: lilo or grub • load kernel (image=), or • load partition boot sector (other=) (dual boot) kernel initialize devices mount root FS run /sbin/init, PID 1 Init Reads /etc/inittab Runs scripts defined (/etc/rc1-5.d/…) I st r t r ( ) t l r: lil r r • l k r l (i ), r • l rtiti t s ct r ( t r ) ( l t) r l i iti liz vic s t r t r /s i /i it, I I it s / tc/i itt s scri ts fi (/ tc/rc - . / ) 17/09/2009 Confidential 10 System state System state 0 - Shutdown 1 – Single User Mode 2 – Basic Multi-user Mode 3 – Full Multi-user without X 4 – Not Used 5 – Mutli-user with X 6 – Reboot t t t - t i l s r sic lti- s r ll lti- s r it t t s tli- s r it t 17/09/2009 Confidential 11 File System 17/09/2009 Confidential 12 File System – File Permission User/Group: Super user: root Normal user: annt User info stored files: $ cat /etc/passwd root:x:0:0:Super-User:/:/sbin/sh annt:x:100:1::/export/home/annt:/bin/bash $ cat /etc/group root::0: annt::100: #cat /etc/shadow root:8gdaU2QTUw4cI:6445:::::: r r : r r: r t r l r: t r i f t r fil : $ cat /etc/passwd root:x:0:0:Super-User:/:/sbin/sh annt:x:100:1::/export/ho e/annt:/bin/bash $ cat /etc/group root::0: annt::100: #cat /etc/shadow root:8gdaU2QTUw4cI:6445:::::: 17/09/2009 Confidential 13 File System – File Permission Character 1 is the type of file: • d = directory • l = symbolic link • s = socket • p = named pipe • - = regular file • c= character (un buffered) device file special • b=block (buffered) device file special r t r i t t f fil : • ir ct r • l s lic li • s s c t • i • - r l r fil • c c r ct r ( ff r ) ic fil s ci l • l c ( ff r ) ic fil s ci l 7 7 7 17/09/2009 Confidential 14 File System – File type Regular files Text file Executable files Directory Directory Mounting point Device file Special file provide interface to device Link file Hard link Symbolic link l r fil s xt fil x c t l fil s ir t r ir ct ry ti i t i fil ci l fil r vi i t rf c t vic i fil r li k y lic li k 17/09/2009 Confidential 15 File System – Permission Example Type "ls -l" and a listing like the following is displayed: total 10 drwxrwxrwx 4 george team1 122 Dec 12 18:02 Projects -rw-rw-rw- 1 george team1 1873 Aug 23 08:34 test -rw-rw-rw- 1 george team1 1234 Sep 12 11:13 datafile Which means the following: Type and # of Files's File's Size in Date of last Filename Permission field Files Owner Group Bytes modification | | | | | | | drwxrwxrwx 4 george team1 122 Dec 12 18:02 Projects Links: The number of directory entries that refer to the file. In our example, there are four. The file's owner in our example is George. The group the file belongs to. In our example, the group is team1. The size of the file in bytes The last modification date. If the file is recent, the date and time is shown. If the file is not in the current year, the year is shown rather than time. The name of the file. "ls -l" listi li t f ll i is is l : total 10 drwxrwxrwx 4 george tea 1 122 Dec 12 18:02 Projects -rw-rw-rw- 1 george tea 1 1873 Aug 23 08:34 test -rw-rw-rw- 1 george tea 1 1234 Sep 12 11:13 datafile ic s t f ll i : Type and # of Files's File's Size in Date of last Filena e Per ission field Files Owner Group Bytes odification | | | | | | | drwxrwxrwx 4 george tea 1 122 Dec 12 18:02 Projects Links: he nu ber of directory entries that refer to the file. In our exa ple, there are four. he file's o ner in our exa ple is eorge. he group the file belongs to. In our exa ple, the group is tea 1. he size of the file in bytes he last odification date. If the file is recent, the date and ti e is sho n. If the file is not in the current year, the year is sho n rather than ti e. he na e of the file. 17/09/2009 Confidential 16 File System (cont.) /etc: contains all system related configuration files in here or in it's sub-directories. No binaries should be or are located here. /etc/fstab: lists file systems mounted /etc/hostname: contains the hostname of your machine. /etc/inittab: boot-time system configuration/initialization script. /lib: contains static/shared libraries needed to boot the system and run the commands. .a: static library .so: shared library /home: Contains home folder for users. /root: home directory of the System Administrator, 'root‘. / t : t i s ll s st r l t fi r ti fil s i r r i it's s - ir t ri s. i ri s s l r r l t r . / tc/fst : lists fil syst s t / tc/ st : c t i s t st f y r c i . / tc/i itt : t-ti syst c fi r ti /i iti liz ti scri t. /li : t i s st ti /s r li r ri s t t t s st r t s. . : st tic li r ry .s : s r li r ry / : t i s f l r f r s rs. /r t: ir ct ry f t yst i istr t r, 'r t‘. 17/09/2009 Confidential 17 File System (cont.) /tmp: Contains mostly files that are required temporarily. Do not remove files from this directory unless you know exactly what you are doing! /usr: Contains the largest share of data on a system. • All user binaries, their documentation, libraries, header files, etc.... • X and its supporting libraries. • User programs like telnet, ftp, etc.... /var: Contains variable data like system logging files, mail and printer spool directories. Variable data are files and directories that the system must be able to write to during operation. /t : t i s stly fil s t t r r ir t r rily. t r v fil s fr t is ir ct ry l ss y k x ctly t y r i ! / sr: t i s t l r st s r f t syst . • ll user binaries, their docu entation, libraries, header files, etc.... • and its supporting libraries. • ser progra s like telnet, ftp, etc.... / r: t i s v ri l t lik syst l i fil s, il ri t r s l ir ct ri s. ri l t r fil s ir ct ri s t t t syst st l t rit t ri r ti . 17/09/2009 Confidential 18 Getting Started Section 2: Basic Administration 17/09/2009 Confidential 19 Login - Putty Notes: Puttyjp support Japanese 17/09/2009 Confidential 20 Login – Tera term Note: VNC client/server is very good tool also 17/09/2009 Confidential 21 Shell Basic 17/09/2009 Confidential 22 Shell types Commonly used shells /usr/bin/sh POSIX shell /usr/bin/ksh Korn shell /usr/bin/csh C shell /usr/bin/tcsh C shell with auto completion and command line editing /usr/bin/bash GNU Bourne Again shell l ll / sr/ i /s I s ll / sr/ i /ks r s ll / sr/ i /cs s ll / sr/ i /tcs s ll it t c l ti c li iti / sr/ i / s r i s ll 17/09/2009 Confidential 23 Pipe Pipe is a way to connect the output of one program to the input of another program without any temporary file Example $who | sort $ps -ax | grep http i is y t c ct t t t f r r t t i t f t r r r it t y t r ry fil x l | s rt s - x | r tt 17/09/2009 Confidential 24 I/O Direction Send output of command to file or to read input from file Command > filename: output result of command to file Command >> filename: append result of command to file Command < filename: command get input from file Standard input: 0 (keyboard) Standard output: 1 (monitor) Standard error: 2 (monitor) Ex: command > log 2>&1 t t f t fil r t r i t fr fil fil : t t r s lt f c t fil fil : r s lt f c t fil fil : c t i t fr fil t r i t: ( r ) t r t t: ( it r) t r rr r: ( it r) x: c l 17/09/2009 Confidential 25 Vi editor Vim: Vi IMproved Operation mode: Insert mode (typing “i”) Command mode (pressing the escape key) Reference doc: vi_quickref.pdf i : i I r r ti : I s rt (ty i “i”) ( r ssi t sc k y) f r : i i r f. f 17/09/2009 Confidential 26 Basic commands Basic command list: List commands.xls and Command help $ –-help $man si list: ist c s.xls l c - l c 17/09/2009 Confidential 27 Install/uninstall software Redhat/Fedora: [root@localhost soft]# rpm -ivh mysql-5.0.27-1.fc6.i386.rpm warning: mysql-5.0.27-1.fc6.i386.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2 Preparing... ########################################### [100%] 1:mysql ########################################### [100%] Debian: dpkg -i ../foo_version-revision_arch.deb Solaris: # pkgadd -d /WWW/src/sys/libiconv-1.11-sol10-x86-local The following packages are available: 1 SMCliconv libiconv (x86) 1.11 Select package(s) you wish to process (or 'all' to process all packages). (default: all) [?,??,q]: all t/ r : [root localhost soft]# rp -ivh ysql-5.0.27-1.fc6.i386.rp warning: ysql-5.0.27-1.fc6.i386.rp : Header V3 DSA signature: NOKEY, key ID 4f2a6fd2 Preparing... ########################################### [100 ] 1: ysql ########################################### [100 ] i : dpkg -i ../foo_version-revision_arch.deb l ris: pkgadd -d / /src/sys/libiconv-1.11-sol10-x86-local The follo ing packages are available: 1 S Cliconv libiconv (x86) 1.11 Select package(s) you ish to process (or 'all' to process all packages). (default: all) [?,??,q]: all 17/09/2009 Confidential 28 Install/uninstall software (cont.) Compile and Installing from source: Download source code of package (*.tgz, *.bz2) Unzip Read README, INSTALL file or related file to know how to install/uninstall this driver Notes: you should have a basic knowledge about gcc (compile options), make file, debug and check tool (dump, ldd …) Auto install/update Fedora: yum Debian: apt-get Note: require get through GCS’s proxy automatically: ntlmap il I st lli fr s r : l s rc c f ck ( .t z, . z ) zi , I LL fil r r l t fil t k t i st ll/ i st ll t is riv r t s: y s l v sic k l t cc (c il ti s), k fil , c ck t l ( , l ) t i st ll/ t r : y i : t- t t : r ir t t r ’s r xy t tic lly: tl 17/09/2009 Confidential 29 Network service and LAMP Network services: Special route for GCS LAN DHCP telnet/ssh ftp samba NFS (network file system) sendmail Cron ntlmap Apache Mysql Oracle t r s r i s: ci l r t f r L t l t/ss ft s ( t rk fil syst ) s il r tl c ys l r cl 17/09/2009 Confidential 30 GCS Network Information C:\Documents and Settings\annt>ipconfig /all Windows IP Configuration Host Name . . . . . . . . . . . . : annguyen0647 Primary Dns Suffix . . . . . . . : cybersoft.vn Node Type . . . . . . . . . . . . : Hybrid IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No DNS Suffix Search List. . . . . . : cybersoft.vn cybersoft.vn Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : cybersoft.vn Description . . . . . . . . . . . : Intel(R) PRO/1000 PL Network Connection Physical Address. . . . . . . . . : 00-18-F3-82-0D-15 Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 172.21.3.164 Subnet Mask . . . . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . . . . : 172.21.0.2 DHCP Server . . . . . . . . . . . : 172.20.0.3 DNS Servers . . . . . . . . . . . : 172.21.0.2 172.20.0.3 Primary WINS Server . . . . . . . : 172.20.0.2 Lease Obtained. . . . . . . . . . : Wednesday, August 06, 2008 4:26:33 PM Lease Expires . . . . . . . . . . : Thursday, August 14, 2008 4:26:33 PM 17/09/2009 Confidential 31 GCS Network Information C:\Documents and Settings\annt>NETSTAT -rn Route Table =========================================================================== Interface List 0x1 ........................... MS TCP Loopback interface 0x2 ...00 18 f3 82 0d 15 ...... Intel(R) PRO/1000 PL Network Connection - Packet Scheduler Miniport =========================================================================== =========================================================================== Active Routes: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 172.21.0.2 172.21.3.164 20 127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1 172.16.0.0 255.255.0.0 172.21.0.1 172.21.3.164 1 172.17.0.0 255.255.0.0 172.21.0.1 172.21.3.164 1 172.20.0.0 255.255.0.0 172.21.0.1 172.21.3.164 1 172.21.0.0 255.255.0.0 172.21.3.164 172.21.3.164 20 172.21.3.164 255.255.255.255 127.0.0.1 127.0.0.1 20 172.21.255.255 255.255.255.255 172.21.3.164 172.21.3.164 20 172.22.0.0 255.255.255.0 172.21.0.1 172.21.3.164 1 172.22.1.0 255.255.255.0 172.21.0.1 172.21.3.164 1 224.0.0.0 240.0.0.0 172.21.3.164 172.21.3.164 20 255.255.255.255 255.255.255.255 172.21.3.164 172.21.3.164 1 Default Gateway: 172.21.0.2 =========================================================================== Persistent Routes: None 17/09/2009 Confidential 32 GCS Network Information Proxy server: find proxy server in ISA client Ex: GBOProxy.cybersoft.vn SMTP server: for setup sendmail Ex: phanthiet. cybersoft.vn 17/09/2009 Confidential 33 Check network configuration Show ip address # ifconfig -a eth0 Link encap:Ethernet HWaddr 00:18:F3:82:12:D8 inet addr:172.21.204.200 Bcast:172.21.255.255 Mask:255.255.0.0 inet6 addr: fe80::218:f3ff:fe82:12d8/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Show route # netstat -rn Routing Table: IPv4 Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- ---------- --------- default 172.21.0.2 UG 1 0 172.16.0.0 172.21.0.1 UG 1 0 172.17.0.0 172.21.0.1 UG 1 0 Show DNS server # cat /etc/resolv.conf search cybersoft.vn nameserver 172.20.0.2 nameserver 172.20.0.3 17/09/2009 Confidential 34 Configure network Configure IP address ifconfig eth1 172.21.204.135 netmask 255.255.0.0 broadcast 172.21.255.255 up Configure route Linux: /sbin/ip route add default via 172.21.0.1 dev eth0 /sbin/ip route add 172.20.0.0/16 via 172.21.0.1 dev eth0 Solaris /usr/sbin/route add net default 172.21.0.2 /usr/sbin/route add net 172.16.0.0/16 172.21.0.1 Other network debug commands: ping, nslookup, uname, hostname, telnet … 17/09/2009 Confidential 35 DHCP - Dynamic Host Configuration Protocol DHCP: Automatically assign an IP address other related configuration information such as the subnet mask and default gateway, DNS servers, WINS servers 17/09/2009 Confidential 36 DHCP 17/09/2009 Confidential 37 Telnet – RFC 854 Telnet (default port 23) is a standard application that almost every TCP/IP implementation provides. It works between hosts that use different operating systems. 17/09/2009 Confidential 38 Telnet – Detect network service Example of use telnet to detect mail server # telnet 172.20.0.4 25 Trying 172.20.0.4... Connected to 172.20.0.4. Escape character is '^]'. 220 PHANTHIET.cybersoft.vn Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Mon, 11 Aug 2008 16:16:08 +0700 17/09/2009 Confidential 39 FTP – File Transfer Protocol Active mode Passive mode 17/09/2009 Confidential 40 FTP – File Transfer Protocol Example C:\Documents and Settings\annt>ftp 172.21.204.133 Connected to 172.21.204.133. 220 dnpperl0955.cybersoft.vn FTP server ready. User (172.21.204.133:(none)): annt 331 Password required for annt. Password: 230 User annt logged in. ftp> binary ftp> get test.txt ftp> put test.txt ftp> prompt off ftp> mget /WWW/* 17/09/2009 Confidential 41 Samba Samba is essentially a TCP/IP file and print server for Microsoft Windows clients. Configure a samba share folder 1. Share Linux directory 1. # vi /etc/samba/smb.conf 2. Add below section: enable user luc and toshiba access to myshare folder [myshare] comment = test share path = tmp/testshare valid users = luc toshiba public = no writable = yes printable = no browseable = yes 2. Set password for samba user # smbpasswd –a luc 3. Restart samba service # /sbin/service smb restart 17/09/2009 Confidential 42 Samba Add new samba user Syntax # smbpasswd -a username Example # smbpasswd -a user1 Enable accessing Windows folder from Linux Syntax: request root privilege to execute • Mount folder smbmount win_dir linux_dir [-o options] • Unmount samba folder smbumount linux_dir Options: not allow space between these below options • rw: read/write mode • ro: read only mode • username: user name to log in to Windows computer • password: password to log in to Windows computer Example • Mount samba folder # smbmount //172.16.5.26/Share /home/luc/share -o ro,username=administrator,password=gcsvn123 • Unmount samba folder # smbumount /home/luc/testshare 17/09/2009 Confidential 43 NFS – Network File System NFS allows users to access files across a network and treat them as if they resided in a local file directory. NFS configuraiton: 17/09/2009 Confidential 44 Sendmail Refer to sendmail howto document 17/09/2009 Confidential 45 Cron Using crontab command to schedule tasks to be automatically run in the background at regular intervals by the cron daemon Syntax crontab [options] [user] Options • -e: edit user's crontab • -l: list user's crontab • -r: delete user's crontab Crontab files path: /var/spool/cron/crontabs/ Crontab file format 17/09/2009 Confidential 46 Cron Example Use df command to check disk space with the below schedule 1. export EDITOR=vi ;to specify a editor to open crontab file. 2. $ crontab –e 3. Input the above content into crontab file 4. Save the file 5. View crontab content $ crontab -l Output memory information to mem.txt after each minute 1. $ crontab -e • * * * * * free >> mem.txt 2. $ crontab -l 17/09/2009 Confidential 47 Cron and problem with time zone 1. The times in cron are local times. This means, that if you configure cron to start some program at 7 in the morning, it is 7 in the morning local time as determined by the system Timezone. This causes headaches, if the system Timezone is not the same you have set for yourself using the TZ enviroment variable, or you have two host in different Timezones that need to start someting at the same time on both hosts. => solution synchronize system time zone and environment time zone. 2. How to check and reconfig system timezone - Show local date: $date Mon Dec 3 23:03:54 EST 2007 EST stand for Eastern Standard Time - Check time zone information: /usr/share/zoneinfo/ or $tzselect - Check system time zone: $cat /etc/timezone - Check environment time zone: $env | grep TZ - Change system time zone: $tzconfig - Synchronize environment time zone to system time zone: add this scrip into /etc/profile if [ -z "$TZ" -a -e /etc/timezone ]; then TZ=`cat /etc/timezone` export TZ fi - Show hardware clock: $/sbin/hwclock - Synchronize hardware clock with current local time: $/sbin/hwclock --systohc - When you change time zone in profile, do not forget to restart apache server. Reference: 17/09/2009 Confidential 48 NTLMAP 'NTLM Authorization Proxy Server' (APS) is a proxy software that allows you to authenticate via an MS Proxy Server (e.g. ISA server) using the proprietary NTLM protocol. Refer to NTML howto 17/09/2009 Confidential 49 Apache Apache site: Compiling and Installing Stopping or Restarting Modules Configuration Files SSL/TLS Encryption Virtual Hosts Server Side Includes (SSI) Authentication, Authorization and Access Control 17/09/2009 Confidential 50 Apache – Stop/start Check Apache version: [root@dnpasa ~]# httpd -V Server version: Apache/2.2.3 Server built: Sep 11 2006 09:43:05 Server's Module Magic Number: 20051115:3 To start/stop Apache HTTP Server: /usr/local/apache/bin/apachectl start/startssl/stop Check error log: tail /usr/local/apache/logs/error_log Check httpd process # ps -ef | grep httpd root 2378 1 0 Jun27 ? 00:00:09 /usr/local/apache/bin/httpd -k start -DSSL nobody 17801 2378 0 Jul09 ? 00:00:29 /usr/local/apache/bin/httpd -k start -DSSL 17/09/2009 Confidential 51 Mysql Start mysql/stop # /etc/init.d/mysql start/stop Check error log # tail /var/adm/messages (Solaris) # tail /var/log/messages (Linux) 17/09/2009 Confidential 52 Oracle Start/stop Oracle Login as oracle user Check env variables: ORACLE_HOME and ORACLE_SID Start oracle instance: sqlplus /nolog sqlplus>connect sys/ as sysdba sqlplus>startup Shutdown oracle instance sqlplus>shutdown normal/immediate Start Oracle listener $ORACLE_HOME/bin/lsnrctl start Connect to DB : sqlplus user/password@servicename 17/09/2009 Confidential 53 Any Questions? 17/09/2009 Confidential 54 Practice User administration Environment variable File system System resources Text editors Text processing Networking Useful commands 17/09/2009 Confidential 55 Create users Logout $ logout List all users which are logging at present time $ who Find location of a program or a command Syntax whereis command Example: find location of adduser command $ whereis adduser 17/09/2009 Confidential 56 Create users Change to root account from normal user $ su Allows a permitted user to execute a command as the super user 1. Grant permissions for normal user 1.# vi /etc/sudoers 2. Add the following line to enable user "luc" to execute "service" command # User privilege specification root ALL=(ALL) ALL luc ALL=/sbin/service 2. Using sudo to execute command $ sudo /sbin/service smb restart 17/09/2009 Confidential 57 Create users Create a user: you must have sufficient privilege to execute this command Add new user # /usr/sbin/adduser username Set password for new user # passwd username Delete user # /usr/sbin/userdel username Shutdown Linux server: you must have sufficient privilege to execute this command # shutdown -h Reboot Linux server: you must have sufficient privilege to execute this command # reboot 17/09/2009 Confidential 58 Environment variables Environment variable in Linux is similar to Window Temporary variable: is a variable which is available to a shell console only User variable: is a variable which is only available to a user System variable: is a variable which is available to all users List of environment variables $ env View a environment variable Syntax $ echo $var_name Example: view HOME variable $ echo $HOME 17/09/2009 Confidential 59 Environment variables Define temporary variable Syntax $ export var_name=value Example $ export JAVA_HOME=/usr/lib/jdk $ export PATH=$PATH:$JAVA_HOME/bin Define user variable: define variable in ~/.bash_profile file instead of shell console. When you relogin, your new variable will be updated. Define a system variable: define variable in /etc/profile file. You need to have root privilege to modify this file 17/09/2009 Confidential 60 File permissions Change file permissions Syntax chmod nnn filename/directory [-R] Options -R: recursive when granting permissions for directory Example: change mode for test.txt file $ chmod 755 test.txt Change file ownership (require root privilege) Syntax chown user[:group] filename/directory [-R] Example: change owner of test.txt to user1 # chown user1 test.txt 17/09/2009 Confidential 61 File operation commands Directory symbols .: current directory ..: parent directory ~:home directory List directories and files Syntax ls [option] Example: list all file and directory $ ls -la Change directory Syntax cd directory Example: change to sample directory $ cd sample $ cd ~ 17/09/2009 Confidential 62 File operation commands Display current working directory Syntax pwd Make a directory Syntax mkdir [option] directory Example: make sample directory $ mkdir sample Remove an empty directory Syntax rmdir directory Example: remove sample directory $ rmdir sample 17/09/2009 Confidential 63 File operation commands Copy file or directory Syntax cp [-r] filename path/[new_filename] Example: copy test.txt to sample directory $ cp test.txt /home/luc/sample Move/rename file Syntax mv filename path mv old_namefile new_filename Example • Move test.txt to sample directory $ mv test.txt /home/luc/sample • Rename test.txt to test1.txt $ mv test.txt test1.txt 17/09/2009 Confidential 64 File operation commands Create a new empty file or modify file timestamp Syntax touch filename Example $ touch test.txt Remove file or directory Syntax rm [-r] filename/directory Options • -r: remove an un-empty directory Example • Remove test.txt $ rm test.txt • Remove sample directory $ rm –r sample 17/09/2009 Confidential 65 File operation commands Page through the contents of a file one screenful at a time Syntax less [options] filename Options • -c: clear screen before displaying • -number: number of lines per screen Key control • Enter: view one more line • q: quit to view a file • b: move back one screen • f: move forward one screen • /text: search for text in the remainder of file Example $less mem.txt 17/09/2009 Confidential 66 File operation commands Display content of file Syntax cat filename view filename Example $ cat test.txt [|more] [|less] $ view test.txt Display first n lines of file Syntax head -number filename Example: display first 10 lines of test.txt $ head -10 test.txt 17/09/2009 Confidential 67 File operation commands Display last n lines of file Syntax tail [options] filename Options • -number: display last n lines of file • -f: Loop forever, trying to read more characters at the end of the file Example: display last 10 lines of test.txt $ tail -10 test.txt $ tail -f test.txt Count words in file Syntax wc [option] filename Option • -c: count bytes • -m: count characters • -l: count lines • -w: count words Example $ wc -lwc test.txt 17/09/2009 Confidential 68 File operation commands Compare files Syntax: default report only the first difference found cmp [-l] file1 file2 Example: compare test.txt and test1.txt and report on each difference $ cmp –l test.txt test1.txt Find differences between two files or directories Syntax diff [options] file1 file2 Options • -a: Treat all files as text and compare them line-by- line, even if they do not seem to be text • -i: Ignore changes in case; consider upper- and lower- case letters equivalent • -r: When comparing directories, recursively compare any subdirectories found. Example $ diff –i test.txt test1.txt 17/09/2009 Confidential 69 File operation commands Send output of a command to file Syntax tee [-a] filename Options -a: append Example: send result of ls command to file $ ls –la | tee list.txt Find file Syntax find [-name] filename Example $ find -name test.txt Locate file Syntax locate filename Example $ locate test.txt 17/09/2009 Confidential 70 File operation commands Archive file Syntax tar [options] filename directory Options • c: create an archive file • x: extract from an archive file • v: verbose • f: archive file name Example • Archive sample directory into sample.tar $ tar –cvf sample.tar sample • Extract sample.tar to current directory $ tar –xvf sample.tar 17/09/2009 Confidential 71 File operation commands Zip file Syntax zip [options] filename.zip directory unzip filename.zip Options • -r: travel the directory structure recursively Example • Archive sample directory into sample.tar $ zip –r sample.zip sample • Unzip sample.zip to current directory $ unzip sample.zip 17/09/2009 Confidential 72 System resources [1] Show status of active processes Syntax ps [options] Options • -a: list all processes of all users • -u: user oriented report • -x: list even processes not executed from terminals Example $ ps -ux Kill a running process Syntax kill [-signal] process-id Options • -l: displays the available kill signals • -9: force running process terminate immediately Example $ ps -9 15599 17/09/2009 Confidential 73 System resources [2] Summarize disk block and file usage Syntax df Report disk space in use for files or directories Syntax du [options] [directory or file] Options • -a: display disk usage for each file, not just subdirectories • -s: display a summary total only Example: display disk usage of files and subdirectories of sample directory $ du –a sample 17/09/2009 Confidential 74 System resources [3] Displays the processes that are using the most CPU resources Syntax top [p pid] Options • p pid: view CPU usage of a process Example $ top Display information about free and used memory on the system Syntax free [options] Options • -m: display output in megabytes (MB) Example $ free 17/09/2009 Confidential 75 Text Editor - vi vi is a Visual Editor which allows user to edit file in Linux. It is a default editor under most Linux and Unix versions Syntax: create or edit file vi filename vi commands: all commands in vi are preceded by pressing the escape key. There are three kind of commands: Text editing commands Cursor movement commands File manipulation commands 17/09/2009 Confidential 76 vi – Text Editing Commands Text editing commands are used during editing content of file. i: insert text before the cursor a: append text after the cursor I: insert text at the beginning of the line A: append text to the end of the line dd: deletes current line dw: deletes current word D: deletes from cursor to end of line x: deletes current character X: deletes previous character yy: copy the current line into the buffer Nyy: copy the next N lines, including the current line, into the buffer p: patse the lines in the buffer into the text after the current line 17/09/2009 Confidential 77 vi – Cursor Movement Commands Cursor movement commands are used to move cursor around the file CTRL+f: forward one screen CTRL+b: back one screen CTRL+d: down half screen CTRL+u: up half screen H: beginning of top line of screen M :beginning of middle line of screen L: beginning of last line of screen G: beginning of last line of file 0: (zero) beginning of line $ : end of line e: end of word 17/09/2009 Confidential 78 vi – File Manipulation Commands File manipulation commands are used to manipulate the file :w writes changes to file :wq writes changes to current file and quits edit session :w! overwrites file :q quits edit session (in case file not be changed) :q! quits edit session and discards changes ZZ write changes to current file and exit 17/09/2009 Confidential 79 Text processing – grep command The grep utility searches files for a pattern and prints all lines that contain that pattern Syntax grep [options] [file[s]] Options • -i: ignore case • -e pattern: search text which matches the parttern Example: file num1.txt and num2.txt has the following content: • num1.txt 1 15 fifteen 2 14 fourteen • num2.txt 4 12 twelve 15 1 one 17/09/2009 Confidential 80 Text processing – sed command Examples $ grep '15' num1.txt $ grep '15' num2.txt > list15.txt $ grep '15' num?.txt $ grep –e '[one,twelve]' num2.txt sed command is used to search and replace text in a file. Syntax sed 's/text_search/text_replace/g' filename [>tempfile] Example $ sed "s/TEST SED/test sed/g" test.txt > test.temp $ mv test.temp test.txt 17/09/2009 Confidential 81 Text processing – awk/gawk commands [1] awk/gawk is a tool for processing text files. It is particularly suitable for processing text-based tables. A table consists of records which contain fields separated by a delimiter Syntax gawk 'pattern {print}'filename Meaning: each input line from filename is checked for a pattern match with the indicated action being taken on a match. Options • $ n: n is a column id. $0 means entire record • Pattern – /text/: search text from lines of file – Operator: ||, &&, !, ==, , >=, != – ~: contains the expression – !~: not contain the expression – NR: number of rows 17/09/2009 Confidential 82 Text processing – awk/gawk commands [2] Example The record.txt file has below content: Ex1: print line which contains 222 $ cat record.txt | gawk '/222/ {print}' Ex2: print NAME and SALARY of records which has SALARY>2000 $ cat record.txt | gawk '$ 3>2000 {print $2 ";" $3}' Ex3: print from line # 1 and # 3 $ gawk 'NR==1,NR==3 {print}' record.txt Ex4: print record which has ID=222 $ gawk '$1==222 {print}' record.txt Ex4: print records which have NAME=AAAA or BBBB $ cat record.txt | gawk '$2=="AAAA" || $2=="BBBB" {print}' ID NAME SALARY 111 AAAA 1000 222 BBBB 2000 333 CCCC 5000 444 DDDD 3000 17/09/2009 Confidential 83 Text processing – Regular expression Below are meaning of metacharacters which are used in the expression of grep and sed commands . : matches any one character • Example: .at à match cat, mat, nat,… * : matches preceding char one or more time • Example: ab*c à match abc, abbc, abbbc,… [] : encloses a char set, and matches any members of the set. • - : specifies a range of characters, ordered according to their ASCII value • ^ : As the first character of a list, the caret means that any character except those in the list should be matched • Example [abc] à match any 'a', 'b', or 'c' [0-9] à mean [0123456789] [A-Za-z] à match all alphabet characters [^a] à match any except a [^0-9] à match any except a numeric digit 17/09/2009 Confidential 84 Text processing – Regular expression [1] ^ : matches characters from the beginning of line • Example: ^error à match all lines beginning with "error" $ : matches characters from the end of line • Example: error$ à match all lines end with "error" 17/09/2009 Confidential 85 Networking View hostname of the Linux server Syntax hostname Check whether the local PC reach to remote host or not Syntax ping hostname|IP Example $ ping localhost View IP of the local PC Syntax ifconfig Note: only root user can execute this command. 17/09/2009 Confidential 86 Networking - telnet telnet utility enables user to communicate with a remote host Syntax telnet hostname|IP Check whether telnet service is ON of not # /sbin/chkconfig –-list telnet Enable telnet service: do the following steps 1. Open file /etc/xinetd.d/telnet 2. Set value for below line: disable=no 3. Restart xinitd service # /etc/rc.d/init.d/xinetd restart 17/09/2009 Confidential 87 Networking - ssh Secure Shell (SSH) tools provide a secure method for logging in and exchanging information with a remote host . It also enables us to execute a command of a remote host. Syntax: execute remote command ssh username@hostname command Example: check disk space from a remote host [luc@localhost ~]$ ssh toshiba@172.16.190.1 df The authenticity of host '172.16.190.1 (172.16.190.1)' can't be established. RSA key fingerprint is 87:09:e2:79:57:61:ba:34:a8:f0:6e:ec:48:71:ec:b8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '172.16.190.1' (RSA) to the list of known hosts. toshiba@172.16.190.1's password: Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 10080488 3508104 6060316 37% / none 1618288 0 1618288 0% /dev/shm /dev/sdb1 302382384 164371536 122650704 58% /home /dev/sda2 221744328 187595576 22884780 90% /opt /dev/sda3 75838500 88424 71897692 1% /usr/local 17/09/2009 Confidential 88 Networking – ftp [1] ftp utility enables user to transfer files from local computer to remote host and vice versa Syntax ftp hostname|IP Check whether ftp service is ON of not # /sbin/chkconfig –-list tftp Enable ftp service: do the following steps 1. Open file /etc/xinetd.d/tftp 2. Set value for below line: disable=no 3. Restart ftp service # /etc/rc.d/init.d/proftpd restart Note: depend on Linux distribution, the command might different 17/09/2009 Confidential 89 Networking – ftp [2] ftp commands Transfer file from local computer to remote host put local-file [remote-file] Get file from remote host to local computer get remote-file [local-file] Enable binary mode before transferring file binary Display available commands help Display path of current directory pwd List directory ls or dir Quit out of FTP program quit 17/09/2009 Confidential 90 Networking - netstat netstat is a useful tool for checking your network configuration and activity Syntax netstat [options] Options • -a: show both listening and non-listening sockets • -n: show network addresses as numbers • -l: show only listening sockets • -p: show pid Example $ netstat –l $ netstat -na 17/09/2009 Confidential 91 Networking – sniffit [1] Sniffit is a packet sniffer which is used to capture packets transfer on a specified host and port To use sniffit, we need to download two below packet: sniffit-0.3.7beta-1.i386.rpm: provide sniffit command. ncurses4-5.0-9.i386.rpm: provide GUI in interactive mode. You can download these above files from the below link: Install sniffit: login to Linux and su to root user. Change to directory which contains two these above files $ rpm –i ncurses4-5.0-9.i386.rpm $ rpm –i sniffit-0.3.7beta-1.i386.rpm 17/09/2009 Confidential 92 Networking – sniffit [2] Using sniffit: before using, we need to create configuration file which contains input parameters for sniffit command Format of parameters in configuration file Create file conf.txt which captures packets on port 23 select both port 23 Run sniffit to capture packets on port 23 # /usr/sbin/sniffit -c conf.txt -M 0 sniffit will capture packets on port 23 and store into two files below. They are in readable text. So we can view and understand the content. -rw-r--r-- 1 root root 770 Aug 8 05:20 172.16.190.1.23-172.16.5.117.1588 -rw-r--r-- 1 root root 25 Aug 8 05:20 172.16.5.117.1588-172.16.190.1.23 -rw-r--r-- 1 root root 20 Aug 8 05:16 conf.txt 17/09/2009 Confidential 93 Networking - traceroute Traceroute is the program that shows you the route over the network between two hosts, listing all the intermediate routers a connection must pass through to get to its destination. It can help you determine why your connections to a given server might be poor Syntax traceroute hostname|IP Example $ traceroute 172.16.5.94 traceroute to 172.16.5.94 (172.16.5.94), 30 hops max, 38 byte packets 1 172.16.5.94 (172.16.5.94) 1.650 ms 1.054 ms 1.493 ms In the above result, traceroute command sends 3 packets to 172.16.5.94. Therefore, there are response times output. 17/09/2009 Confidential 94 Useful commands [1] Run a command in the current directory when the current directory is not on the path Syntax $ ./command Run command in the backgroup mode: this is useful for executing batch program Syntax $ command & Example $ top & Run the command following this only if the previous command completes successfully Syntax $ command1 && command2 Example $ grep 'aaa' f1.txt && echo "End of result" 17/09/2009 Confidential 95 Useful commands [2] Run the command following only if the previous command did not complete successfully Syntax $ command1 || command2 Example $ grep 'aaa' f1.txt || echo “String not found” View list of previous command $ history Repeat previous command $ !! View list of available commands: press two times. Send current process to background: press CTRL+z Convert window file format to Linux text file format and vice versa Syntax $ dos2unix filename $ unix2dos filename 17/09/2009 Confidential 96 Special characters Back stick ` Back sticks are used for command substitution Back slash \ Back slash hide the following character from the shell. The character following the back slash loses any special meaning Semi colon ; Semi colon lets you put more than one command on a line Ampersand & Ampersand at the end of a command puts that command into the background 17/09/2009 Confidential 97 Regular expression Star * Zero or more times Dot . One or more times Group [] [AaBb] Range – [0-9] [a-zA-Z] Slash \ \* \. 17/09/2009 Confidential 98 Any Questions? 17/09/2009 Confidential 99 LPI™ certification Linux Professional Institute™ family of certifications : Level 1: Junior Level Linux Professional. Level 2: Advanced Level Linux Professional. Level 3: Senior Level Linux Professional. LPI Website: 17/09/2009 Confidential 100 References site 1. 2. 3. 4. services-during_01.html 5. Hierarchy/index.shtml 6. 7. Manual/custom-guide/s1-samba-configuring.html#S2-SAMBA- CONFIGURING-CMDLINE 8. 9. Collection/FastStart.html#anon-example 10.Man pages at your linux machine. . tt :// . iki i . r / iki/ yst . tt :// .li x. r /l ss s/ i r/t c. t l . tt :// . ix i . t/li x/li xs rtc ts.s t l . tt ://li x l . l s t.c / / / li - - is li - s rvic s- ri . t l . tt :// .li x.c / i s/Li x- il syst - i r rc y/i x.s t l . tt :// . iki i . r / iki/ ris f Li x istri ti s . tt :// .r t.c / cs/ ls/li x/ L- - l/c st - i /s -s -c fi ri . t l - - I I - LI . tt :// .f s. r / cs/s c ri /c s c . t l . tt :// .s . r /s / cs/ / - - ll cti / st t rt. t l - x l . s t y r li x c i . 17/09/2009 Confidential 101 Thank you!

Các file đính kèm theo tài liệu này:

  • pdfLinux Fundamental (For ICT).pdf
Tài liệu liên quan