开机流程 访问控制和服务启动设置

源码包比较好的下载的网站
http:.//sourceforget.net
链接
linux的链接分为软链接和硬链接
软链接相当于微软下面的快捷图标
特点 可以跨越分区,可以对目录创建,创建时产生一个新的inode,代表一个独立的文件
硬链接
特点 不能跨分区,不能对目录创建,不会创建一个新的inode,相当于对原有文件的路径访问,间接
起到备份的作用
注:inode 文件存储的位置
创建的方法
软链接 ln -s 链接目标文件 链接名
eg:
现查看原有的Inode
[root@localhost yumtest]# ll -i
total 65788
13238274 -rwxr-xr-x 1 root root 62230770 May 20 16:35 AdobeReader_chs-8.1.7-1.i486.rpm
13238275 -rwxr-xr-x 1 root root 5046743 May 20 16:36 linuxqq-v1.0.2-beta1.i386.rpm
13271042 drwxr-xr-x 2 root root 4096 May 21 15:08 repodata
[root@localhost yumtest]#
创建链接
[root@localhost yumtest]# ln -s linuxqq-v1.0.2-beta1.i386.rpm qq
[root@localhost yumtest]# ll -i
total 65788
13238274 -rwxr-xr-x 1 root root 62230770 May 20 16:35 AdobeReader_chs-8.1.7-1.i486.rpm
13238275 -rwxr-xr-x 1 root root 5046743 May 20 16:36 linuxqq-v1.0.2-beta1.i386.rpm
13238276 lrwxrwxrwx 1 root root 29 May 24 16:56 qq -> linuxqq-v1.0.2-beta1.i386.rpm
13271042 drwxr-xr-x 2 root root 4096 May 21 15:08 repodata
[root@localhost yumtest]#
发现,是产生了一个新的inode的,也就是一个新的文件
硬链接
ln 链接目标 链接名
eg
[root@localhost yumtest]# ln linuxqq-v1.0.2-beta1.i386.rpm qq2
[root@localhost yumtest]# ll -i
total 70732
13238274 -rwxr-xr-x 1 root root 62230770 May 20 16:35 AdobeReader_chs-8.1.7-1.i486.rpm
13238275 -rwxr-xr-x 2 root root 5046743 May 20 16:36 linuxqq-v1.0.2-beta1.i386.rpm
13238276 lrwxrwxrwx 1 root root 29 May 24 16:56 qq -> linuxqq-v1.0.2-beta1.i386.rpm
13238275 -rwxr-xr-x 2 root root 5046743 May 20 16:36 qq2
13271042 drwxr-xr-x 2 root root 4096 May 21 15:08 repodata
[root@localhost yumtest]#
可以看到,新的qq2跟原先的目标文件的inode是一致的,说明,并没有新的文件产生,只是,多了一条
路径而已
系统启动的过程
开机->bios加电自检,找到启动设备
->找到MBR
->grub(找到内核和initrd)
->内核启动,产生init进程
->/etc/rc.sysinit(获取主机的网络环境也就是系统初始化)
->/etc/inittab确定启动级别
->执行/etc/rc.d(rc.d下所有以S开头的脚本)/
->/etc/rc.local(模式为5的情况)
inittab 启动模式
0: 关机
1: 单用户模式 只能root登录,不需要密码
2: 多用户模式 不能NFS等网络服务
3: 完全多用户模式 但没图形界面
4: 保留未用
5: 图形
6: 重启
在/etc/inittab中
id:5:initdefault: 决定启动模式
如果是图形界面的自启动程序 在/etc/X11/xinit/xinitrc.d/中
比如,你想让你的火狐浏览器开机自启动,就需要在里面添加一个.sh的脚本
[root@localhost yumtest]# cd /etc/X11/xinit/xinitrc.d/
[root@localhost xinitrc.d]# ls
localuser.sh sabayon-xinitrc.sh wacomcpl.sh xinput.sh
[root@localhost xinitrc.d]#
默认的为上面这些,我这里,添加一个firefox.sh的脚本
[root@localhost xinitrc.d]# vim firefox.sh
#!/bin/bash
/usr/bin/firefox &
路径可以通过which找寻
[root@localhost xinitrc.d]# which firefox
/usr/bin/firefox
服务管理
服务是一组后台进程,不管有没有用,一直在运行
服务的启动脚本一般放在/etc/rc.d/init.d/中
[root@localhost /]# cd /etc/rc.d/
[root@localhost rc.d]# ls
init.d rc rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.local rc.sysinit
在/etc/rc.d/rcn.d(n代表数字)中有其软链接
服务启动
service service_name start
service service_name stop
service service_name restart
所有的service启动服务都是调用/etc/rc.d/init.d/下的脚本,但并不是所有的脚本都能被service所调用,如
果要被service所调用,必须遵循一定的格式
控制服务的开机启动
ntsysv
练习:尝试将sendmail设置成开机不启动
chkconfig --list 查看开机服务设置
--level 2345 service_name on/off
eg: chkconfig --level 3 sendmail off
-add 添加一个chkconfig管理服务
--del 删除一个chkconfig管理服务
练习:将sendmail iptables ip6tables autofs 服务开机禁用
案例:
场景一:有a b c d三用户,对test文件权限要求
a r
b r-x
c rwx
d wx
碰到这种问题,我们如果用单纯的权限来工作,肯定会很艰难,而且基本上是不可能,那么,我们就需要
使用一种叫ACL访问控制列表的规则来定义相应的权限
ACL:针对同一个文件或目录,对不同的用户实现不同的权限色绘制,它是在内核级别上实现的,
linux从2.6开始支持对ext2 ext3 xfs jfs等文件系统的支持
ACL实现的前提条件
1 内核支持
可以通过uname -r /boot/config-xxx查看
[root@localhost desktop-integration]# uname -r
2.6.18-194.el5
[root@localhost boot]# cat config-2.6.18-194.el5 |grep ACL
CONFIG_EXT2_FS_POSIX_ACL=y
CONFIG_EXT3_FS_POSIX_ACL=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_FS_POSIX_ACL=y
CONFIG_NFS_V3_ACL=y
CONFIG_NFSD_V3_ACL=y
CONFIG_NFS_ACL_SUPPORT=m
2 文件系统支持
tune[root@localhost boot]# tune2fs -o acl /dev/hd8
tune2fs 1.39 (29-May-2006)
[root@localhost boot]# tune2fs -l /dev/hdb8 |grep acl
Default mount options: user_xattr acl
挂载时要加入acl选项
mount -o acl 分区,挂载点
mount -o acl /dev/hdb6 /share
如果是已经挂载的
mount -o remount,acl /dev/hdb6 /share
ACL操作
setfacl 设置文件的acl信息
getfacl 查看文件的acl信息
setfacl [选项] 文件名
-m 设置ACL
-x 取消ACL
-b 清空文件的ACL设置
setfacl -m u:oracle:rw uu.txt
setfacl -x g:dba uu.txt
上述题目的做法
[root@localhost etc]# useradd a
[root@localhost etc]# passwd a
[root@localhost etc]# useradd b
[root@localhost etc]# passwd b
[root@localhost etc]# useradd c
[root@localhost etc]# passwd c
[root@localhost etc]# useradd d
[root@localhost etc]# passwd d
在这里,我为了省麻烦,直接把处理过程写到脚本中,也就是
[root@localhost tmp]# vim setfacl.sh
#!/bin/bash
setfacl -m u:a:r test
setfacl -m u:b:rx test
setfacl -m u:c:rwx test
setfacl -m u:d:wx test
[root@localhost tmp]# chmod u+x setfacl.sh
[root@localhost tmp]# ./setfacl.sh
[root@localhost tmp]# getfacl test # file: test
# owner: root
# group: root
user::rwuser:
a:r--
user:b:r-x
user:c:rwx
user:d:-wx
group::r--
mask::rwx
other::r--
[root@localhost tmp]# ll
total 8
-rwxr--r-- 1 root root 105 May 24 19:13 setfacl.sh
-rw-rwxr--+ 1 root root 0 May 24 19:12 test
可以看到,这个时候,就生成了,接下来,就需要你去切换用户尝试
但是
一旦用户多起来,要进行权限修改的时候,发现,是非常繁琐的,这个时候,就可以用到
mask来统一管理权限
setfacl -m mask::r uu.txt
[root@localhost tmp]# setfacl -m mask::r test
[root@localhost tmp]# getfacl test
# file: test
# owner: root
# group: root
user::rwuser:
a:r--
user:b:r-x #effective:r--
user:c:rwx #effective:r--
user:d:-wx #effective:---
group::r--
mask::r--
other::r--
[root@localhost tmp]#
可以看到,mask之后的变化,接着,切换用户发现之具有R的权限
取消acl,可以使用
[root@localhost tmp]# setfacl --remove-all test
[root@localhost tmp]# getfacl test
# file: test
# owner: root
# group: root
user::rwgroup::
r--
other::r--
第二种清除方法
[root@localhost tmp]#
[root@localhost tmp]# ./setfacl.sh
[root@localhost tmp]# getfacl test
# file: test
# owner: root
# group: root
user::rwuser:
a:r--
user:b:r-x
user:c:rwx
user:d:-wx
group::r--
mask::rwx
other::r--
[root@localhost tmp]#
[root@localhost tmp]# setfacl -b test
[root@localhost tmp]# getfacl test
# file: test
# owner: root
# group: root
user::rwgroup::
r--
other::r--
[root@localhost tmp]#
我们如何去备份这些信息,可以
getfacl test >acl.bak 即可
如果是目录
getfacl -R share >acl1.bak
[root@localhost tmp]# getfacl test >all.bak
[root@localhost tmp]# setfacl -b test
[root@localhost tmp]# getfacl test
# file: test
# owner: root
# group: root
user::rwgroup::
r--
other::r--
还原
setfacl --restore=all.bak
[root@localhost tmp]# setfacl --restore=all.bak
[root@localhost tmp]# getfacl test
# file: test
# owner: root
# group: root
user::rwuser:
a:r--
user:b:r-x
user:c:rwx
user:d:-wx
group::r--
mask::rwx
other::r--
[root@localhost tmp]#
Linux中的打包压缩
1 compress 默认没安装
yum install compress*
比较老的压缩方式
compress ull.vmdk -->ull.vmdk.z
容量变小,直接在原文件压缩,原文件会消失
解压
compress -d ull.vmdk.z
2 gzip 压缩
gzip file -->file.gz
解压
gzip -d file_name.gz
3 bzip 压缩 目前是最高的
bzip -z filename 但速度比较慢
4 rar 需安装
tar xvf rarlinx...tar.gz
cd rar
make
make install

你可能感兴趣的:(职场,访问控制,休闲,开机流程,服务启动设置)