System01 DAY07(自定义YUM与Shell应用)

    xiaoxiao2022-06-26  175

    自定义Yum仓库  问题 准备软件包目录新建文件夹 /custom拷入 linuxqq、realplayer 两个 RPM 包为软件包目录生成 repodata/ 数据从 RHEL 6 光盘安装 createrepo执行 createrepo /custom测试上述 YUM 源  方案 本题的思路: 1)先搭建好yum仓库,安装createrepo软件包 2)创建目录“/custom” 3)将事先准备好的rpm包,复制到目录“/custom”目录里 4)执行 createrepo /custom 5)编写新的yum客户端配置文件,添加新的yum源  步骤 实现此案例需要按照如下步骤进行。 步骤一:准备软件包目录 新建文件夹 /custom,命令操作如下所示: [root@localhost /]# mkdir /custom [root@localhost /]# ls -ld /custom/ drwxr-xr-x. 2 root root 4096 1月 13 21:27 /custom/ [root@localhost /]# ls /root/桌面/ httpd-2.2.25.tar.gz linuxqq-v1.0.2-beta1.i386.rpm RealPlayer11GOLD.rpm [root@localhost /]# 拷入 linuxqq、realplayer 两个 RPM 包 [root@localhost /]# cp /root/桌面/linuxqq-v1.0.2-beta1.i386.rpm /custom/ [root@localhost /]# cp /root/桌面/RealPlayer11GOLD.rpm /custom/ [root@localhost /]# ls /custom/ linuxqq-v1.0.2-beta1.i386.rpm RealPlayer11GOLD.rpm [root@localhost /]# 步骤二:为软件包目录生成 repodata/ 数据 从 RHEL 6光盘安装 createrepo。(因cretaerepo包依赖关系复杂首先要搭建yum) 命令操作如下所示: [root@localhost /]# umount /dev/cdrom [root@localhost /]# mount /dev/cdrom /media/ //挂载光盘设备到/media mount: block device /dev/sr0 is write-protected, mounting read-only [root@localhost /]# mount | tail -1 /dev/sr0 on /media type iso9660 (ro) [root@localhost /]# vim /etc/yum.repos.d/rhel6.repo //配置客户端文件 [rhel-6] name=Red Hat Enterprise Linux 6 baseurl=file:///media/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [root@localhost /]# yum repolist //客户端测试yum Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. repo id repo name status rhel-6 Red Hat Enterprise Linux 6 3,690 repolist: 3,690 [root@localhost /]# yum -y install createrepo //利用yum安装createrepo 执行 createrepo /custom [root@localhost /]# ls /custom/ linuxqq-v1.0.2-beta1.i386.rpm RealPlayer11GOLD.rpm [root@localhost /]# createrepo /custom/ Spawning worker 0 with 2 pkgs Workers Finished Gathering worker results

    Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete [root@localhost /]# ls /custom/ linuxqq-v1.0.2-beta1.i386.rpm RealPlayer11GOLD.rpm repodata [root@localhost /]# 步骤三:测试上述 YUM 源 编写客户端配置文件,命令操作如下所示: [root@localhost /]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ls rhel6.repo rhel-source.repo [root@localhost yum.repos.d]# cp rhel6.repo myrpm.repo [root@localhost yum.repos.d]# vim myrpm.repo [rhel-myrpm] name=Red Hat Enterprise Linux myrpm baseurl=file:///custom enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release 测试yum源 [root@localhost /]# yum repolist Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. rhel-myrpm | 2.9 kB 00:00 … rhel-myrpm/primary_db | 3.4 kB 00:00 … repo id repo name status rhel-6 Red Hat Enterprise Linux 6 3,690 rhel-myrpm Red Hat Enterprise Linux myrpm 2 repolist: 3,692 [root@localhost /] 4. Shell基础应用  问题

    查看IP地址、检查最近执行过的10条命令执行最近一次以 ifc 开头的命令为用户mike重置密码,屏蔽所有输出执行 mkdir /a /b/c ,将报错存到 err.txt  方案 查看历史命令的命令是history命令。此命令会把最近执行的1000条以内的命令显示出来。 想看最近执行的10条命令,可以利用“|”交给tail命令提取最后10条。还可以利用“|” 交给grep命令来筛选特定历史命令。 命令的输出信息会比较多,我们可以利用“&>” 重定向到/dev/null。来屏蔽所有输出。 收集错误信息为“2>”。  步骤 实现此案例需要按照如下步骤进行。 步骤一:查看IP地址、检查最近执行过的10条命令 命令操作如下所示: [root@localhost /]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:17:BF:F7 inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe17:bff7/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:20291 errors:0 dropped:0 overruns:0 frame:0 TX packets:5188 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:16183740 (15.4 MiB) TX bytes:482909 (471.5 KiB) …… [root@localhost /]# history | tail -10 539 cd /etc/yum.repos.d/ 540 ls 541 cp rhel6.repo myrpm.repo 542 vim myrpm.repo 543 cd / 544 yum repolist 545 ifconfig 546 history | tail -10 547 ifconfig 548 history | tail -10 [root@localhost /]# 步骤二:执行最近一次以 ifc 开头的命令 命令操作如下所示: [root@localhost /]# !ifc ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:17:BF:F7 inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe17:bff7/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:20315 errors:0 dropped:0 overruns:0 frame:0 TX packets:5203 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:16185686 (15.4 MiB) TX bytes:485795 (474.4 KiB) …… 步骤三:为用户mike重置密码,屏蔽所有输出 命令操作如下所示: [root@localhost /]# useradd mike [root@localhost /]# echo 123456 | passwd --stdin mike 更改用户 mike 的密码 。 passwd: 所有的身份验证令牌已经成功更新。 [root@localhost /]# echo 123456 | passwd --stdin mike &> /dev/null [root@localhost /]# 步骤四:利用mkdir同时建立“/a”与 “/b/c” ,将报错存到 err.txt 命令操作如下所示: [root@localhost /]# mkdir /a /b/c 2> err.txt [root@localhost /]# ls -ld /a drwxr-xr-x. 2 root root 4096 1月 13 22:00 /a [root@localhost /]# ls -ld /b ls: 无法访问/b: 没有那个文件或目录 [root@localhost /]# cat err.txt mkdir: 无法创建目录"/b/c": 没有那个文件或目录 [root@localhost /]#

    最新回复(0)