liunx基础五
1、每12小时备份并压缩/etc/目录至/backup目录中,保存文件名称格式为,"etc-年-月-日-时-分.tar.gz"
首先确保crond守护进程处于运行状态 Centos7 systemctl status crond.service 输出结果: Active: active (running) 或者命令 service crond status Centos6 service crond status 输出结果 crond (pid 2221) is running... 编辑 mkdir /backup/ #创建目录 tar -zcvf /backup/etc-"$(date +%F-%H-%M)".tar.gz /etc/ 测试命令 输出结果: [[email?protected]/backup]#ls etc-2019-08-27-23-20.tar.gz 输入命令 crontab -e * */12 * * * tar -zcvf /backup/etc-"$(date +%F-%H-%M)".tar.gz /etc/ 查看目前的时程表 [[email?protected]~]#crontab -l * */12 * * * tar -zcvf /backup/etc-"$(date +%F-%H-%M)".tar.gz /etc 2、rpm包管理功能总结以及实例应用演示。①功能总结②实例应用演示下载一下prm包作为测试文件:
查看rpm包信息:
输出结果 Name : lrzsz Version : 0.12.20 Release : 36.el7 Architecture: x86_64 Install Date: (not installed) Group : Applications/Communications Size : 184846 License : GPLv2+ Signature : RSA/SHA256,2014年07月04日 星期五 11时35分32秒,Key ID 24c6a8a7f4a80eb5 Source RPM : lrzsz-0.12.20-36.el7.src.rpm Build Date : 2014年06月10日 星期二 07时29分11秒 Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://www.ohse.de/uwe/software/lrzsz.html Summary : The lrz and lsz modem communications programs 查看rpm包的内容:
输出结果: /usr/bin/rb /usr/bin/rx /usr/bin/rz /usr/bin/sb /usr/bin/sx /usr/bin/sz /usr/share/locale/de/LC_MESSAGES/lrzsz.mo /usr/share/man/man1/rz.1.gz /usr/share/man/man1/sz.1.gz 查看rpm包的依赖:
输出结果: libc.so.6()(64bit) libc.so.6(GLIBC_2.11)(64bit) libc.so.6(GLIBC_2.14)(64bit) libc.so.6(GLIBC_2.15)(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) libc.so.6(GLIBC_2.7)(64bit) libnsl.so.1()(64bit) rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PartialHardlinkSets) <= 4.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rtld(GNU_HASH) rpmlib(PayloadIsXz) <= 5.2-1 安装rpm包:
输出结果: 准备中... ################################# [100%] 正在升级/安装... 1:lrzsz-0.12.20-36.el7 ################################# [100%] 查询系统是否安装指定的rpm包
输出结果:
卸载rpm包:
查询文件属于那个包:
输出结果: 查询命令属于那个包: [[email?protected]~]#rpm -qf $(which rz) lrzsz-0.12.20-36.el7.x86_64 #输出结果 3、yum的配置和使用总结以及yum私有仓库的创建。yum的配置
yum的使用总结创建yum私有库①对etc/yum.repos.d/的Centos-Base.repo进行备份
②修改Centos-Base.repo文件 [Base] name=CentOS-$releasever-Base baseurl=file:///media gpgchek=1 ③对光盘进行挂载
④重新加载yum yum clean yum makecache ⑤查看yun源 [[email?protected]/etc/yum.repos.d]#yum repolist 输出结果 4、写一个脚本实现列出以下菜单给用户:(1)disk:show disk info信息 (2)mem: show memory info信息 (3)cpu: show cpu info信息 (*)quit vim cr.sh #!/bin/bash #******************************************************************** #Author: benny #QQ: 759354304 #Date: 2019-09-02 #FileName: cr.sh #URL: http://www.benny.com #Description: The test script #Copyright (C): 2019 All rights reserved #******************************************************************** cat << EOF disk:show disk info; men: show memory info; cpu:show cpu info (*)QUIT EOF read -p "your chice:" option if [[ "$option" == "disk" ]]; then fdisk -l /dev/[sh]d[a-z] elif [[ "$option" == "men" ]]; then free -m elif [[ "$option" == "men" ]]; then lscpu else echo "Unkown option" exit 3 fi 5、sed用法总结并结合实例演示
特殊用法实例: sed -n ‘n;p‘ FILE:显示偶数行; sed ‘1!G;h;$!d‘ FILE:逆序显示文件的内容; sed ’$!d‘ FILE:取出最后一行; sed ‘$!N;$!D‘ FILE:取出文件后两行; sed ‘/^$/d;G‘ FILE:删除原有的所有空白行,而后为所有的非空白行后添加一个空白行; sed ‘n;d‘ FILE:显示奇数行; sed ‘G‘ FILE:在原有的每行后方添加一个空白行; 6、 用bash实现统计访问日志文件中状态码大于等于400的IP数量并排序[[email?protected]~]#awk ‘$9>400{print $1}‘ /var/log/httpd/access_log* |uniq -c |sort -nr 输出结果: 2 10.0.0.1 7、 使用自制的yum源安装ftp、openssh、curl、wget、tcpdump等软件包ⅰ、查看以上软件是否安装 yum list installed fpt openshh curl wget tcpdump``` 若安装进行卸载 rpm -e --nodeps wget curl tcpdump yum remove 完全移除软件包,包括所有依赖项此命令很危险,不建议使用,可能会误卸载别的软件所需要的依赖项 Ⅱ、在当前yum下查找是否存在以上软件,yum源来自`CentOS-7-x86_64-Everything-1810.iso`包含大部分软件 yum list ftp openshh curl wget tcpdump 出结果为: 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 可安装的软件包 curl.x86_64 7.29.0-51.el7 Base ftp.x86_64 0.17-67.el7 Base tcpdump.x86_64 14:4.9.2-3.el7 Base wget.x86_64 1.14-18.el7 Base Ⅲ、直接安装 yum install -y ftp openshh curl wget tcpdump``` Ⅳ、检查安装结果 [[email?protected]~]#yum list installed fpt openshh curl wget tcpdump 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 已安装的软件包 curl.x86_64 7.29.0-51.el7 @Base tcpdump.x86_64 14:4.9.2-3.el7 @Base wget.x86_64 1.14-18.el7 @Base (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |