Linux系統檔案許可權+計劃任務+日誌系統 實驗目的:熟練掌握檔案許可權相關概念和具體操作實驗環境:Red Hat Enterprise Linux Server 5.3實驗步驟:一、檔案許可權二、計劃任務三、日誌系統一、檔案許可權(一)基本許可權1. r (讀,4)w(寫,2) x(執行,1)2. u (所有者)g(所有組) o(其它)3. chmod (改變檔案許可權)chown (改變檔案所有者和所有組)4. chmod 777 boss (設定boss檔案為可讀,可寫,可執行)5. chown boss.root (設定 boss檔案為boss使用者所有,root 組所有,預設改變檔案所有者)6. chgrp groupname f i lename (改變檔案的所有組)(二)特殊許可權1.suid 4 chmod u+s f ilename chmod 4755 f ilename2.sgid 2 chmod g+s f ilename chmod 2755 f ilename3.sticky-bit 1 chmod o+t f ilename chmod 1755 f ilename(三)檔案系統許可權1. chattr (設定檔案系統許可權) a 只能追加 I 不能修改 具體許可權選項可以 man chattr2. lsattr (查看檔案系統許可權) -d 查看檔案夾(四)facl 檔案存取控制清單1. facl 只能針對分區設定2. Vi /etc/fstab 在該分區/dev/sda6 /boss ext3 defaults,acl 0 03. mount -o remount /boss4. set facl -m u:username:permit ion f ilename(針對使用者佈建)5. set facl -m g:groupname:permit ion filename(針對組設定)6. set facl -x username f ilename(刪除使用者佈建)7. set facl -x groupname f ilename(刪除群組設定 )8. getfacl f ilename(查看檔案設定)(五)磁碟配額1. quota 只能針對分區設定2. vi /etc/fstab (使該分區支援 quota)/dev/sda6 /boss ext3 defaults,usrquota,grpquota 0 03. mount -o remount /boss (重新掛載檔案系統)4. quotacheck -cugm/home5. edquota username (編輯使用者的磁碟配額)Disk quotas for user user1 (uid 503): (單位是k)Filesystem blocks soft hard inodes sof t hard/dev/sda11 0 0 0 0 0 06. edquota -g groupname (編輯組的磁碟配額)Disk quotas for group root (gid 0):Filesystem blocks soft hard inodes soft hard/dev/sda11 3105312 0 0 6 0 07.quotaon /home (開啟磁碟配額)8. repquota -a (查看系統的磁碟配額)9. edquota -t (查看到期時間)10. setquota (命令列設定磁碟配額)setquota username (block soft ) (block hard) (inode sof t) (inode hard)二、計劃任務1.at 臨時計劃任務at 15:18 10/30/08at> wall "hello world" 命令at> Ctrl+z 儲存關閉corn * * * * *分 時 日 月 周32 15 * * */var/spool/at (儲存目錄)2.crontab -e (編輯周期計劃任務)/etc/init .d/crond start (守護進程必須開啟)crontab格式說明minute 0-59hour 0-23day of month 1-31month 1-12 (or names, see below)day of week 0-7 (0 or 7 is Sun, or use names)Minute hour day month week command分 時 日 月 周 命令3.crontab -l(查看目前使用者的 cron計劃工作清單) crontab -u (指定使用者)4.crontab -r(清除所有計劃任務) crontab f ilename (把檔案讀入 crontab中)5.cd /var/spool/cron/ (crontable 任務儲存位置)6.vim/etc/crontab(系統管理的計劃任務)SHELL=/bin/bash 執行環境PATH=/sbin:/bin:/usr/sbin:/usr/bin 命令執行環境MAILTO=root 運行資訊郵件發送給rootHOME=/# run-parts 目錄下的指定的指令碼(遺漏補充指令碼)01 * * * * root run-parts /etc/cron.hourly (每小時的第一分鐘)02 4 * * * root run-parts /etc/cron.daily (每天的淩晨4點 02 分)22 4 * * 0 root run-parts /etc/cron.weekly (每周日的淩晨4點 22 分)42 4 1 * * root run-parts /etc/cron.monthly(每月的 1號的淩晨 4點42分)運行身份 指定目錄 目錄(運行目錄下面所有的指令碼)7.anacron#vim /etc/anacrontab 檢測cron(日.星期.月)是否運行,如果沒有運行,立即補充運行1 65 cron.daily run-parts /etc/cron.daily7 70 cron.weekly run-parts /etc/cron.weekly30 75 cron.monthly run-parts /etc/cron.monthly時限1天發現cron.daily 沒有運行,則就運行/etc/cron.daily 65: 延時 65 分鐘7天發現cron.daily 沒有運行 70: 延時 70 分鐘30 天發現 cron.monthly 75: 延時 75 分鐘8./var/spool/anacron (anacron 儲存位置)9. anacron 守護進程10.spool/anacron 檔案都記錄上次啟動並執行時間(每次運行完成後都會改變)計算時間差三、日誌系統1.dmesg 查看系統初始化資訊2.日誌守護進程 syslogd klogd種類:auth(驗證),authpriv、cron(計劃任務) 、daemon、kernl(核心) 、lpr(列印) 、mail(郵件)mark(時間戳記通常關閉) 、news(新聞),security(same as auth)、syslog、user(使用者) 、uucplocal0 through local7(使用者自訂)等級: debug, info(詳細), not ice(通知), warning(警告), warn (same as warning)err(錯誤資訊)error (same as err)crit , alert, emerg,panic(恐慌) (same as emerg).#man 5 syslog.conf3.vim /etc/syslog.conf# Log all kernel messages to the console.# Logging much else clutters up the screen.#kern.* /dev/console (發送到控制台)# Log anything (except mail) of level info or higher.# Don't log private authent icat ion messages!*.info;mail.none;authpriv.none;cron.none /var/log/messages(所有對象的info以上的等級,除了 main、authpriv、cron)# The authpriv f ile has restricted access.authpriv.* /var/log/secure(authpriv 的所有等級資訊,儲存到/var/log/secure檔案中)# Log all the mail messages in one place.mail.* -/var/log/maillog(mai l 對象的所有等級,立即儲存到/var/log/maillog 檔案中)# Log cron stuffcron.* /var/log/cron(cron 對象的所有等級,儲存到/var/log/cron 檔案中)# Everybody gets emergency messages*.emerg *(所有對象最嚴重的等級,發送給所有使用者)# Save news errors of level crit and higher in a special f ile.uucp,news.crit /var/log/spooler# Save boot messages also to boot.loglocal7.* /var/log/boot.log4. #種類.等級#*.debug 所有種類.調試#*.!=info 除了info以外的資訊都要#*.!info 除了info以上的資訊都要#mail,kern.debug 指定 mail,kern 兩個對象的 debug 資訊#kern.* /dev/console*.* @192.168.0.15. 預設syslog日誌同步, -不同步設定 支援發送至/dev/tty1(控制台),@192.168.0.1(遠程伺服器)日誌預設直接記錄到磁碟(如果需要緩衝區的在目錄前-)重新啟動syslog(新配置後重啟生效)#tail -f /var/log/messages 查看記錄檔Oct 31 10:08:54 localhost syslogd 1.4.1: restart (remote recept ion). m日期 主機 進程名稱 訊息6.vim /etc/syscongif/syslog (開啟遠程日誌接收)—————————————————————————————————————————————#Opt ions to syslogd# -m 0 disables 'MARK' messages. (關閉 mask對象)# -r enables logging fromremote machines (接受來自遠端電腦的日誌)# -x disables DNS lookups on messages recieved with (關閉 DNS 解析)# See syslogd(8) for more detailsSYSLOGD_OPTIONS="-m 0" (改為 SYSLOGD_OPTIONS="-m 0 -f -x")#Opt ions to klogd# -2 prints all kernel oops messages twice; once for klogd to decode, and# once for processing with 'ksymoops'# -x disables all klogd processing of oops messages ent irely# See klogd(8) for more detailsKLOGD_OPTIONS="-x"#SYSLOG_UMASK=077# set this to a umask value to use for all log f iles as in umask(1).# By default , all permissions are removed for "group" and "other" .—————————————————————————————————————————————7.logger -p kern.info(層級) "內容" -t 對象 手動發送日誌,-p指定物件類別,發送資訊8.把web服務的訪問日誌放到Log Service器上CustomLog "| logger -p local4.info -t apache " common9.syslogd 使用514連接埠,通過iptables控制接受哪些使用者的日誌10.日誌輪詢 每天都執行 放在/etc/cron.daily/中vim /etc/logrotate.conf# see "man logrotate" for details# rotate log f iles weeklyweekly (檔案記錄周為單位)# keep 4weeks worth of backlogsrotate 4 (儲存一個月的日誌量)# create new (empty) log f iles after rotat ing old onescreate (建立新增檔案通過建立方式)# uncomment this if you want your log f iles compressed#compress (是否使用壓縮)# RPM packages drop log rotat ion informat ion into this directoryinclude /etc/logrotate. d# no packages own wtmp -- we'll rotate them here/var/log/wtmp {monthlycreate 0664 root utmprotate 1}