http://10.1.1.35/ule_basic/ule06.txt

--
硬链接和软链接


inode:每当创建一个文件和目录的时候,都会为这个文件创建一个innode编号,这些信息都是存放在innode表里


软链接: 类似windows上的快捷方式

[root@li ~]# ll /etc/grub.conf
lrwxrwxrwx 1 root root 22 Mar 27 03:14 /etc/grub.conf -> ../boot/grub/grub.conf

ln - make links between files


[root@li ~]# which vi
/bin/vi
[root@li ~]# which vim
/usr/bin/vim
[root@li ~]# mv /bin/vi
vi view
[root@li ~]# mv /bin/vi /bin/vi.bak
[root@li ~]# ln -s /usr/bin/vim /bin/vi






[root@li test]# ll -i
total 0
327363 -rw-r--r-- 1 root root 0 Apr 18 09:51 a
327364 lrwxrwxrwx 1 root root 1 Apr 18 09:51 b -> a --innode编号不一样


特点:
1,它会创建一个新的innode编号,相当是一个独立的文件
2,它类似于windows下的快捷方式,访问的时候多了一个中转的过程,最终访问的内容就是它链接的目标文件
3,它可以跨分区创建
4,它可以对目录进行链接




硬链接:


[root@li test]# touch 1
[root@li test]# ln 1 2

[root@li test]# ll -i
total 4
327367 -rw-r--r-- 2 root root 0 Apr 18 09:56 1
327367 -rw-r--r-- 2 root root 0 Apr 18 09:56 2


[root@li test]# ln 3 /boot/4
ln: creating hard link `/boot/4' to `3': Invalid cross-device link




特点:
1,它不会新创建一个innode编号,不代表一个独立的文件
2,它不能跨分区创建
3,它相当于是为文件创建了一个冗余
4,不能手工对目录进行硬链接

[root@li mail]# pwd
/var/mail
[root@li mail]# pwd -P
/var/spool/mail


[root@li mail]# cd /etc/init.d/
[root@li init.d]# pwd -P
/etc/rc.d/init.d


--------------------------------------------------------------------------------

系统开机启动过程:

开机-->bios(配置主板的程序,basic input and output system,加电自检,找到启动设备的编号)-->找到mbr(master bootloader record,它是属于硬盘的0磁盘0扇区)-->grub-->通过grub找到vmlinuz和initrd(驱动硬件)--> 内核启动,产生init进程-->/etc/inittab(确定系统的启动级别)-->/etc/rc.sysinit(获取主机的网络环境和主机类型,测试与载入设备,是否启动selinux,模块的加载,设置系统时间.................)-->/etc/rc.local


vim /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 do not have networking)--多用户模式,但没有NFS,没有网络
# 3 - Full multiuser mode --带网络的文本多用户模式,如果3模式没有网络的话就和2模式一样
# 4 - unused --保留
# 5 - X11 --图形模式
# 6 - reboot (Do NOT set initdefault to this) --重启
#
id:5:initdefault: --设定开机后默认的启动级别,不要设成0或者6,如果设成0或者6致命开机不了,在grub的选择界面按E编辑这一次启动进入5模式(临时,只对这次进系统有效),进入后再修改/etc/initab(这是永久生效)

# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3 --这是定义六个级别启动的服务脚本,这六个目录的服务脚本全是做的
l4:4:wait:/etc/rc.d/rc 4 --/etc/rc.d/init.d目录下脚本的软链接
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now --定义ctrl+alt+del三键重启功能

# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"


# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6 --定义六个文本界面终端 tty

# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon --启动图形




--------------------------------------------------


服务管理


手动启动或关闭服务,与开机自动自动启动服务无关
service httpd start
service httpd stop
service httpd restart

/etc/init.d/httpd restart

/etc/init.d/和/etc/rc.d/init.d 目录下存放的都是服务启动脚本

对于一个服务脚本,一般都有下面两行注释
# chkconfig: - 85 15
- 代表所有运行级别(0-6),如果要自定级别的话在这里可以用数字表示,例如:2345
85 代表开机时启动的顺序号为85
15 代表关机时关闭服务的顺序号为15
# description: Apache is a World Wide Web server. It is used to serve /
# HTML files and CGI.





[root@li ~]# ll /etc/rc0.d/ --看一下 0级别的启动脚本
K01dnsmasq K35vncserver K87multipathd
K01setroubleshoot K35winbind K87portmap



[root@li ~]# ll /etc/rc5.d/ --对比一个5级别的启动脚本
K01dnsmasq K89rdisc S25pcscd
K02avahi-dnsconfd K91capi S26acpid
K02NetworkManager S00microcode_ctl S26apmd


k 代表kill 就是指开机不自动启动
s 代表start 就是指开机自动启动


---------------------
手动修改服务开机自动启动或者不启动
命令
chkconfig - updates and queries runlevel information for system services


[root@li ~]# chkconfig --list --查看服务开机在各个级别是否启动
NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off
anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off
apmd 0:off 1:off 2:on 3:on 4:on 5:on 6:off


[root@li ~]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off


修改httpd服务开机后不自动启动
[root@li ~]# chkconfig httpd off
[root@li ~]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

修改httpd服务开机后自动启动
[root@li ~]# chkconfig httpd on
[root@li ~]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

可以针对特定的级别来设定开机后自动启动或者关闭
[root@li ~]# chkconfig httpd off --level 23
[root@li ~]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:off 3:off 4:on 5:on 6:off

删除一个服务(--只是chkconfig命令看不到了)
[root@li ~]# chkconfig --del httpd
[root@li ~]# chkconfig --list |grep httpd

添加一个服务(相对于chkconfig --del)
[root@li ~]# chkconfig --add httpd
[root@li ~]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
有两点要求:1, 服务脚本要存在于/etc/init.d或者是/etc/rc.d/init.d
2, 就是要有 # chkconfig:
# description: 这两行



图形配置服务开机自动启动或者关闭
命令

ntsysv - simple interface for configuring runlevels

默认是配置当前的level

ntsysv --level 35 用--level定义级别



每个服务前去掉*就表示开机不自动启动

按F1的话可以看到服务的描述,对应服务脚本里的description

就目前所学大概留下的服务network,portmap,sshd,syslog,vmware,gpm


--一般在一台服务新安装完系统后,就应该根据业务需要,把不用的服务的开机自动启动给关掉,优化开机速度


---------------------------------------

[root@li rc5.d]# runlevel --看当前的运行级别
N 5






-------------------------------------------------------


磁盘配额 quota

可以以用户来配额,也可以以组来配额


应用的场景:

web服务器 对web空间进行限制
邮件服务器 对用户的邮件空间进行限制
文件服务器 对用户的文件共享空间进行限制


quota的使用限制:

1,它只能对分区有效
2,内核要支持quota
3,只能针对普通用户,不能限制root用户


quota的限制方式:

1,block
2,inode 对文件个数来做限制,不太好用,但可以和block一起使用

--第一步:
先分一个区出来做测试:


fdisk /dev/sda

Command (m for help): n --新建一个分区
First cylinder (21848-38913, default 21848):
Using default value 21848
Last cylinder or +size or +sizeM or +sizeK (21848-22195, default 22195): +1000M --指定分区为1000M大小
Using default value 22195

Command (m for help): w --保存并退出

[root@li /]# partprobe --将刚分区的信息刷新到磁盘分区表

[root@li /]# mkfs.ext3 /dev/sda13 --格式化刚分的分区


[root@li /]# mkdir /quota --创建一个目录用于quota试验的挂载



--第二步:
挂载刚分的区,注意挂载参数
[root@li /]# mount -t ext3 -o usrquota,grpquota /dev/sda13 /quota/ --usrquota指支持以用户来配额,grpquota指支持以组来配额


[root@li /]# mount
/dev/sda13 on /quota type ext3 (rw,usrquota,grpquota) --用mount命令验证挂载参数

要想永久生效:

写到/etc/fstab

/dev/sda13 /quota ext3 defaults,usrquota,grpquota 0 0


--第三步:
对要使用quota功能的分区生成quota配置文件
命令为quotacheck
quotacheck - scan a filesystem for disk usage, create, check and repair
quota files

[root@li /]# cd /quota/
[root@li quota]# ls
lost+found
quotacheck -cauvg
-c 忽略已经原有的配置文件并再次生成
-a 扫描所有使用挂载参数挂载的分区,并对他们生成配置文件
-u 生成与用户配额有关的配置文件
-g 生成与组配额有关的配置文件
-v 可以看到生成配置过程信息

[root@li quota]# quotacheck -cauvg --对启用quota的分区生成配置文件
quotacheck: Scanning /dev/sda13 [/quota] quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory --第一次扫描有报错,没关系
done
quotacheck: Checked 3 directories and 2 files
quotacheck: Old file not found.
quotacheck: Old file not found.

[root@li quota]# ls --再次列表查看,会发现多了两个配置文件
aquota.group aquota.user lost+found


--第四步:
开始对用户使用配额

[root@li quota]# edquota -u a


Disk quotas for user a (uid 533):
Filesystem blocks soft hard inodes soft hard
/dev/sda13 0 20000 30000 0 0 0
--软限制为20M ,硬限制为30m inode不好控制,不建议使用



[root@li quota]# edquota -u b

Disk quotas for user a (uid 533):
Filesystem blocks soft hard inodes soft hard
/dev/sda13 0 40000 50000 0 0 0


--第五步:
启用quota功能
quotaon /dev/sda13



--第六步:
查看配额的使用情况:
[root@li quota]# repquota -a
*** Report for user quotas on device /dev/sda13
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 69712 0 0 4 0 0



[root@li quota]# repquota -avugs --查看更详细的磁盘配额
-a 直接搜索有quota标志的分区,报告quota的结果
-v 显示详细信息
-u 显示使用者的quota值
-g 显示组的quota值
-s Try to report used space, number of used inodes and limits in
more appropriate units than the default ones.

*** Report for user quotas on device /dev/sda13
Block grace time: 7days; Inode grace time: 7days --grace time指的是宽限时间,默认是7天
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 69712 0 0 4 0 0
a -- 0 20000 30000 0 0 0
b -- 0 40000 50000 0 0 0

Statistics:
Total blocks: 7
Data blocks: 1
Entries: 3
Used average: 3.000000

*** Report for group quotas on device /dev/sda13
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Group used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 69712 0 0 4 0 0

Statistics:
Total blocks: 6
Data blocks: 1
Entries: 1
Used average: 1.000000



宽限时间(grace time)的修改方法:
[root@li quota]# edquota -t

Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/sda13 10days 7days



--第七步:
测试

[root@li quota]# chmod 777 /quota/ --用root用户把权限改为都可写,方便测试


下面使用a用户测试:

[root@li ~]# su - a
[a@li quota]$ dd if=/dev/zero of=/quota/a1 bs=1M count=19 --创建一个19M的文件a1,没有警告
19+0 records in
19+0 records out
19922944 bytes (20 MB) copied, 0.0535929 seconds, 372 MB/s


[a@li quota]$ dd if=/dev/zero of=/quota/a2 bs=1M count=2 --再创建一个2M的文件a2,因为19+2大于对a用户的软件限制20M,所以报警告
sda13: warning, user block quota exceeded.
2+0 records in
2+0 records out
2097152 bytes (2.1 MB) copied, 0.00702628 seconds, 298 MB/s

[a@li quota]$ dd if=/dev/zero of=/quota/a3 bs=1M count=8 --创建8M的文件a3,还没超过硬限制


[a@li quota]$ dd if=/dev/zero of=/quota/a4 bs=1M count=2 --创建2M的文件a4,超过硬限制,失败
sda13: write failed, user block limit reached.
dd: writing `/quota/a4': Disk quota exceeded
1+0 records in
0+0 records out
266240 bytes (266 kB) copied, 0.00137422 seconds, 194 MB/s


b用户测试方式也一样

root用户查看测试后的情况:

[root@li quota]# repquota -a
*** Report for user quotas on device /dev/sda13
Block grace time: 10days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 69712 0 0 4 0 0
a +- 30000 20000 30000 9days 5 0 0
b +- 50000 40000 50000 9days 2 0 0




-----------------------------------------------------------


组quota配置
要使用组quota配置,挂载时要加上grpquota的参数
1,做实验用两个或多个用户加入到一个组,要求gid相同
grupadd quota
useradd -g quota a
useradd -g quota b

usermod -g quota a

2,编辑组quota时
edquota -g quota

3,测试的时候,
对quota组的限制要以组员a和b创建文件占用大小的总和的计算



[root@li quota]# groupadd quota

[root@li quota]# useradd -g quota aa
[root@li quota]# useradd -g quota bb
[root@li quota]# id aa
uid=537(aa) gid=538(quota) groups=538(quota)
[root@li quota]# id bb
uid=538(bb) gid=538(quota) groups=538(quota)


[root@li quota]# repquota -avgs

*** Report for group quotas on device /dev/sda13
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Group used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 69712 0 0 4 0 0
a -- 30000 0 0 5 0 0
b -- 50000 0 0 2 0 0
quota -- 0 30000 40000 0 0 0

Statistics:
Total blocks: 7
Data blocks: 1
Entries: 4
Used average: 4.000000

[aa@li ~]$ dd if=/dev/zero of=/quota/aa1 bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.0339249 seconds, 309 MB/s

[bb@li ~]$ dd if=/dev/zero of=/quota/bb1 bs=1M count=21
sda13: warning, group block quota exceeded.
21+0 records in
21+0 records out
22020096 bytes (22 MB) copied, 0.0730932 seconds, 301 MB/s


[aa@li ~]$ dd if=/dev/zero of=/quota/aa2 bs=1M count=10
sda13: write failed, group block limit reached.
dd: writing `/quota/aa2': Disk quota exceeded
9+0 records in
8+0 records out
8396800 bytes (8.4 MB) copied, 0.0282151 seconds, 298 MB/s









---------------------------------------------------------------------------------


现在有a,b,c三个用户,要求对同一个文件test拥有不同的权限
对于test a r
b rw
c rwx

-r--rw-rwx a b test
-rwxr--rw- c a test

现在有一个老板boss,一个部门a,另一个部门b,要求对同一个目录test拥有不同的权限
对于test boss rwx
a rx
b wx

drwxr-x-wx boss a test


现在有多个用户,每个人对同一个文件的权限都不同



acl access control list 访问控制列表
针对同一个文件,对不同的用户实现不同的权限设置,它是内核级别实现权限控制

--要注意的:在rhel5.1,5.2版本是不能直接支持,需要挂载时加上acl参数 -o acl

[root@li test]# dumpe2fs /dev/sda8 |grep user_xattr
dumpe2fs 1.39 (29-May-2006)
Default mount options: user_xattr acl --这里有acl表示是支持acl




setfacl 设置acl命令 --对文件和目录都可以
getfacl 查看acl权限状态

setfacl - set file access control lists


EXAMPLES --man帮助文档中的例子
Granting an additional user read access
setfacl -m u:lisa:r file

Revoking write access from all groups and all named
users (using the effective rights mask)
setfacl -m m::rx file

Removing a named group entry from a file’s ACL
setfacl -x g:staff file



setfacl
-m 设置acl
-x 与-m相反
-b 清空文件所有设置的acl


[root@li test]# ll |grep test
-rw-r--r-- 1 root root 0 Apr 18 16:05 test

[root@li test]# getfacl test
# file: test
# owner: root
# group: root
user::rw-
group::r--
other::r--




[root@li test]# setfacl -m u:a:rwx test --设置a用户对test文件的权限为rwx

[root@li test]# ll |grep test --用ll查看时发现有一个+号,而且权限有点不一样,表明有acl在起作用
-rw-rwxr--+ 1 root root 0 Apr 18 16:05 test


[root@li test]# getfacl test
# file: test --指文件名
# owner: root --指文件的属主
# group: root --指文件的属组
user::rw- --指的是属主对此文件的权限
user:a:rwx --指的是a用户对此文件的权限
group::r-- --指的是属组对此文件的权限
mask::rwx --指的是一个有效位,做一个与运算
other::r-- --指的others对此文件的权限


[root@li test]# setfacl -m u:b:r test
[root@li test]# setfacl -m u:c:rx test
[root@li test]# setfacl -m u:d:wx test
[root@li test]# getfacl test
# file: test
# owner: root
# group: root
user::rw-
user:a:rwx
user:b:r--
user:c:r-x
user:d:-wx
group::r--
mask::rwx
other::r--



[root@li test]# setfacl -m g:quota:rwx test --设置quota组对test文件的权限为rwx
[root@li test]# getfacl test
# file: test
# owner: root
# group: root
user::rw-
user:a:rwx
user:b:r--
user:c:r-x
user:d:-wx
group::r--
group:quota:rwx
mask::rwx
other::r--


[root@li test]# setfacl -m o:x test --对others对test文件的权限为x
[root@li test]# getfacl test
# file: test
# owner: root
# group: root
user::rw-
user:a:rwx
user:b:r--
user:c:r-x
user:d:-wx
group::r--
group:quota:rwx
mask::rwx
other::--x


[root@li test]# setfacl -m mask:r test --对test文件的mask值设为r
[root@li test]# getfacl test
# file: test
# owner: root
# group: root
user::rw-
user:a:rwx #effective:r--
user:b:r--
user:c:r-x #effective:r--
user:d:-wx #effective:---
group::r--
group:quota:rwx #effective:r--
mask::r--
other::--x


[root@li test]# setfacl -b test
[root@li test]# getfacl test
# file: test
# owner: root
# group: root
user::rw-
group::r--
other::--x


[root@li test]# setfacl -m u:a:rw,g:b:rwx,o:r,mask:rwx test --一次设置多个acl
[root@li test]# getfacl test
# file: test
# owner: root
# group: root
user::rw-
user:a:rw-
group::r--
group:b:rwx
mask::rwx
other::r--


-------------------------------------------------------------------------

题目:
1,新建一个2G大小的分区,挂载到/abc目录,要求支持用户配额,组配额,acl功能,并要求开机后能自动挂载
2,新建三个用户a,b,c要求a,b,c三个用户的gid一致,都为a用户的gid;在/abc目录的分区对a,b,c分别配置不同的quota限制,a用户(soft 20M,hard 30M),b用户(soft 30M,hard 40M),c用户(soft 40M,hard50M)
3,并对a组配额,要求a组(soft 80m,hard 100m)
4,在/abc目录下,建立一个acl文件
要求实现
a用户属于a组 对acl rw
b用户属于a组 对acl r
c用户属于a组 对acl rwx
d用户不属于a组 对acl w
e用户不属于a组 对acl wx
5,在/abc目录下,建立一个share目录
要求实现
root用户 对share rwx
a组 对share wx
d组 对share rx









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值