unit1

######################Red Hat System Administration II##########

#############unit 1 自动安装 RED HAT ENTERPRISE LINNUX########

学习目标:

*了解kickstart自动安装脚本

*制作kickstart安装脚本

*使用kickstart自动安装脚本

Kickstart概述

*使用Kickstart,系统管理员可以创建一个包含安装期间所有常见问题的答案的文件,以自动安装Red Hat Enterprise Linux

*Kickstart 类似于 Oracle solaris 中的Jumpstart或Microsoft Windows的无人执守安装

Kickstart制作工具安装

4*软件包

 --system-config-kickstart

*安装

 --yum install system-config-kickstart

创建Kickstart文件

*使用 system-config-kickstart工具

*使用文本编辑器

--模板:/root/anaconda-ks.cfg

--编辑完成后使用ksvalidator命令校验正确性

eg:

[root@localhost yum.repos.d]# yum install system-config-kickstart -y

已加载插件:langpacks

正在解决依赖关系

--> 正在检查事务

---> 软件包 system-config-kickstart.noarch.0.2.9.2-4.el7 将被 安装

--> 正在处理依赖关系 system-config-keyboard >= 1.3.1,它被软件包 system-config-kickstart-2.9.2-4.el7.noarch 需要

--> 正在处理依赖关系 system-config-date,它被软件包 system-config-kickstart-2.9.2-4.el7.noarch 需要

--> 正在处理依赖关系 system-config-language,它被软件包 system-config-kickstart-2.9.2-4.el7.noarch 需要

--> 正在检查事务

---> 软件包 system-config-date.noarch.0.1.10.6-2.el7 将被 安装

--> 正在处理依赖关系 system-config-date-docs,它被软件包 system-config-date-1.10.6-2.el7.noarch 需要

---> 软件包 system-config-keyboard.noarch.0.1.4.0-4.el7 将被 安装

--> 正在处理依赖关系 system-config-keyboard-base = 1.4.0-4.el7,它被软件包 system-config-keyboard-1.4.0-4.el7.noarch 需要

---> 软件包 system-config-language.noarch.0.1.4.0-6.el7 将被 安装

--> 正在检查事务

---> 软件包 system-config-date-docs.noarch.0.1.0.11-4.el7 将被 安装

---> 软件包 system-config-keyboard-base.noarch.0.1.4.0-4.el7 将被 安装

--> 解决依赖关系完成

依赖关系解决

=========================================================================

 Package                       架构     版本              源        大小

=========================================================================

正在安装:

 system-config-kickstart       noarch   2.9.2-4.el7       server   351 k

为依赖而安装:

 system-config-date            noarch   1.10.6-2.el7      server   619 k

 system-config-date-docs       noarch   1.0.11-4.el7      server   527 k

 system-config-keyboard        noarch   1.4.0-4.el7       server    33 k

 system-config-keyboard-base   noarch   1.4.0-4.el7       server   103 k

 system-config-language        noarch   1.4.0-6.el7       server   132 k

事务概要

=========================================================================

安装  1 软件包 (+5 依赖软件包)

总下载量:1.7 M

安装大小:6.4 M

Downloading packages:

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

总计                                         73 MB/s | 1.7 MB  00:00     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在安装    : system-config-date-1.10.6-2.el7.noarch               1/6

  正在安装    : system-config-date-docs-1.0.11-4.el7.noarch          2/6

  正在安装    : system-config-language-1.4.0-6.el7.noarch            3/6

  正在安装    : system-config-keyboard-base-1.4.0-4.el7.noarch       4/6

  正在安装    : system-config-keyboard-1.4.0-4.el7.noarch            5/6

  正在安装    : system-config-kickstart-2.9.2-4.el7.noarch           6/6

  验证中      : system-config-date-docs-1.0.11-4.el7.noarch          1/6

  验证中      : system-config-keyboard-1.4.0-4.el7.noarch            2/6

  验证中      : system-config-date-1.10.6-2.el7.noarch               3/6

  验证中      : system-config-kickstart-2.9.2-4.el7.noarch           4/6

  验证中      : system-config-keyboard-base-1.4.0-4.el7.noarch       5/6

  验证中      : system-config-language-1.4.0-6.el7.noarch            6/6

已安装:

  system-config-kickstart.noarch 0:2.9.2-4.el7                           

作为依赖被安装:

  system-config-date.noarch 0:1.10.6-2.el7                               

  system-config-date-docs.noarch 0:1.0.11-4.el7                          

  system-config-keyboard.noarch 0:1.4.0-4.el7                            

  system-config-keyboard-base.noarch 0:1.4.0-4.el7                       

  system-config-language.noarch 0:1.4.0-6.el7                            

完毕!

[root@localhost yum.repos.d]# system-config-kickstart

/usr/share/system-config-kickstart/kickstartGui.py:104: GtkWarning: GtkSpinButton: setting an adjustment with non-zero page size is deprecated

  xml = gtk.glade.XML ("/usr/share/system-config-kickstart/system-config-kickstart.glade", domain="system-config-kickstart")

/usr/lib/python2.7/site-packages/scdate/core/zonetab.py:241: RuntimeWarning: Untranslated time zone: Antarctica/Troll

  entry = ZoneTabEntry(code, lat, long, tz, comments)

/usr/lib/python2.7/site-packages/scdate/core/zonetab.py:241: RuntimeWarning: Untranslated time zone: Europe/Busingen

  entry = ZoneTabEntry(code, lat, long, tz, comments)

/usr/lib/python2.7/site-packages/scdate/core/zonetab.py:241: RuntimeWarning: Untranslated time zone: Asia/Khandyga

  entry = ZoneTabEntry(code, lat, long, tz, comments)

/usr/lib/python2.7/site-packages/scdate/core/zonetab.py:241: RuntimeWarning: Untranslated time zone: Asia/Ust-Nera

  entry = ZoneTabEntry(code, lat, long, tz, comments)

已加载插件:langpacks

[root@localhost yum.repos.d]# ls /root/Desktop/

ks.cfg

[root@localhost yum.repos.d]# ls

soft.repo  yum.repo

[root@localhost yum.repos.d]# cd /root/Desktop/

[root@localhost Desktop]# ksvalidator ks.cfg

[root@localhost Desktop]# vim ks.cfg

%packages

@base

lftp

%end

[root@localhost Desktop]# ksvalidator ks.cfg

[root@localhost Desktop]# yum install httpd -y

已加载插件:langpacks

软件包 httpd-2.4.6-40.el7.x86_64 已安装并且是最新版本

无须任何处理

[root@localhost Desktop]# systemctl start httpd

[root@localhost Desktop]# systemctl enable httpd

[root@localhost Desktop]# cp ks.cfg /var/www/html/

[root@localhost Desktop]# cd  /var/www/html/

[root@localhost html]# ls

ks.cfg  rhel7.2

选择明细

--basic configuration -------------基本信息设定

--installation method -------------安装模式选择

--boot loader options -------------引导程序选择

--partition information------------分区划分策略

--authentication -----------------认证加密方式

--firewall configuration-----------火墙配置信息

--display configuration------------图形界面选择

--package selection----------------软件包选择

--pre-installtion------------------安装前执行脚本

--post-installtion-----------------安装后执行脚本

Kickstart 文件参数解析

%end 目的结束                     zerombr 清空mbr

%package 安装包                network 网络设定

%pre 安装前执行脚本         firewall 火墙设定

%post 安装后执行脚本       lang 语言设定

url 安装源路径                   keyboard 键盘设定

repo yum 源地址          timezone 时区设定

text 文本安装             auth 认证方式选择

vnc 安装时开启vnc    rootpw  root密码

Askmethod 交互模式 selinux selinux认定

cleanpart 删除分区 services 开机启动服务

part 分区策略      group.user 用户组建立

ignoredisk 跳过磁盘 logging 安装日志设定

bootloader引导程序设定 firstboot 首次启动设定

volgroup lvm组设定   reboot,poweroff,halt安装完成动作

logvol lvm设定

为安装程序提供kickstart文件

*网络服务器:FTP HTTP 和 NFS

*DHCP/TFTP 服务器

*USB 磁盘或CD-ROM

*本地磁盘

创建引导介质

*安装磁盘

*PXE

*boot.iso

使安装程序指向kickstark文件

*ks=http://server/dir/file

*ks=ftp://server/dir/file

*ks=nfs:server:/dir/file

*ks=hd:device:/dir/file

*ks=cdrom:/dir/file

在另一台主机上测试自动安装

[root@foundation60 images]# vim vm_create.sh

#!/bin/bash

virt-install

--name $*

--memory 1024

--vcpus 2

--file /var/lib/libvirt/images/$*.qcow2

--file-size 8

--location http://172.25.254.241/rhel7.2

--extra-args "ks=http://172.25.254.241/ks.cfg"

[root@foundation60 images]# sh vm_create.sh test

Starting install...

Retrieving file vmlinuz...                         | 9.8 MB     00:00 !!!

Retrieving file initrd.img...                      |  76 MB     00:01 !!!

Exception in thread Checking storage allocation:

Traceback (most recent call last):

********************************************

*************通过管理配置文件设置你主机dhcp获取ip**

[root@localhost html]# yum search dhcp

已加载插件:langpacks

=========================== N/S matched: dhcp ===========================

dhcp-common.x86_64 : Common files used by ISC dhcp client and server

dhcp-libs.x86_64 : Shared libraries used by ISC dhcp client and server

dhcp-libs.i686 : Shared libraries used by ISC dhcp client and server

dhclient.x86_64 : Provides the ISC DHCP client daemon and dhclient-script

dhcp.x86_64 : Dynamic host configuration protocol software

dnsmasq.x86_64 : A lightweight DHCP/caching DNS server

  名称和简介匹配 only,使用“search all”试试。

[root@localhost html]# yum install dhcp.x86_64 -y

已加载插件:langpacks

正在解决依赖关系

--> 正在检查事务

---> 软件包 dhcp.x86_64.12.4.2.5-42.el7 将被 安装

--> 正在处理依赖关系 dhcp-common = 12:4.2.5-42.el7,它被软件包 12:dhcp-4.2.5-42.el7.x86_64 需要

--> 正在处理依赖关系 dhcp-libs(x86-64) = 12:4.2.5-42.el7,它被软件包 12:dhcp-4.2.5-42.el7.x86_64 需要

--> 正在检查事务

---> 软件包 dhcp-common.x86_64.12.4.2.5-27.el7 将被 升级

--> 正在处理依赖关系 dhcp-common = 12:4.2.5-27.el7,它被软件包 12:dhclient-4.2.5-27.el7.x86_64 需要

---> 软件包 dhcp-common.x86_64.12.4.2.5-42.el7 将被 更新

---> 软件包 dhcp-libs.x86_64.12.4.2.5-27.el7 将被 升级

---> 软件包 dhcp-libs.x86_64.12.4.2.5-42.el7 将被 更新

--> 正在检查事务

---> 软件包 dhclient.x86_64.12.4.2.5-27.el7 将被 升级

---> 软件包 dhclient.x86_64.12.4.2.5-42.el7 将被 更新

--> 解决依赖关系完成

依赖关系解决

=========================================================================

 Package           架构         版本                  源            大小

=========================================================================

正在安装:

 dhcp              x86_64       12:4.2.5-42.el7       server       511 k

为依赖而更新:

 dhclient          x86_64       12:4.2.5-42.el7       server       279 k

 dhcp-common       x86_64       12:4.2.5-42.el7       server       172 k

 dhcp-libs         x86_64       12:4.2.5-42.el7       server       128 k

事务概要

=========================================================================

安装  1 软件包

升级           ( 3 依赖软件包)

总下载量:1.1 M

Downloading packages:

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

总计                                        1.3 MB/s | 1.1 MB  00:00     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在更新    : 12:dhcp-libs-4.2.5-42.el7.x86_64                     1/7

  正在更新    : 12:dhcp-common-4.2.5-42.el7.x86_64                   2/7

  正在安装    : 12:dhcp-4.2.5-42.el7.x86_64                          3/7

  正在更新    : 12:dhclient-4.2.5-42.el7.x86_64                      4/7

  清理        : 12:dhclient-4.2.5-27.el7.x86_64                      5/7

  清理        : 12:dhcp-common-4.2.5-27.el7.x86_64                   6/7

  清理        : 12:dhcp-libs-4.2.5-27.el7.x86_64                     7/7

  验证中      : 12:dhcp-common-4.2.5-42.el7.x86_64                   1/7

  验证中      : 12:dhcp-4.2.5-42.el7.x86_64                          2/7

  验证中      : 12:dhclient-4.2.5-42.el7.x86_64                      3/7

  验证中      : 12:dhcp-libs-4.2.5-42.el7.x86_64                     4/7

  验证中      : 12:dhcp-common-4.2.5-27.el7.x86_64                   5/7

  验证中      : 12:dhcp-libs-4.2.5-27.el7.x86_64                     6/7

  验证中      : 12:dhclient-4.2.5-27.el7.x86_64                      7/7

已安装:

  dhcp.x86_64 12:4.2.5-42.el7                                            

作为依赖被升级:

  dhclient.x86_64 12:4.2.5-42.el7    dhcp-common.x86_64 12:4.2.5-42.el7  

  dhcp-libs.x86_64 12:4.2.5-42.el7  

完毕!

[root@localhost html]# cd /etc/dhcp/

[root@localhost dhcp]# vim dhcpd.conf

36行以下27&28行删除

7 option domain-name "example.com";

8 option domain-name-servers 172.25.254.254;

30 subnet 172.25.254.0 netmask 255.255.255.0 {

31   range 172.25.254.231 172.25.254.232;

32   option routers 172.25.254.222;

33 }

[root@localhost dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd

dhcpd6.conf.example  dhcpd.conf.example   

[root@localhost dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y

[root@localhost dhcp]# ls

dhclient.d  dhcpd6.conf  dhcpd.conf

[root@localhost dhcp]# vim dhcpd.conf

[root@localhost dhcp]# systemctl start dhcpd

在另一台虚拟机上测试:

先删除本机ip

nmtui-->eth0-->systemctl restart network-->ifconfig

##########################unit 2 控制对文件的访问##########

学习目标

*读取文件权限

*设定权限列表

*设备权限列表加载

权限列表的读取

[kiosk@fundation0 Desktop]$getfacl file

#file:file 文件名称

#owner:kiosk 文件所有人

#group:kiosk 文件所有组

#user::rw- 用户权限

#user:kiosk:rwx 特殊指派用户及权限

group::rw- 组权限

mask::rwx 可指派最大权限

other::r-- 其他人权限

setfacl 用于设置或修改文件的ACL

*setfacl -m u:bob:rw filename

 --授予用户 bob 读写权限

*setfacl -m g:westos:rw filenqme

 --授予组westos 读写权限

*setfacl -m g:redhat:r filename

--授予组redhat 读的权限

*setfacl -x u:bob filename

--删除用户       bob的ACL权限

*setfacl -m o::- filename

--修改其他所有人的权限为空

[root@localhost mnt]# mkdir test

[root@localhost mnt]# ls -l

total 3948544

-rw-r--r--. 1 root root 4043309056 Apr  4 21:55 rhel-server-7.2-x86_64-dvd.iso

drwxr-xr-x. 2 root root          6 Apr  5 03:42 test

[root@localhost mnt]# id student

uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)

[root@localhost mnt]# setfacl -m u:student:rwx test

[root@localhost mnt]# getfacl test/

# file: test/

# owner: root

# group: root

user::rwx

user:student:rwx

group::r-x

mask::rwx

other::r-x

[root@localhost mnt]# cd test/

[root@localhost test]# ll

total 0

[root@localhost test]# mkdir haha

[root@localhost test]# ls -ld test/

ls: cannot access test/: No such file or directory

[root@localhost test]# ls -ld haha/

drwxr-xr-x. 2 root root 6 Apr  5 03:45 haha/

[root@localhost test]# setfacl -m d:u:student:rwx /mnt/test/

[root@localhost test]# ls

haha

[root@localhost test]# getfacl /mnt/test/

getfacl: Removing leading '/' from absolute path names

# file: mnt/test/

# owner: root

# group: root

user::rwx

user:student:rwx

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:student:rwx

default:group::r-x

default:mask::rwx

default:other::r-x

[root@localhost test]# ls -l haha/ -d

drwxr-xr-x. 2 root root 6 Apr  5 03:45 haha/

[root@localhost test]# mkdir /mnt/test/redhat

[root@localhost test]# getfacl /mnt/test/redhat/

getfacl: Removing leading '/' from absolute path names

# file: mnt/test/redhat/

# owner: root

# group: root

user::rwx

user:student:rwx

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:student:rwx

default:group::r-x

default:mask::rwx

default:other::r-x

ACL 掩码及继承

*具有ACL的文件拥有一个“mask”(掩码),这个掩码既能够限制拥有该文件的组的最大权限,又能够限制ACL中的补充用户和组所拥有的最大权限

*setfacl -m m:rwx file

*目录可以有“默认 ACL”条目,系统自动针对在该目录中创建的新文件设置这些条目,这类似setgid权限的方法(针对目录时),使得在该目录中创建的新文件归拥有该目录的组所有。

*setfacl -m: d:u:bob:rw directory

[root@localhost mnt]# touch file

[root@localhost mnt]# ls -l file

-rw-r--r--. 1 root root 0 Apr  5 03:52 file

[root@localhost mnt]# setfacl -m u:student:rwx file

[root@localhost mnt]# ls -l file

-rw-rwxr--+ 1 root root 0 Apr  5 03:52 file

[root@localhost mnt]# chmod 644 file

[root@localhost mnt]# ls -l file

-rw-r--r--+ 1 root root 0 Apr  5 03:52 file

[root@localhost mnt]# getfacl file

# file: file

# owner: root

# group: root

user::rw-

user:student:rwx #effective:r--

group::r--

mask::r--

other::r--

[root@localhost mnt]# setfacl -m m:rwx file

[root@localhost mnt]# getfacl file

# file: file

# owner: root

# group: root

user::rw-

user:student:rwx

group::r--

mask::rwx

other::r--

设备权限列表加载

*挂载文件系统之后,必须启用对POSIX ACL 条目的支持

*安装程序会配置它创建的所有ext4文件系统,以自动启用ACL支持

*tune2fs -l /dev/sdal |grep “Default mount”

Default mount options :

user_xattr acl

*如果手动格式化文件系统,则需要使用 acl 挂载选项挂载该系统

*tune2fs -o user_xattr,acl /dev/sda1

unit1:

1.新建用户并满足以下条件:

1)asasin uid=2000

2)sareo uid=2001

3)这两个用户都属于deho组

[root@localhost mnt]# groupadd deho

[root@localhost mnt]# useradd -u 2000 -g deho asasin

[root@localhost mnt]# useradd -u 2001 -g deho sareo

4)这两个用户密码为westos0o11

[root@localhost mnt]# passwd asasin

Changing password for user asasin.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

[root@localhost mnt]# echo westos0oll |passwd --stdin sareo

Changing password for user sareo.

passwd: all authentication tokens updated successfully.

5)新建用户taromati,

6)此用户为系统用户,没有交互式shell

[root@localhost mnt]# useradd -c "" taromati

2.新建文件/public并满足以下条件

1)所有用户都可以在此目录中建立文件

2)除sareo用户外任何人在此目录中建立的文件都自动归属到deho组 中

4)sareo对此目录中新建所有文件爱你均不能作任何操作

3)任何人在此目录中只能删除属于自己的文件

[root@localhost /]# mkdir /public

[root@localhost /]# cd /public/

[root@localhost public]# setfacl -m d:g:deho:rwx /public/

[root@localhost public]# setfacl -m u:sareo:0 /public/

[root@localhost public]# chmod o+t /public/

原文地址:https://www.cnblogs.com/yangying2017/p/6669790.html