Marco Linux cloud computing classes throughout the week 5 job (20190722-20190728)

1, every 12 hours backup and compression / etc / directory to / backup directory to save the file name format, "etc- years - when - - Month - Day points .tar.gz"

Backup script as follows:
[root @ bccobbler mageedu] More etcbackup.sh #
# / bin / bash!
&& mkdir / Backup [-d "/ Backup"!]
Datetime = $ (/ bin / DATE + "% Y-% M- H-D-%% M% ")
/ bin / -czf /backup/etc-${datetime}.tar.gz the tar / etc
[@ bccobbler the root mageedu] # # the crontab -e add the following line in the last row:
0 / 12 / bin / bash /root/mageedu/etcbackup.sh &> / dev / null
execute the script:
[root @ bccobbler mageedu] # SH etcbackup.sh
Marco Linux cloud computing classes throughout the week 5 job (20190722-20190728)

2, rpm package management summary and application examples demonstrate.

use can be divided in accordance with the rpm command to install, upgrade, uninstall, query, verify, database maintenance into six parts;
rpm - RPM Package Penalty for Manager
rpm command: rpm [OPTIONS] [PACKAGE_FILE]
installation: -i, --install
upgrade: - U, --update, -F, --freshen
uninstall: -e, --erase
query: -q, --query
check: -V, --verify
database maintenance: - BuildDB, --initdb
1) installation
rpm {-i | --install} [install -options] PACKAGE_FILE ...

-ivh PACKAGE_FILE ... RPM
the GENERAL the OPTIONS:
v: verbose, detailed information
vv: more verbose output

[install-Options]:
H: hash Marks output a progress bar; each # represents 2% of the schedule;
-test: test installation, inspection reports and messages, dependencies and conflicts;
-nodeps: Ignore dependencies; not recommended;
- replacepkgs: reinstall
-nosignature: Do not check the signature information package, without checking the legitimacy of sources;
-nodigest: Do not check package integrity of information;
RPM package installed example.rpm example.rpm -i;
-iv example.rpm install rpm example. rpm package and display information is being installed in the installation process;
rpm -ivh example.rpm mounted example.rpm package and display information and progress of the installation being installed in the installation process;
2) upgrade
rpm {-U | --upgrade} [the install-Options] PACKAGE_FILE ...
RPM {-F | --freshen} [the install-Options] PACKAGE_FILE ...
-oldpackage: downgrade;
-force: mandatory upgrade;
RPM -Uvh example.rpm upgrade package example.rpm

Note: (1) do not do the kernel upgrade; Linux support for multi-core versions co-exist, therefore, directly install the new version of the kernel;
(2) If an original package configuration file has been modified to install, upgrade, new version with a profile of the program will not overwrite the original version supplied configuration file, but the new version of the configuration file renaming (FILENAME.rpmnew) after providing;
3) uninstall
rpm {-e | --erase} [- -allmatches] [- nodeps] [--noscripts] [- the test] PACKAGE_NAME ...
-allmatches: uninstall all versions matches the given name of the package;
-nodeps: ignore dependencies
-test: test uninstall, dry run mode
rpm -e example uninstall the software example, note: you can only enter the package names, not the file name
4) query
rpm {-q | --query} [select -options] [query-options]

[the SELECT-Options]
PACKAGE_NAME: query specified package is already installed, and version;
A, --all: query all the packages already installed;
f FILE: query file specified by the installation package which generates;
the p-, --package PACKAGE_FILE: performing a query packet for realizing the operation of the program is not installed;
-whatprovides CAPABILITY: CAPABILITY specified by the query which package provides;
-whatrequires CAPABILITY: CAPABILITY query is specified which depends packet;

[-Query Options]
-changelog: Query rpm package changlog;
L, --list: list of all the files generated by the installation;
I, --info: information related to the package, version number, size, packet group belongs, and the like;
C, --configfiles: query the specified configuration file provided by the package;
D, --docfiles: query document specified provide a package;
-provides: CAPABILITY listed all the specified package provided;
R & lt, --requires: query dependencies specified package;
-scripts: viewing package comes with the script fragment;
usage:
qi pACKAGE, -qf FILE, -qc pACKAGE, -ql pACKAGE, -qd pACKAGE
QPI PACKAGE_FILE, -qpl PACKAGE_FILE, -qpc PACKAGE_FILE, ...

#rpm -q example query package example
5) Check package
rpm {-V | --verify} [SELECT-Options] [Verify-Options]
rpm -V package PKG check
6) reconstruction of the database
by the rpm command query a rpm package is installed, to be done by the rpm database; sometimes rpm system is a problem, can not be installed and query, the database might be a problem, you can use the following command to rebuild.
rpm manager database path: / var / lib / rpm /
query: here performed by the database;

Get help:
CentOS 6: RPM man
CentOS 7: man rpmdb

{--initdb RPM | --rebuilddb} [--dbpath DIRECTORY] [--root DIRECTORY]
--initdb: initializing the database, this database may be no real create a new initialization; this may do nothing;
- -rebuilddb: rebuild, re-created by reading all the packages already installed on the current system;

3, yum configuration and use yum summarize and create a private warehouse.

yum (yellow dog, Yellowdog Update Modifier ) the tool package manager is a front end package manager Fedora, RedHat, SUSE in. Based rpm package management, can automatically download from the specified server rpm package and install, can be handled automatically dependencies, and one-time installation of all packages depending
client configuration file corresponding to the specified server access several follows:
FTP: //
HTTP : //
nfs: //
file: ///
profile:
/etc/yum.conf: providing a common configuration for all warehouse
/etc/yum.repos.d/*.repo: providing configured to point to the warehouse

仓库指向的定义:
[repositoryID]
name=repo_name                    #显示的名称
baseurl=url://path/to/repository/   #路径可以是网络上的也可以是本地访问路径
enabled={1|0}                     #是否启用包来源合法性验证
gpgcheck={1|0}                    #是否启用仓库
gpgkey=URL                        #公钥文件
enablegroups={1|0}
failovermethod={roundrobin|priority}   默认为:roundrobin,意为随机挑选;
cost=1000   #仓库开销,用来做优先级,数值越小,优先级越大默认为1000

yum common command
yum insatll package installation package
yum list list all available package and package group
yum clean all clear all buffered data
yum deplist package lists a package all its dependencies
yum remove package to uninstall a package
to create a private warehouse yum
create yum repository:
the createrepo [Options] <Directory>

4, write a script to achieve the user menu lists the following:

(1) disk: show disk info information
(2) mem: show memory info information
(3) cpu: show cpu info Information
( ) quit
script as follows:
[root @ bccobbler mageedu] More os.sh #
# / bin / bash!
#
CAT << EOF
Disk) Show Disks info
MEM) Show Memory info
the CPU) Show the CPU info
) the QUIT
EOF

read -p "Your choice: " option

if [[ "$option" == "disk" ]];then
fdisk -l /dev/[sh]d[a-z]
elif [[ "$option" == "mem" ]];then
free -m
elif [[ "$option" == "cpu" ]];then
lscpu
else
echo "Unknown option."
exit 3
fi
执行结果如下:
Marco Linux cloud computing classes throughout the week 5 job (20190722-20190728)
Marco Linux cloud computing classes throughout the week 5 job (20190722-20190728)
Marco Linux cloud computing classes throughout the week 5 job (20190722-20190728)

5, sed usage summary and presentation with examples

sed是一种在线编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非你使用重定向存储输出。sed主要用来自动编辑一个或多个文件;简化对文件的反复操作;编写转换程序等。
sed用法格式:
sed [OPTION]... ‘script‘ [input-file] ...
script:地址定界编辑命令
sed常用选项:
-n:不输出模式空间中的内容至屏幕;
-e script, --expression=script:多点编辑;能指定多个编辑命令
-f /PATH/TO/SED_SCRIPT_FILE每行一个编辑命令;
-r, --regexp-extended:支持使用扩展正则表达式;
-i[SUFFIX], --in-place[=SUFFIX]:直接编辑原文件 ;
地址定界:
(1) 空地址:对全文进行处理;**
(2) 单地址:
:指定行;
/pattern/:被此模式所匹配到的每一行;
(3) 地址范围
,#: 指定行到指定行
,+#: 从指定数字行加上指定数字,例如3,+8 ,从第三行开始到第十行(包括第三行)
,/pat1/ 从指定行到第一次匹配到的pat结束
/pat1/,/pat2/ 从第一次匹配到的pat到第二次匹配到的pat
$:最后一行;
(4) 步进:~
2:所有奇数行
2:所有偶数行

编辑命令:
d:删除;
p:显示模式空间中的内容;
a \text:在行后面追加文本“text”,支持使用\n实现多行追加;
i \text:在行前面插入文本“text”,支持使用\n实现多行插入;
c \text:把匹配到的行替换为此处指定的文本“text”;
w /PATH/TO/SOMEFILE:保存模式空间匹配到的行至指定的文件中;
r /PATH/FROM/SOMEFILE:读取指定文件的内容至当前文件被模式匹配到的行后面;文件合并;
=:为模式匹配到的行打印行号;
!:条件取反;
地址定界!编辑命令;
s///:查找替换,其分隔符可自行指定,常用的有s@@@, s###等;
替换标记:
g:全局替换;
w /PATH/TO/SOMEFILE:将替换成功的结果保存至指定文件中;
p:显示替换成功的行;
示例:
显示/etc/passwd文件的奇数行:
[root@bccobbler yum]# cat -n /etc/passwd |sed -n 'p;n'
Marco Linux cloud computing classes throughout the week 5 job (20190722-20190728)
逆序显示/etc/passswd内容
[root@bccobbler yum]# sed '1!G;h;$!d' /etc/passwd
Marco Linux cloud computing classes throughout the week 5 job (20190722-20190728)

6、 用bash实现统计访问日志文件中状态码大于等于400的IP数量并排序;

[root@bccobbler mageedu]# sed -n -r '/\<40[0-9]\>/p' /var/log/httpd/access_log|cut -d" " -f1 |sort|uniq -c

7、 使用自制的yum源安装ftp、openssh、curl、wget、tcpdump等软件包;

[root@bccobbler yum]# mkdir yum
[root@bccobbler yum]# cp /opt/centos/Packages/ftp openssh curl tcpdump ./
[root@bccobbler yum]# createrepo /yum/
Spawning worker 0 with 5 pkgs
Spawning worker 1 with 4 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@bccobbler yum]# vi /etc/yum.repos.d/local.repo
[yum]
name=yum
baseurl=file:///yum/
enabled=1
gpgcheck=0

Marco Linux cloud computing classes throughout the week 5 job (20190722-20190728)
[root@bccobbler yum]# yum install -y ftp openssh curl wget tcpdump

Guess you like

Origin blog.51cto.com/3401973/2424303