unit11&7&8

#######################第十一单元系统恢复技术

一、系统引导过程概述

通电---->bios 初始化---->grub2 磁盘引导阶段---->grub2 文件引导阶段---->指定 boot 所在分区---->

启动内核,只读挂在 / 设备---->启动 init 程序进入初始化阶段---->启动 systemd 初始化进程---->读取 /etc/systemd/中的文件---->启动程序---->启动登陆环境

二、bios 初始化

• 基本输入 / 输出系统 ( BIOS ) 是内置于标准 x86/x86-64硬件的固件接口 , 将硬件置于已知状态并准备好系统以加载操作系统

• 出现什么情况 ?

– 检测并初始化硬件

– 确定从中引导的设备

• 可能出现了什么错误 ?

– 错误或异常 BIOS 设置

– 错误引导设备顺序

• 可以如何中断或影响 ?

– 按特定于供应商的键

– 使用特定于供应商的配置实用程序

– 通常 , <F12> 可以执行一次引导顺序覆盖

三、grub 磁盘引导阶段

• MBR

– mbr 的作用是为了记录 /boot 目录所在分区位置

– 磁盘的 0 磁道 1 扇区的前 446 字节

– dd if=/dev/zero of=/dev/xda bs=446 count=1

eg:

[root@localhost ~]# dd if=/dev/zero of=/dev/vda bs=446 count=1

1+0 records in

1+0 records out

446 bytes (446 B) copied, 0.000140221 s, 3.2 MB/s

[root@localhost ~]# reboot

Connection to 172.25.254.141 closed by remote host.

Connection to 172.25.254.141 closed.

[root@foundation41 ~]# rht-vmctl view desktop

Force off 关闭虚拟机

灯泡

open

Add Hardware       Boot Options        Aplay

重新开启        

Troubleshooting————> Rescue a Red Enterprise Linux system-->continue-->ok--->ok

df

chroot /mnt/sysimage/   

grub2-install /dev/vda

Force off    Boot Options   

灯泡

– grub2-install /dev/xda

四、grub 文件引导阶段

• /boot/grub2/grub.cfg

– 指定 /boot 分区位置

– 加载内核

– 启动系统初始化进程

– grub2-mkconfig

eg:

[root@localhost grub2]# cd /boot/grub2

[root@localhost grub2]# ls

device.map  fonts  grub2.cfg  grubenv  i386-pc  locale  themes

[root@localhost grub2]# rm -fr grub2.cfg

[root@localhost grub2]# grub2-mkconfig > /boot/grub2/grub2.cfg  ##恢复/boot/grub2/grub.cfg

Generating grub configuration file ...

Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64

Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img

Found linux image: /boot/vmlinuz-0-rescue-946cb0e817ea4adb916183df8c4fc817

Found initrd image: /boot/initramfs-0-rescue-946cb0e817ea4adb916183df8c4fc817.img

done

[root@localhost grub2]# cat grub2.cfg

....

set root='hd0,msdos1'mkinitrd /boot/initramfs-$(uname -r ).img $(uname -r)

if [ x$feature_platform_search_hint = xy ]; then

  search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1'  9bf6b9f7-92ad-441b-848e-0257cbb883d1

else

  search --no-floppy --fs-uuid --set=root 9bf6b9f7-92ad-441b-848e-0257cbb883d1

fi

linux16 /boot/vmlinuz-3.10.0-123.el7.x86_64 root=UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 ro vconsole.keymap=us console=tty0 crashkernel=auto  vconsole.font=latarcyrheb-sun16

initrd16 /boot/initramfs-3.10.0-123.el7.x86_64.img

}

*2

[root@localhost grub2]# rm -fr grub2.cfg

重启

grub>set root='hd0,msdos1'

grub>linux16 /boot/vmlinuz-3.10.0-123.el7.x86_64 ro root=/dev/vda1

grub>initrd16 /boot/initramfs-3.10.0-123.el7.x86_64.img

grub>boot

[root@localhost grub2]# grub2-mkconfig > /boot/grub2/grub2.cfg

五、内核引导阶段

•检测硬件设备

•设备驱动初始化

•将 / 只读挂在

•载入初始进程 systemd

•内核文件丢失请重新安装内核

六、systemd 初始化

•开启 selinux 和 systemd-tools

•加载内核参数

•加载系统时钟,键盘,主机名称

•读写挂载 / 文件系统

•激活 raid , lvm 设备

•激活系统配额

•启动 multi-user.target.wants 中的所有服务脚本

•启用虚拟控台

•启动图形

七、启动级别

•runlever0.target -> poweroff.target

•runlever1.target -> rescue.target

•runlever2.target -> multi-user.target

•runlever3.target -> multi-user.target

•runlever4.target -> multi-user.target

•runlever5.target -> grapical.target

•runlever6.target -> reboot.target

八、设定启动级别

• systemctl set-default + 启动级别

• /etc/systemd/system/default.target

eg:将vmlinuz-3.10.0-327.el7.x86_64删除

eg:将initramfs-3.10.0-327.el7.x86_64.img删除

eg:开机自动关闭

eg:重设root用户密码

###################第七单元访问网络文件共享服务

一、挂载网络文件系统

• 网络文件系统是由网络附加存储服务器通过网络向多个主机提供的一种文件系统 , 而不是由块设备 ( 例如硬盘驱动器 ) 提供的。客户端通过特殊的文件系统协议和格式访问远程存储

• Linux 中有两种主要协议可用访问网络文件系统 : NFS 和CIFS 。 NFS ( Network File System ) 可看作是 Linux 、UNIX 及其它类似操作系统的标准文件系统。 CIFS( Comon Internet File System ) 则是针对 Microsoft Windows 系统的标准网络文件系统

• 访问网络共享的三个基本步骤

– 1. 识别要访问的远程共享

– 2. 确定挂载点 ( 应该将共享挂载到的位置 ), 并创建挂载点的空目录

– 3. 通过相应的名利或配置更改挂载网络文件系统

二、CIFS: 通用网络文件系统

•CIFS 是针对 Microsoft Windows 操作系统的本地网络文件系统。Linux 系统可以挂载和访问 CIFS 文件共享 , 如同常见的网络文件系统一样。然而 , 由于 CIFS 是基于 NTFS 文件系统权限模型及其自身的身份验证系统来构建的 , 因而 CIFS 协议中的所有内容并不能很好地映射到 Linux 中

• samba-client RPM 软件包所包含的 smbclient 实用程序可用来识别由 Windows 或 Samba 文件服务器提供的 CIFS 共享。该实用程序工作起来犹如在 Microsoft Windows 中单击网上邻居。然后 mount命令可用于挂载共享。访问 CIFS 共享的命令

– . 识别 :# smbclient -L instructor.example.com

– 2. 确定挂载点 :# mkdir /remote2

– 3. 挂载 :# mount //instructor.example.com/ftp /remote2

三、NFS : 网络文件系统

• NFS ( Network File System ) 是由 Linux 、 UNIX 及其他类似操作系统使用的互联网标准协议 , 可作为它们的本地网络文件系统。它是一种活动扩展之下的开放标准 , 可支持本地 Linux 权限和文件系统功能

• Red Hat Enterprise Linux 7 在默认情况下支持 NFSv4 ( 该协议的版本 4 ), 并在该版本不可用的情况下自动回退到 NFSv3 和NFSv2 。对于在客户端上运行的所有版本的 NFS , 均应启用两种服务 : rpcbind 和 nfslock 。 NFSv4 使用 TCP 协议与服务器进行通信 , 而较早版本的 NFS 则可能使用 TCP 或 UDP

• 有两种方法用来确定由服务器提供的 NFS 导出 , 或叫做文件共享。如果服务器支持 NFSv3 或 NFSv2 , 您可以使用 showmount -eserver 命令来获取导出项列表。如果服务器支持 NFSv4 , 则可以

/ 导出项挂载到一个空目录并浏览所有导出文件系统的内容

四、访问 NFS 导出的命令

• 1. 识别

– # showmount -e instructor.example.com

• 2. 确定挂载点

– # mkdir /remote1

• 3. 挂载

– # mount

instructor.example.com:/var/ftp/pub /remote1

五、自动挂载网络存储

•使用 mount 命令 , 需要具有 root 用户权限以连接到网络共享。或者 , 我们可以向 /etc/fstab 添加条目 , 但是随后与网络服务器的连接将始终处于活动状态。当某一程序试图访问网络共享中的文件时 , 可以将 automounter ( 或 autofs )服务配置为 “ 按需 ” 挂载网络共享。当共享不再使用并处于不活动状态一定时间以后 ,automounter 会对共享解除挂载

• 不活动状态的时间间隔默认为五分钟 , 但该时间间隔可在/etc/sysconfimount 172.25.254.250:/nfsshare/nfs1   /mntg/autofs 中进行全局更改

• [root@instructor ~]# grep TIMEOUT /etc/sysconfig/autofs

# TIMEOUT - set the default mount timeout (default 600).

TIMEOUT=300

...output omitted....

通常 , 我们需要使用网络共享在不活动状态下保持挂载一小段时间 , 从而防止在段时间内对其进行再次使用。这能够避免不必要的挂载 / 解除挂载的周期,在本节中 , 我们将介绍使用自动挂载器的两种方法。首先 ,使用特殊的 /net 自动挂载挂载点 , 然后手动配置间接自动挂载映射。特殊映射 /net

• 默认情况下 , autofs 服务运行时 , 存在一个名为 /net 的特殊目录 , 但是该目录将显示为空

• 访问不存在的目录 /net/instructor.example.com 会使自动挂载器创建该子目录 , 并显示该 NFS 服务器上的所有NFS 导出项。这有时称为 “ 浏览 ” 共享userlist_enable=YES

– # cd /net/instructor.example.com

– # ls

– home kickstart var

• 在 /net/instructor.example.com 之下的所有文件和目录停止使用且超时期满子后 ,autofs 将共享解除挂载并删除空的 /net/instructor.example.com 子目录

六、间接映射

• 除了使用 /net 映射 , 系统管理员也可以手动配置任意目录, 以便访问时在其子目录上 “ 按需 ” 挂载特定共享。示例:

• 间接映射使用两层配置文件语法。在顶级文件/etc/auto.master 中 , 每个管理的 “ 父 ” 目录和包含子目录挂载点与网络共享的单独的第二个配置文件的名称占一行

# cat /etc/auto.master

/demo /etc/auto.demo

# cat

/etc/auto.demo

public -ro

nfsserver.domain:/exported/path

service autofs reload 重载 autofs 服务

# cd

/demo/public

eg:

[root@localhost yum.repos.d]# yum install samba-client -y

已加载插件:product-id, search-disabled-repos, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

server                                                   | 4.1 kB     00:00     

(1/2): server/group_gz                                     | 134 kB   00:00     

(2/2): server/primary_db                                   | 3.4 MB   00:00     

软件包 samba-client-4.1.1-31.el7.x86_64 已安装并且是最新版本

无须任何处理

[root@localhost yum.repos.d]# smbclient -L //172.25.254.250

Enter root's password:

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Sharename       Type      Comment

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

westos1         Disk      test share

westos2         Disk      test share

westos3         Disk      test share

westos4         Disk      test share

westos5         Disk      test share

westos6         Disk      test share

westos7         Disk      test share

westos8         Disk      test share

westos9         Disk      test share

westos10        Disk      test share

IPC$            IPC       IPC Service (Samba Server Version 4.1.1)

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Server               Comment

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

Workgroup            Master

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

[root@localhost yum.repos.d]# smbclient  //172.25.254.250/westos2

Enter root's password:

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: > ls

  .                                   D        0  Fri Feb 24 01:10:09 2017

  ..                                  D        0  Wed Dec  2 20:43:01 2015

  .q                                  [root@localhost net]# rpm -ql autofs

H        0  Fri Feb 24 01:10:07 2017

48936 blocks of size 2097152. 14630 blocks available

[root@localhost yum.repos.d]# smbclient  //172.25.254.250/westos2

[root@localhost yum.repos.d]# mount //172.25.254.250/westos1 /mnt/ -o username=guest

[root@localhost ~]# showmount -e 172.25.254.250

Export list for 172.25.254.250:

/nfsshare/nfs5 *

/nfsshare/nfs4 *

/nfsshare/nfs3 *

/nfsshare/nfs2 *

/nfsshare/nfs1 *

/content       172.25.0.0/255.255.0.0

[root@localhost /]# vi /etc/rc.local

/etc/rc.d/rc.local

[root@localhost /]# chmod +x /etc/rc.d/rc.local

eg:

[root@localhost net]# rpm -ql autofs  ##查找autofs配置文件

[root@localhost net]#vim /etc/sysconfig/autofs

TIMEOUT=3

[root@localhost net]# vi /etc/auto.master

/mnt    /etc/auto.hello

[root@localhost net]# vi /etc/auto.hello

*       172.25.254.250:/nfsshare/&

#################第八单元LDAP 网络用户账户

一、使用 LDAP 服务器进行网络身份验证

[root@server41 yum.repos.d]# hostnamectl set-hostname desktop11.example.com   ##设置主机名为desktop11

ldap客户端所须软件

yum sssd krb5-workstation -y

• 在本课程中 , 到目前为止 , 我们已经介绍了通过每台计算机上的本地文件( 例如 /etc/passwd ) 管理的本地用户账户。但是 , 在多个系统上将本地用户账户协调一致非常困难

*本节中 , 我们将介绍如何将计算机设置为客户端 , 以使用现有 LDAP 目录服务提供的网络用户账户。这样 , LDAP 目录就成为我们组织中所有网络用户和组的中心机构

*用户账户信息可以确定装户的特征和配置。身份验证方式用于确定尝试登录的人员是否应该获得对账户的使用权限。网络目录服务可以提供用户账户信息和身份验证方法

*LDAP 目录服务器可以用作分布式、集中式、网络用户管理服务。目录条目按树结构排列 , 可以在其中进行搜索。基础 DN ( 区分名称 ) 是树的基础 , 用于搜索用户和组的目录条目

*LDAP 客户端配置的主要元素

– 1. 服务器的完全限定主机名

– 2. 基础 DN , 用于搜索用户定义

– 3. 认证机构 (“ CA” ) 证书 , 用于签署 LDAP 服务器的 SSL 证书

二、安装客户端软件

• authconfig-gtk

• sssd

• krb5-workstation

三、通过 authconfig-gtk 认证 ldap 用户

• authconfig-gtk

                                                                             

时因为tls的证书缺失,需要到服务器端下载所需要的证书到/etc/openldap/cacerts,

用到的命令

wget http://172.25.254.254/pub/example-ca.crt

[root@server41 yum.repos.d]# authconfig-tui ##去掉[*] Use LDAP【*] Use Kerberos

 [root@server41 yum.repos.d]# authconfig-tui ##加上

四、检测 ldap 认证用户

• getent passwd ldapuserx

• vim /etc/sssd.conf

– enumerate = ture | false

– systemctl restart sssd

getent passwd ldapuser1

如果用户信息可以正常显示,证明客户端认成功。

[root@server41 yum.repos.d]# getent passwd ldapuser2

ldapuser2:*:1702:1702:LDAP Test User 2:/home/guests/ldapuser2:/bin/bash

五、通过 authconfig-tui 认证 ldap 用户

• authconfig-tui

六、下载证书文件

• cd /etc/openldap/cacerts

• wget

  http://classroom.example.com/pub/examp

  le-ca.crt

• ls /etc/openldap/cacerts

七、自动挂在 ldap 用户家目录

• 安装 autofs

• 编辑 autofs 策略文件

– vim /etc/auto.masteryum install autofs -y

vim /etc/autofs.master

/home/guests##家目录的上一级 /etc/auto.ldap

– vim /etc/auto.ldap

ldapuser1 172.25.254.254:/home/guests/ldapuser1

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

*##所有用户 172.25.254.254:/home/guests/&

ldapuser0

classroom.example.com:/home/guests/ldapuser0

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