Post on 30-Dec-2015
description
網路伺服器應用Linux Server
Andres, Wen-Yuan Liao
Department of Computer Science and Engineering
De Lin Institute of Technology
andres@dlit.edu.twhttp://www.cse.dlit.edu.tw/~andres
第 4 章 系統管理
4-1 使用者帳號管理4-2 檔案權限管理4-3 開機與關機 4-4 deamon
4-1 使用者帳號管理
群組與權限系統管理員( root )每個使用者 檔案與目錄
root 帳號 系統設定管理
adduser, userdel 指令passwd 指令
useradd
新增使用者(帳號) useradd –D useradd –g useradd –s /bin/csh useradd –f 10
passwd password 設定密碼
userdel
userdel user delete 刪除與修改使用者帳號 userdel –t username
su
switch user轉換使用者帳號
su username轉換成 root 管理員
日常使用 Linux 時用一般使用者的帳號操作需要 root 權限su -
/etc/passwd, etc/shadow
/etc/passwd 檔案 使用者的帳號與密碼等相關資料 使用文字編輯器來觀看這個檔案 root:x:0:0:root:/root:/bin/bash
Username Password UID (user ID) GID (group ID) Name Home directory shell
4-2 檔案權限管理
所有軟硬體裝置通通視為檔案 權限管理只要在意檔案權限的設定即可
Linux 的做法比較單純 Linux 的安全等級比 windows 更早獲得美國國家
安全局的認證。
檔案權限
檔案擁有者擁有人 (owner)擁有群組 (group)
存取權限 (mode)某使用者帳號被移除
檔案忘記移除,變成無人擁有檔案視同 root 所擁有
檔案權限
drwxrwxrwx owner group other
第一個字 (-/d) file (-) or directory (d)
每個權限都由三個位元構成 read ( r ) write (w) execute (x)
檔案權限
ls -alrwxr-xr-x
- 沒有權限,owner 可讀寫執行group 可讀及執行other 可讀及執行。八進位數字 755 來表示
chown, chgrp
chownchange owner更改擁有者chown root filename
chgrpchange group更改群組chgrp 755 filename
4-3 開機與關機
開機的步驟與程序:BIOSLoaderOS kernel /sbin/init init 執行 /etc/rc.d/rd.sysinit init 執行 run level init 執行 /etc/rc.d/rc.local
Loader
BIOS 在開機磁碟機的第 0 磁區、第 0 磁柱(MBR, master boot record) 載入開機的磁區
開機載入程式 (boot loader) 「開機管理程式」可以選擇:是啟動 Linux 作業系
統,還是 Windows 作業系統 LILO
LInux LOader /etc/lilo.conf 檔案
GRUB 預設的開機管理程式 Erich Stefan Boleyn 設計與撰寫 /etc/grub.conf 檔案
/etc/grub.conf
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.4.18-14)
root (hd0,0)
kernel /vmlinuz-2.4.18-14 ro root=LABEL=/
initrd /initrd-2.4.18-14.img
OS kernel
找出 kernel 所在位置,接著載入並執行它以啟動開機程序
一旦 kernel 載入完畢,一些基本設備也完成初始化 (initialization) Linux kernel :
/boot/vmlunz-2.4.18-14Mandrake
Windows kernel
kernel 執行 /sbin/init
嘗試從某個設備載入以及掛上 (mount) root filesystem 一旦 root filesystem 被載入並掛上,會看到一行
訊息像: VFS: Mounted root (ext3 filesystem) readonly
此時系統會在 root filesystem 上找到 init 程式 ( 在 /bin or /sbin) 並執行
init 讀取它的組態設定檔 (configuration file) /etc/inittab
/etc/inittab
# Default runlevel. The runlevels used by RHS are:# 0 - halt (Do NOT set initdefault to this)# 1 - Single user mode# 2 - Multiuser, without NFS (The same as 3, if you d
o not have networking)# 3 - Full multiuser mode# 4 - unused# 5 - X11# 6 - reboot (Do NOT set initdefault to this)# id:5:initdefault:
init 執行 /etc/rc.d/rc.sysinit
/etc/inittab# System initialization.si::sysinit:/etc/rc.d/rc.sysinit
啟動基本系統服務: 對所有磁碟執行 fsck 載入必備的核心模組 (modules) 啟動 swapping 進行網路初始化 將指定在 fstab 內的磁碟掛上
init 執行 run level
當 sysinit script 結束後,控制權回到 init 上,接著進入預設的 runlevel
/etc/inittabl0:0:wait:/etc/rc.d/rc 0l1:1:wait:/etc/rc.d/rc 1l2:2:wait:/etc/rc.d/rc 2l3:3:wait:/etc/rc.d/rc 3l4:4:wait:/etc/rc.d/rc 4l5:5:wait:/etc/rc.d/rc 5l6:6:wait:/etc/rc.d/rc 6
/etc/rc.d/*
包含系統「開機與關機」時必須執行的執行檔或 Script 檔案
/etc/rc.d/rcX.d/* :X 表示 0~6 Link ->/etc/rc.d/init.d/* 以「 S 」開頭
startup 進入 level 時要執行的檔案
以「 K 」開頭kill退出 level 時要執行的檔案
/etc/rc.d/rc.local
init 執行 /etc/rc.d/rc.local #!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
開機
關機
少有重複開關機的現象 /etc/rc.d/init.d/httpd restart
重新啟動或是暫停某一項服務不需重新開機
關機
sync 指令 shutdown 指令
shutdown now shutdown –r shutdown –h now shutdown –Fshutdown +3
reboot
重新啟動系統預設值會自動執行 sync
halt
先偵測系統的 run level halt -d
關閉系統,但不將資料寫入記錄檔halt -p
關閉系統,並關閉電源halt -t
先關閉所有的網路介面之後,再關閉系統
4.4 daemon
Stand_aloneSuper daemon***d
Stand_alone
/etc/rc.d/init.d/* /etc/rc.d/init.d/syslog startService syslog start
Super daemon
/etc/rc.d/init.d/xinetd /etc/xinetd.conf /etc/xinetd.d/*