Linux系统文件权限+计划任务+日志系统


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 ilename
2.sgid 2 chmod g+s f ilename chmod 2755 f ilename
3.sticky-bit 1 chmod o+t f ilename chmod 1755 f ilename
(三)文件系统权限
1. chattr (设置文件系统权限) a 只能追加 I 不能修改 具体权限选项可以 man chattr
2. lsattr (查看文件系统权限) -d 查看文件夹
(四)facl 文件访问控制列表
1. facl 只能针对分区设置
2. Vi /etc/fstab 在该分区
/dev/sda6 /boss ext3 defaults,acl 0 0
3. mount -o remount /boss
4. 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 0
3. mount -o remount /boss (重新挂载文件系统)
4. quotacheck -cugm/home
5. 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 0
6. edquota -g groupname (编辑组的磁盘配额)
Disk quotas for group root (gid 0):
Filesystem blocks soft hard inodes soft hard
/dev/sda11 3105312 0 0 6 0 0
7.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/08
at> wall "hello world" 命令
at> Ctrl+z 保存关闭
corn * * * * *
分 时 日 月 周
32 15 * * *
/var/spool/at (保存目录)
2.crontab -e (编辑周期计划任务)
/etc/init .d/crond start (守护进程必须开启)
crontab格式说明
minute 0-59
hour 0-23
day of month 1-31
month 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 运行信息邮件发送给root
HOME=/
# 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.daily
7 70 cron.weekly run-parts /etc/cron.weekly
30 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(用户) 、uucp
local0 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.conf
3.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 stuff
cron.* /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.log
local7.* /var/log/boot.log
4. #种类.等级
#*.debug 所有种类.调试
#*.!=info 除了info以外的信息都要
#*.!info 除了info以上的信息都要
#mail,kern.debug 指定 mail,kern 两个对象的 debug 信息
#kern.* /dev/console
*.* @192.168.0.1
5. 默认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 details
SYSLOGD_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 details
KLOGD_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服务的访问日志放到日志服务器上
CustomLog "| logger -p local4.info -t apache " common
9.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 backlogs
rotate 4 (保存一个月的日志量)
# create new (empty) log f iles after rotat ing old ones
create (创建新增文件通过创建方式)
# uncomment this if you want your log f iles compressed
#compress (是否使用压缩)
# RPM packages drop log rotat ion informat ion into this directory
include /etc/logrotate. d
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}
 

相关内容

    暂无相关文章