Bài giảng Hệ điều hành linux: Chương 5 Các thao tác quản trị hệ thống cơ bản do Ngô Văn Công biên soạn cung cấp các kiến thức cơ bản như: Siêu tài khoản người dùng(superuser account), quá trình khởi động và thoát khỏi hệ thống, quản lý tài khoản người dùng,...
Trang 1Các thao tác quản trị hệ
thống cơ bản
Ngô Văn Công
Trang 2Nội dung
account)
Quá trình khởi động và thoát khỏi hệ thống
Quản lý hệ thống tập tin
Điều khiển các tiến trình
Trang 3root - Superuser account
Tải khoản có quyền cao nhất trong hệ thống
Không có hạn chế nào được áp đặt trên tài khoản này
Thường dùng để duy trì và quản trị hệ thống
cách thông dụng để chuyển vào tài khoản root là:
Trang 4Quá trình khởi động và thoát khỏi
hệ thống
Startup and Initialization)
tập tin /etc/inittab
các tập tin rc
Trang 5Khởi động hệ thống và khởi tạo
Booting the kernel
Initializing device drivers
Executing init in /sbin
init reading /etc/inittab
Executing rc files based on runlevel
Trang 7/etc/inittab file
File format
code:runlevels:action:command
Runlevels
# Default runlevel The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
Trang 8Switching runlevel
Generally, Linux operates in runlevel 3 or 5
Edit initdefault in /etc/inittab
Running init manually
# init 5 (switch to X11 mode)
# init 3 (switch to multiuser mode)
# init 1 (switch to single user mode)
Finding previous and current system run level
# runlevel
Trang 9Services start/stop at boot
nn = 00 - 99: enforce executing order
S10network S12syslog S99local K90network K10xfs
S* and K* are symlinks to real scripts
Central directory for real scripts: /etc/rc.d/init.d, /etc/init.d
Trang 10Linux Services
There are 113 deamons, Out of them, the following are most widely used:
Trang 11(tt)
Trang 12Start and stop daemon
If a startup script exists in the /etc/init.d directory
Trang 13 Fedora and Redhat also come with the service command
Trang 14Chế độ đơn người
Trang 15shutdown hệ thống
shutdown - tắt hệ thống
# shutdown -r +10 (reboot after 10 minutes)
# /sbin/shutdown -r +10 "Rebooting to try new kernel"
# shutdown -h now (halt immediately)
Trang 16Quản lý tài khoản
Trang 17Người dùng và nhóm
Tài khoàn người dùng và tài khoản hệ thống
mỗi người dùng sẽ có 1 tên và định danh(id) duy nhất (unsigned number)
Mỗi người dùng thuộc về ít nhất 1 nhóm
Mỗi nhóm có tên và định danh duy nhất (unsigned
number)
Tên tài khoản người dùng thường là chữ thường
Tài khoản siêu người dùng luôn có id là 0
Trang 18Thêm tài khoản người dùng
useradd [-u uid] [-g group] [-G group, ]
[-d home] [-s shell] [-c comment] name
# useradd -g students -c "Student 001" stud001 passwd - set user password
# passwd stud001
Trang 19Chỉnh sửa và xoá tài khoản
người dùng
usermod [-u uid] [-g group] [-G group, ]
[-d home] [-s shell] [-c comment] [-l new_name] name
# usermod -u 1001 stud001
userdel [-r] name
-r: remove user’s home directory
# userdel -r stud001
Trang 20password - mật khẩu người dùng(mã hóa)
uid - user ID (system convenient)
gid - group ID
gecos - thông tin khác của người dùng
homedir - thư mục home của người dùng
shell - chương trình sẽ chạy khi người dùng login vào, thường là /bin/bash
T ăng bảo mật cho mật khẩu : /etc/shadow
Trang 22Tập tin /etc/shadow
được mã hóa cho tài khoản người dùng
Login name
Encrypted password
Trang 23(tt)
Trang 24Khóa tài khoản người dùng
Đặt ! trong trường password của tập tin /etc/shadow
Thay đổi shell đăng nhập thành
/sbin/nologin
Trang 26Tập tin /etc/group
Định dạng
groupname:password:gid:members
groupname - bất kỳ chuỗi ký tự nào
password - tùy chọn mật khẩu
Trang 27Chỉnh sửa người sở hữu và nhóm
chown - Thay đổi người sở hữu và nhóm
# chown -R stud001:students /home/stud001
Trang 28Cấp quyền root khi chạy 1 lệnh:
lệnh sudo
sudo command
/etc/sudoers: Tập tin chứa thông tin người dùng được phép sudo
Cú pháp của một dòng trong file sudoers như sau:
User host computer=command
Defaults logfile=/var/log/sudolog
Trang 29user1 ALL=(ALL) ALL
user1 có thể chạy bất kỳ câu lệnh nào, dưới quyền bất kỳ người dùng nào nhưng phái biết password của user1
user1 ALL=(root) shutdown
user1 chỉ có quyền chạy câu lệnh shutdown, nhưng phải biết
passwrd của user1
user1 ALL=(root) NOPASSWD: /usr/bin/id
user1 chỉ có thể chạy câu lệnh /usr/bin/id và không cần password;
no password will be needed
user1 ALL=(accounts) /bin/kill, /usr/bin/kill, /usr/bin/pkill
sudo -u accounts pkill monthend
Trang 31Các kiểu hệ thống tệp
ext2 - common Linux filesystem
msdos - MS-DOS FAT
vfat - Windows 95/98 FAT
ntfs - Windows NT/2000/XP NTFS
iso9660 - CD-ROMS
smbfs - SMB sharing filesystem
nfs - Network File System
proc - /proc filesystem (process information)
ext3, reiserfs, jfs, xfs - journaling filesystems
Trang 32Gắn kết hệ thống tệp
mount -t type /what /where
# mount -t ext2 /dev/hda5 /mnt/backup
# mount -t msdos /dev/fd0 /mnt/floppy
# mount -t iso9660 /dev/hdd /mnt/cdrom
# mount -t vfat /dev/hdc1 /mnt/c
Hiển thị các hệ thống tệp gắn kết
# mount
/dev/hda1 on / type ext3 (rw)
Trang 33 Floppy disk /dev/fd0
Hard drives /dev/hdX, /dev/sdX
Trang 35Định dạng hệ thống tệp
Phân vùng đĩa
fdisk
Định dạng hệ thống tệp
mkfs -t type device blocks
blocks: size of the filesystem (1024-byte blocks)
Trang 36Kiểm tra và chỉnh sửa hệ thống tệp
Kiểm tra sự toàn vẹn của hệ thống tệp
Ngoại trừ phân vùng root, umount thiết bị trước khi kiểm tra
fsck -t type device
# fsck -t ext3 /dev/hda2
Trang 37Quản lý Software
Có 2 định dạng khác nhau
RPM Package Manager (RPM) – Red hat, Suse
Debian Package (DEB) – Debian, Ubuntu
Tarball
Trang 39RPM - Red Hat Package
Management
Các gói cài đặt trong các hệ thống red hat
Thông tin về gói được lưu trữ trong cơ sở dữ liệu
Trang 41Xóa gói
rpm -e
# rpm -e openssh-server-3.1p1-3
# rpm -e xvnkb
Trang 42Truy vấn thông tin gói
rpm -q
# rpm -ql fileutils: Liệt kê các tập tin của gói
# rpm -qip xvnkb-0.2.4-2.i386.rpm: in ra thông tin
tóm tắt của gói
# rpm –qa: Liệt kê tất cả gói
Trang 43Vấn đề phụ thuộc
# rpm -ihv MagicPoint-1.09a-1.i386.rpm
error: failed dependencies:
VFlib2 >= 2.25.6-4 is needed by MagicPoint-1.09a-1 libpng.so.2 is needed by MagicPoint-1.09a-1
# rpm -ihv MagicPoint-1.09a-1.i386.rpm \
VFlib2-2.25.6-4.i386.rpm \ libpng-1.0.12-2.i386.rpm
Trang 45Quản lý gói với APT
Trang 46Điều khiển tiến trình
Hiểu về tiến trình
Liệt kê danh sách tiến trình đang chạy
Kết thúc tiến trình
Trang 47Hiểu về tiến trình
Tiến trình là một chương trình được nạp vào bộ nhớ để chạy
Nhiều tiến trình cùng chạy đồng thời tại một thời điểm
Mỗi tiến trình sẽ được gắn kết id duy nhất: PID (process ID)
Tiến trình có người sở hữu(owner) và quyền giống như tập tin
C ác kiểu tiến trình
Daemon processes
Background processes
Foreground processes
Trang 48Tiến trình nền(Background
processes)
Đặt ký tự & sau tên tập tin khi chạy
Cat > vidu.txt &
Ctrl+Z : Chuyển tiến trình từ tiền cảnh sang tiến trình nền
jobs: hiển thị tất cả tiến trình nền
bg: bắt đầu tiến trình ở chế độ nền
fg: chuyển tiến trình sang thành tiến trình tiền cảnh
Trang 49ps - liệt kê danh sách tiến trình
ps [options]
a: select all processes on a terminal
x: select processes without controlling ttys
u: display user-oriented format
Uptime: how long server is up
Free: information about memory usage
Trang 51killall - kết thúc tiến trình qua tên
killall [ -s signal ] name
$ killall -SIGHUP syslogd
$ killall -9 man
Trang 52top - process CPU/Memory consumption
Press h at anytime for list of interactive commands
Trang 53Chạy tiến trình 1 cách tự động
Các công việc đòi hỏi tính tự động
Trang 55Hệ thống cron
crontab files: cấu hình của cron
crontab commmand: câu lệnh dùng để chỉnh
sửa tập tin crontab
crond daemon: đọc tập tin crontab và thực hiện các công việc trong đó
Trang 56 Ngày trong tuần (Sun=0, Mon=1, Sat=6)
Chương trình có thể được chạy vào một ngày nào đó và tại một thời điểm cụ thể.
0 2 * * * /bin/organize_data
Trang 57 command is run at one min past every
hour
command is run daily at 8:17 am
command is run daily at 8:17 pm
command is run at 4 am every Sunday
command is run 4:42 am every 1st of the month
command is run hourly on the 19th of July
Trang 58crontab command - maintain crontab files
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }
-l: display current crontab on stdout
-r: remove current crontab
-e: edit current crontab
$ crontab -l
5 0 * * * echo “this is a test”
Trang 59Red Hat System wide cron
Trang 60Q &A