Linux云自动化运维第八课

第十三单元 软件安装

一、软件名称识别

[abrt-addon-ccpp]-[2.1.11-19].[el7].[x86_64].rpm ###rpm结尾的适用与redhat操作系统

       ||      ||         ||       ||

    软件名称    软件版本 软件适用系统 64位

二、如何安装软件

1.rpm

rpm -ivh name.rpm ###安装 ,-v显示过程,-h指定加密方式为hash

-e name ###卸载

-ql name ###查询软件生成文件

-qlp name.rpm ###查询软件安装后会生成什么文件

-qa ###查询系统中安装的所有软件名称

-qa |grep name ###查询软件是否安装

-q name ###。。。。

-qp name.rpm ###查询软件安装包安装后的名字

-qf filename ###查看filename属于那个安装包

-ivh name.rpm --force ###强制安装

-qi name ###查看软件信息

-Kv name.rpm ###检测软件包是否被篡改

-qp name.rpm --scripts ###检测软件在安装或卸载过程中执行的动作

2.yum

上层软件管理工具,最重要的功能是可以解决软件的倚赖关系

yum能够投入使用的前提是必须要有yum源,以及配置源的指向文件

三、server源端

1.从网络上下本机系统版本匹配的iso镜像文件

rhel-server-7.1-x86_64-dvd.iso

eg:[root@localhost ~]# scp root@172.25.254.62:/iso/rhel-server-7.2-x86_64-dvd.iso /iso/

2.把rhel-server-7.1-x86_64-dvd.iso挂在到/mnt以便访问镜像中的文件

mount rhel-server-7.1-x86_64-dvd.iso /mnt

eg:[root@localhost ~]#  mount /iso/rhel-server-7.2-x86_64-dvd.iso /rhel7.2/

3.配置本机yum源指向

rm -fr /etc/yum.repos.d/*

vim /etc/yum.repos.d/yum.repo

[Server]

name=rhel7.1

baseurl=file:///mnt

gpgcheck=0

eg:[root@localhost ~]# vi /etc/yum.repos.d/yum.repo

[root@localhost ~]# cat /etc/yum.repos.d/yum.repo

[virgo]

name=rhel7.2

baseurl=file:///rhel7.2

gpgcheck=0

4.安装资源共享服务

yum install httpd -y

systemctl stop firewlsh-plugin-11.2.202.451-release.x86_64.rpmld

systemctl disable firewalld

systemctl start httpd

systemctl enable httpd

eg:[root@localhost ~]# yum clean all

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

[root@localhost ~]# systemctl start httpd

[root@localhost ~]# systemctl status httpd

[root@localhost ~]# systemctl enable httpd

[root@localhost ~]# systemctl status firewalld

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

5.建立共享目录,并挂在镜像文件到共享目录上

mkdir /var/www/html/rhel7.1

umount /mnt

mount rhel-server-7.1-x86_64-dvd.iso /var/www/html/rhel7.1

eg:[root@localhost ~]# mkdir /var/www/html/rhel7.2

[root@localhost ~]# umount /rhel7.2/

[root@localhost ~]# mount /iso/rhel-server-7.2-x86_64-dvd.iso /var/www/html/rhel7.2/

6.测试

在浏览器中输入:http://本机ip/rhel7.1

可以看到镜像中的内容

eg:http://172.25.254.66/rhel7.2

7.修改本机yum源指向

[server]

name=rhel7.1

baseurl=file:///var/www/html/rhel7.1

gpgcheck=0

8.开机自动挂在iso

vim /etc/rc.d/rc.local

mount rhel-server-7.1-x86_64-dvd.iso /var/www/html/rhel7.1

:wq

chmod +x /etc/rc.d/rc.local

eg:[root@localhost ~]# vim /etc/rc.d/rc.local

[root@localhost ~]# cat /etc/rc.d/rc.local

#!/bin/bash

touch /var/lock/subsys/local

mount /iso/rhel-server-7.2-x86_64-dvd.iso /var/www/html/rhel7.2/

9.第三方软件仓库的搭建

把所有的rpm软件包放到一个目录中,这个目录中只能存在rpm文件

createrepo -v /rpm存放目录

vim /etc/yum.repos.d/xxx.repo

[Software]

name=software

baseurl=file:///rpm存放目录

gpgcheck=0

四、client指向端

vim /etc/yum.repos.d/xxxx.repo ###仓库指向文件位置

[xxxx] ###自定义软件仓库名称

name=xxxx ###自定义软件仓库描述

baseurl=ftp://|http://|file:// ###仓库位置

gpgcheck=0 ###不检测gpgkey

###gpgkey表示软件的出品logo

yum clean all ###清空yum缓存识别新配置

eg:[root@foundation62 yum.repos.d]# vim /etc/yum.repos.d/yum.repo

[root@foundation62 yum.repos.d]# cat /etc/yum.repos.d/yum.repo

[foundation62]

name=rhel7.2

baseurl=http://172.25.254.66/rhel7.2

gpgcheck=0

[root@foundation62 yum.repos.d]# yum clean all

五、yum命令

yum install softwarename ###安装

repolist ###列出设定yum源信息

remove softwarename ###卸载

list softwarename ###查看软件源中是否有次软件

list all ###列出所有软件名称

list installd ###列出已经安装的软件名称

list available ###列出可以用yum安装的软件名称

clean all ###清空yum缓存

search softwareinfo ###根据软件信息搜索软件名字

whatprovides filename ###在yum源中查找包含filename文件的软件包

update ###更新软件

history ###查看系统软件改变历史

reinstall softwarename ###重新安装

info softwarename ###查看软件信息

groups list ###查看软件组信息

groups info softwaregroup ###查看软件组内包含的软件

groups install softwaregroup ###安装组件

groups remove softwaregroup ###卸载组件

eg:[root@localhost ~]# yum repolist   ###列出设定yum源信息

Loaded plugins: product-id, search-disabled-repos, subscription-manager

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

repo id                              repo name                            status

virgo                                rhel7.2                              4,620

repolist: 4,620

[root@localhost ~]# yum list all   ###列出所有软件名称

[root@localhost ~]# yum list installd   ###列出已经安装的软件名称

[root@localhost ~]# yum list available   ###列出可以用yum安装的软件名称

第十四单元 linux中设备的访问

一、设备访问

1.设备识别

/dev/xdxn ###硬盘设备/dev/sda1

/dev/cdrom ###光驱

/dev/mapper/* ###虚拟设备

2.设备的使用

fdisk -l ###查看真实存在的设备

cat /proc/partitions ###系统能够识别的设备

blkid ###系统能够挂载使用的设备id

df ###查看设备被系统使用的情况

eg:[root@foundation42 /]# fdisk -l   ###查看真实存在的设备

磁盘 /dev/sda:320.1 GB, 320072933376 字节,625142448 个扇区

Units = 扇区 of 1 * 512 = 512 bytes

扇区大小(逻辑/物理):512 字节 / 4096 字节

I/O 大小(最小/最佳):4096 字节 / 4096 字节

磁盘标签类型:dos

磁盘标识符:0x00095828

   设备 Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048   104861695    52429824    7  HPFS/NTFS/exFAT

/dev/sda2       104861696   105271295      204800   83  Linux

/dev/sda3       105271296   113463295     4096000   82  Linux swap / Solaris

/dev/sda4       113463296   625141759   255839232    5  Extended

/dev/sda5       113465344   625141759   255838208   83  Linux

磁盘 /dev/sdb:7755 MB, 7755792384 字节,15148032 个扇区

Units = 扇区 of 1 * 512 = 512 bytes

扇区大小(逻辑/物理):512 字节 / 512 字节

I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘标签类型:dos

磁盘标识符:0x04dd5721

   设备 Boot      Start         End      Blocks   Id  System

/dev/sdb1   *          63    15148031     7573984+   c  W95 FAT32 (LBA)

[root@foundation42 /]# cat /proc/partitions   ###系统能够识别的设备

major minor  #blocks  name

   8        0  312571224 sda

   8        1   52429824 sda1

   8        2     204800 sda2

   8        3    4096000 sda3

   8        4          1 sda4

   8        5  255838208 sda5

  11        0    1048575 sr0

   7        0    3948544 loop0

   8       16    7574016 sdb

   8       17    7573984 sdb1

[root@foundation42 /]# blkid   ###系统能够挂载使用的设备id

/dev/sda1: UUID="40486AB4486AA87C" TYPE="ntfs"

/dev/sda2: UUID="f0ca4790-6775-414d-b16a-122ebc150994" TYPE="xfs"

/dev/sda3: UUID="94a483f0-9b72-4efd-a4bc-0f99606c1722" TYPE="swap"

/dev/sda5: UUID="f9da5a71-c5f7-4002-920b-aa7a01f37d94" TYPE="xfs"

/dev/loop0: UUID="2015-10-30-11-11-49-00" LABEL="RHEL-7.2 Server.x86_64" TYPE="iso9660" PTTYPE="dos"

/dev/sdb1: LABEL="M-PM-!M-4M-(" UUID="0000-0001" TYPE="vfat"

[root@foundation42 /]# df   ###查看设备被系统使用的情况

文件系统           1K-块     已用      可用 已用% 挂载点

/dev/sda5      255713288 17418536 238294752    7% /

devtmpfs         1813796        0   1813796    0% /dev

tmpfs            1826872      524   1826348    1% /dev/shm

tmpfs            1826872     9060   1817812    1% /run

tmpfs            1826872        0   1826872    0% /sys/fs/cgroup

/dev/sda2         198380   134004     64376   68% /boot

tmpfs             365376       24    365352    1% /run/user/1000

/dev/loop0       3947824  3947824         0  100% /rhel7.2

/dev/sdb1        7559200  4179136   3380064   56% /run/media/kiosk/С

3.设备的挂载

mount 设备 挂载点

mount /dev/sdb1 /mnt ###把系统中第二块硬盘的第一个分区挂载到/mnt目录上

eg:[root@foundation42 /]# mount /dev/sdb1 /mnt/   ###把系统中第二块硬盘的第一个分区挂载到/mnt目录上

[root@foundation42 /]# ls /mnt/

123                        打印                    实验指导   新建文件夹 (2)

Docker学习笔记.pdf         计算机系统结构课程设计  实验指导1  运维

System Volume Information  考研英语                微机原理   助学金

4.卸载设备

umout 设备|挂载点

如出现以下情况:

[root@foundation0 ~]# umount /dev/sdb1

umount: /home/kiosk/Desktop/photo: target is busy.

        (In some cases useful info about processes that use

         the device is found by lsof(8) or fuser(1))

解决:

fuser -kvm 设备|挂载点 -k kill ,-v显示详细信息,-m扫描设备

eg:[root@foundation42 mnt]# umount /mnt/   ###卸载挂载在/mnt/下的设备

umount: /mnt:目标忙。

        (有些情况下通过 lsof(8) 或 fuser(1) 可以

         找到有关使用该设备的进程的有用信息)

[root@foundation42 mnt]# fuser -vm /dev/sdb1   ###查看卸载不了的原因

                     用户     进程号 权限   命令

/dev/sdb1:           root     kernel mount /run/media/kiosk/С

                     root      21620 ..c.. bash

[root@foundation42 mnt]# cd ..

[root@foundation42 /]# umount /mnt/   ###卸载成功

[root@foundation42 /]# cd /mnt/

[root@foundation42 mnt]# ls

vm_create.sh  vm_kz.sh  vm_reset.sh  westos.xml

[root@foundation42 mnt]# df

文件系统           1K-块     已用      可用 已用% 挂载点

/dev/sda5      255713288 17420628 238292660    7% /

devtmpfs         1813796        0   1813796    0% /dev

tmpfs            1826872      524   1826348    1% /dev/shm

tmpfs            1826872     9060   1817812    1% /run

tmpfs            1826872        0   1826872    0% /sys/fs/cgroup

/dev/sda2         198380   134004     64376   68% /boot

tmpfs             365376       28    365348    1% /run/user/1000

/dev/loop0       3947824  3947824         0  100% /rhel7.2

/dev/sdb1        7559200  4179136   3380064   56% /run/media/kiosk/С

[root@foundation42 mnt]# cd ..

[root@foundation42 /]# umount /dev/sdb1

二、软硬链接

ls -i ###查看文件节点号

ln -s /file /file1 ###软链接

ln /file /file1 ###硬链接

eg:[root@foundation42 mnt]# touch file

[root@foundation42 mnt]# ls -li file    ###查看文件节点号

807990471 -rw-r--r-- 1 root root 0 Mar 31 15:35 file

[root@foundation42 mnt]# ln -s /mnt/file /opt/   ###软链接

[root@foundation42 mnt]# ls -li /opt/file

18687 lrwxrwxrwx 1 root root 9 Mar 31 15:36 /opt/file -> /mnt/file

[root@foundation42 mnt]# rm -fr /mnt/file

[root@foundation42 mnt]# ls -li /opt/file

18687 lrwxrwxrwx 1 root root 9 Mar 31 15:36 /opt/file -> /mnt/file

[root@foundation42 mnt]# cat /opt/file    ###软链接,删除母文件,软链接产生的文件也会被删除

cat: /opt/file: 没有那个文件或目录

[root@foundation42 mnt]# rm -fr /opt/file

[root@foundation42 mnt]# touch file2

[root@foundation42 mnt]# ls -li file2

807990471 -rw-r--r-- 1 root root 0 Mar 31 15:37 file2

[root@foundation42 mnt]# ln /mnt/file2 /opt/   ###硬链接

[root@foundation42 mnt]# ls -li /opt/file2

807990471 -rw-r--r-- 2 root root 0 Mar 31 15:37 /opt/file2

[root@foundation42 mnt]# ls -li /mnt/file2

807990471 -rw-r--r-- 2 root root 0 Mar 31 15:37 /mnt/file2

[root@foundation42 mnt]# rm -fr /mnt/file2    ###硬链接,删除母文件,硬链接产生的文件不会被产生

[root@foundation42 mnt]# ls -li /opt/file2

807990471 -rw-r--r-- 1 root root 0 Mar 31 15:37 /opt/file2

[root@foundation42 mnt]# rm -fr /opt/file2

三、文件查找

1.locate filename ###在文件数据库中搜索filename信息,updatedb更新文件数据库

2.find

find 查找位置 -条件 条件值  -exec 动作 {} ;

-name

-not 条件

-user

-group

-size

-perm

--maxdepth

--mindepth

-a

-o

-type f 文件

  d 目录

c 字符设备

b 块设备

s 套节字

l 链接

find /mnt -user student

find /mnt -group linux

find /mnt -user student -a -group linux

find /mnt -user student -o -group linux

find /mnt -user student -a -group linux

find /mnt -user student

find /mnt -user student -a -not -group linux

dd if=/dev/zero of=/mnt/file1 bs=1024 count=10

dd if=/dev/zero of=/mnt/file2 bs=1024 count=20

dd if=/dev/zero of=/mnt/file3 bs=1024 count=30

find /mnt -size 10k

find /mnt -size -10k

find /mnt -size +10k

eg:[root@localhost mnt]# ls -l

总用量 64

-rw-r--r--. 1 root root 10240 Mar 31 04:05 file1

-r--------. 1 root root 20480 Mar 31 04:06 file2

-rwxrwxrwx. 1 root root 30720 Mar 31 04:07 file3

[root@localhost mnt]# find /mnt -perm 444   ###查找权限是444的文件r--r--r--

[root@localhost mnt]# find /mnt -perm 644   ###查找权限是644的文件rw-r--r--

/mnt/file1

[root@localhost mnt]# find /mnt -perm /444   ###查找拥有r权限的文件

/mnt

/mnt/file1

/mnt/file2

/mnt/file3

[root@localhost mnt]# find /mnt -perm -444   ###查找所有用户都拥有r权限的文件

/mnt

/mnt/file1

/mnt/file3

[root@localhost mnt]# find /mnt -perm -222   ###查找所有用户都拥有w权限的文件

/mnt/file3

[root@localhost mnt]# find /mnt -perm -111   ###查找所有用户都拥有x权限的文件

/mnt

/mnt/file3

[root@localhost mnt]# find /mnt -perm /111   ###查找拥有x权限的文件

/mnt

/mnt/file3

[root@localhost mnt]# find /mnt -perm /222   ###查找拥有w权限的文件

/mnt

/mnt/file1

/mnt/file3

[root@localhost mnt]# find /mnt -perm -421   ###查找所有人拥有r权限,所有组拥有w权限,其他人拥有x权限

/mnt/file3

原文地址:https://www.cnblogs.com/Virgo-sept/p/6667690.html