1. 程式人生 > >第六週作業(crontab,rpm,yum,sed使用)

第六週作業(crontab,rpm,yum,sed使用)

1. 每12小時備份並壓縮/etc/目錄至/backup/目錄中,儲存檔案格式為:“etc-年-月-日-時-分.tar.gz”

[[email protected] ~]# mkdir backup                            #####建立backup目錄
[[email protected]

~]# crontab -e                                 ####開啟編輯介面定義任務

0 */12 * * * tar -zcf /backup/etc-$(date +"%Y-%m-%d-%H-%M").tar.gz /etc   >/dev/null      
儲存即可,提示資訊為crontab: installing new crontab

2. rpm包管理功能總結以及應用演示。

rpm包的功能:將編譯好的應用程式的各組成檔案打包成一個或者多個程式包檔案,從而方便的實現程式包的安裝、升級、解除安裝和查詢等功能。

組織格式:(1)程式包的清單檔案(即安裝或者解除安裝時需要執行的指令碼),每個程式包都單獨實現

     (2)資料庫:/usr/lib/rpm/目錄下,主要是提供程式包的名稱和版本、包與包的依賴關係、軟體功能說明以及安裝生成各檔案路徑及校驗資訊等

獲取程式包的途徑:

(1)系統的發行版的光碟或者官方的檔案伺服器或者映象站點,主要有http://mirrors.aliyun.com;http://mirrors.suhu.com ; http://mirrors.163.com

(2)專案的官方站點:如http.apache.org ; www.zabix.org

(3)第三方組織,如epel或者搜尋工具(pkgs.org 、 rpmfind.net 、rpm.pbone.net)

(4)自己製作的rpm包

rpm程式包管理

Centos系統上rpm命令管理程式包(安裝、升級、解除安裝、查詢和校驗以及資料庫維護)

安裝

格式:rpm [OPTIONS]  [Package_file]

                      -i | --install  :安裝

[install-options] :-v:顯示安裝過程中的詳細資訊

        -h:以#顯示進度條

        --test:測試安裝,不真正安裝,僅報告依賴資訊和衝突資訊

        --nodeps:忽略依賴關係

        --replacepkgs:覆蓋安裝

        --force:強制安裝

常用組合選項:-ivh;-ivvh(顯示更加詳細的資訊)

演示:安裝zsh程式包

~]# rpm  -ivh  zsh-5.0.2-7.e17.x86_64.rpm

升級

rpm {-U | --update }[install options] PACKAGE_FILE

      -U :升級或安裝

rpm {-F | --freshen }[install options] PACKAGE_FILE

      -F:升級

組合使用:-Uvh;-Fvh

[install options] :

--test:測試安裝,不真正安裝,僅報告依賴資訊和衝突資訊

        --nodeps:忽略依賴關係

        --oldpackages:降級到舊版本

注意:(1)不要對核心執行升級,linux允許多個核心共存,因此可以直接安裝多個不同版本的核心

   (2)如果程式包的配置檔案安裝之後曾被修改,升級時,新版本的檔案不會覆蓋老版本的配置檔案,而是把新版本的配置檔案重新命名後儲存(加字尾.rpmnew)

解除安裝:移除已經安裝的程式包

rpm {-e |--erase}  [OPTIONS] PACKAGE_FILE

                              --allmatches:若一個程式包同時安裝多個版本,則一次性解除安裝

         --nodeps:忽略依賴關係

         --test:測試解除安裝

查詢:檢視某包是否已經安裝,以及檢查安裝的所有的包,還可以查詢某包的具體資訊

用法:rpm {-q | --query} [selece-options]  [query-options]  

[selece-options] :挑選選項

        rpm -q PACKAGE_NAME:查詢指定的包是否已經安裝以及其版本

        rpm  -qa :查詢已經安裝的程式包

        rpm  -qf /PATH/TO/SMEFILE :查詢某檔案是由哪個安裝包生成

        rpm -qpi:查詢尚未安裝的程式包的相關資訊      

        --whatprovides CAPABILITY :查詢制定的CAPABBILITY是由哪個安裝包生成

        --whatrequires CAPABILITY:查詢制定的CAPABBILITY是被哪個安裝包所依賴

 [query-options] :查詢選項

(1)--change:查詢某rpm包的修改日誌

如:~]# rpm -q --change bash

(2)-l | --list :列出某安裝包生成的檔案列表

如:~]# rpm -ql bash 

(3)-i :查詢某包的簡要說明資訊

如:rpm -qi bash

(4)-c:查詢某包安裝完成後生成的所有配置檔案

如:~]#rpm -qc bash

(5)-d:查詢指定程式包提供的幫助文件

如:~]#rpm -qd bash

(6)--provides:列出指定程式包提供的CAPABILITY;--whatprovides:查詢bash能力由哪個程式包提供

如:~]#rpm -q  --provides bash  ;      ~]#rpm -q  --whatprovides bash 

(7)--requires:查詢某包依賴的CABABILITY

如:rpm -q --requires bash

(8)--scripts:查詢某包安裝或解除安裝時的執行指令碼(指令碼由4類)

如:rpm -q --scripts bash

四類指令碼:preinstall:安裝過程開始之前執行的指令碼

       postinstall:安裝過程完成之後執行的指令碼

       preuninstall:解除安裝之前執行的指令碼

       postuninstall:解除安裝過程完成之後執行的指令碼

示例:

[[email protected] ~]# rpm -qi bash            #########查詢bash的簡要說明資訊
Name        : bash
Version     : 4.2.46
Release     : 30.el7
Architecture: x86_64
Install Date: 2018年10月30日 星期二 21時34分37秒
Group       : System Environment/Shells
Size        : 3667709
License     : GPLv3+
Signature   : RSA/SHA256, 2018年04月25日 星期三 18時54分19秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : bash-4.2.46-30.el7.src.rpm
Build Date  : 2018年04月11日 星期三 08時55分22秒
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.gnu.org/software/bash
Summary     : The GNU Bourne Again shell
Description :
The GNU Bourne Again shell (Bash) is a shell or command language
interpreter that is compatible with the Bourne shell (sh). Bash
incorporates useful features from the Korn shell (ksh) and the C shell
(csh). Most sh scripts can be run by bash without modification.
[[email protected] ~]# rpm -qc httpd                        ###########查詢httpd包安裝之後生成的配置檔案
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd

校驗:查詢安裝之後生成的檔案是否發生了改變

格式:rpm {-V | verify} [select-option] [verify-option]

[[email protected] ~]# rpm -V httpd
              

3. yum的配置和使用總結以及yum私有倉庫的建立

 

4. 寫一個指令碼實現以下選單給使用者:

  (1)disk:show disk info資訊

  (2)mem :show memory info資訊

  (3)cpu:show cpu info資訊

  (*)quit

5. sed用法總結並結合例項演示:

 

6. 用bash實現統計訪問日誌中狀態碼大於等於400的IP數量並排序

7. 使用自制的yum源安裝ftp、openssh、curl、tcpdump等軟體包