做网站需要多少带宽,asp.net网站很快吗,免费做公司网站,野花香电视剧在线观看高清源码编译安装
RPM软件包#xff1a;rpm -ivh 或者 yum -y install
需要开发编译工具gcc、gcc-c、make等...
源码包----开发工具gcc与make----》可以执行的程序-----》运行安装 •主要优点
–获得软件的最新版#xff0c;及时修复bug
–软件功能可按需选择/定制#xff…源码编译安装
RPM软件包rpm -ivh 或者 yum -y install
需要开发编译工具gcc、gcc-c、make等...
源码包----开发工具gcc与make----》可以执行的程序-----》运行安装 •主要优点
–获得软件的最新版及时修复bug
–软件功能可按需选择/定制有更多软件可供选择
–源码包适用各种平台
–…… 步骤1安装开发工具gcc与make释放源代码至指定目录 步骤2tar解包释放源代码至指定目录 步骤3./configure 配置指定安装目录/功能模块等选项 步骤4make 编译生成可执行的二进制程序文件 步骤5make install 安装将编译好的文件复制到安装目录
真机tools.tar.gz 传递数据到虚拟机
真机为Linux ]# ls /linux-soft/s1]# scp /linux-soft/s1/tools.tar.gz root192.168.88.240:/root
真机为windowswindterm进行上传tools.tar.gz 虚拟机192.168.88.4 案例
虚拟机A
1.安装开发工具 [rootserver ~]# yum -y install gcc make[rootserver ~]# rpm -q gcc[rootserver ~]# rpm -q make[rootserver ~]# 2.进行解压缩
源码包默认放在/usr/local [rootserver ~]# tar -xf /root/tools.tar.gz -C /usr/local[rootserver ~]# ls /usr/local/toolsinotify-tools-3.13.tar.gz #监听文件 3.进行tar解包 [rootserver ~]# tar -xf /usr/local/tools/inotify-tools-3.13.tar.gz -C /usr/local/ [rootserver ~]# ls /usr/local/[rootserver ~]# cd /usr/local/inotify-tools-3.13/[rootserver ~]# ls 4.运行configure脚本 作用1检测当前系统是否安装gcc 作用2指定安装位置与功能 作用3生成Makefile文件制作程序的大纲做菜的菜谱 ./configure
只能在当前目录下生成makefile文件 [rootserver ~]# cd /usr/local/inotify-tools-3.13/[rootserver ~]# ./configure --help #查看帮助信息,大概浏览一下[rootserver ~]# ./configure --prefix/opt/myrpm #指定安装位置此步骤不产生相应的目录 常见的报错信息 gcc开发工具没有安装checking for gcc... nochecking for cc... nochecking for cl.exe... noconfigure: error: no acceptable C compiler found in $PATHSee config.log for more details.
5.进行make编译变成可以执行的程序放在内存中只能在当前目录下
【此时的目的是生成二进制文件】 [rootserver ~]# cd /usr/local/inotify-tools-3.13/[rootserver inotify-tools-3.13]# make 6.进行make install安装。 只能在当前目录下 [rootserver ~]# cd /usr/local/inotify-tools-3.13/[rootserver inotify-tools-3.13]# make install [rootserver inotify-tools-3.13]# ls /opt/[rootserver inotify-tools-3.13]# ls /opt/myrpm/[rootserver inotify-tools-3.13]# ls /opt/myrpm/bin/ rsync同步监视ssh 数据同步
同步的实时性 按照固定周期定期同步 时间间隔不好固定同步不及时或资源浪费
实时性较差
Linux内核的inotify机制 提高时间响应式的文件系统通知机制 安装inotify-tools 控制工具可调用此机制实现监控
• 命令用法
rsync [选项...] 源目录 目标目录
• rsync操作选项 -n测试同步过程不做实际修改 --delete删除目标文件夹内多余的文档 -a归档模式相当于-rlptgoD -v显示详细操作信息 -X保持acl策略不变
本地同步(文件级)
#一般默认10G以上采用rsyns低于10G也可以看个人爱好。
#每使用rsyns一次就同步一次。
#不加--delete 就是只改不删除 [rootserver ~]# mkdir /mydir /todir [rootserver ~]# echo haha /mydir/h.txt [rootserver ~]# rsync -avX --delete /mydir/ /todir #同步目录的内容[rootserver ~]# ls /mydir/[rootserver ~]# ls /todir/[rootserver ~]# touch /todir/a.txt [rootserver ~]# ls /todir/[rootserver ~]# rsync -avX --delete /mydir/ /todir[rootserver ~]# ls /todir/[rootserver ~]# ls /mydir/ 远程同步rsyncssh
与远程的 SSH目录保持同步
下行rsync [...] userhost:远程目录 本地目录
上行rsync [...] 本地目录 userhost:远程目录
虚拟机A的/mydir目录的内容与虚拟机B的/mnt进行同步
虚拟机A [rootserver ~]# rsync -avX --delete /mydir/ root192.168.88.2:/mnt……..connecting (yes/no)? yesroot192.168.88.2s password: #输入密码 虚拟机B [rootserver ~]# ls /mnt 实时数据同步
虚拟机A的/mydir/目录的内容与虚拟机B的/mnt进行同步
实现ssh无密码验证(公钥与私钥)
虚拟机A
1.虚拟机A生成公钥与私钥 [rootserver ~]# ssh-keygen #一路回车[rootserver ~]# ls /root/.ssh/id_rsa(私钥) id_rsa.pub(公钥) known_hosts(记录曾经远程管理过的机器) 2虚拟机A将公钥传递给虚拟机B [rootserver ~]# ssh-copy-id root192.168.88.5[rootserver ~]# rsync -avX --delete /mydir/ root192.168.88.5:/remove_file 同步源文件(192.168.88.4) 192.168.88.5---同步前
192.168.88.5---同步后 监控目录内容变化工具
• 基本用法
inotifywait [选项] 目标文件夹
• 常用命令选项
-m持续监控捕获一个事件后不退出
-r递归监控、包括子目录及文件
-q减少屏幕输出信息
-e指定监视的 modify、move、create、delete、attrib 等事件类别 inotifywait 监控目录内容变化rsync -avX --delete /mydir/ root192.168.88.2:/mnt 书写shell脚本(了解)
脚本可以运行一个文件实现某种功能
中文:新建用户zhangsan shell useradd zhangsan
[rootserver /]# vim /root/hello.sh
echo hello world
hostname
id root
ifconfig | head -2
[rootserver /]# chmod x /root/hello.sh #所有人赋予执行权限
[rootserver /]# /root/hello.sh #绝对路径执行脚本
重复性循环解决
格式 while 条件do重复执行的事情done
[rootserver /]# vim /etc/rsync.sh
while /opt/myrpm/bin/inotifywait -rqq /opt/
do
rsync -aX --delete /mydir/ root192.168.88.5:/opt/
done
[rootserver /]# chmod x /etc/rsync.sh #赋予执行权限
[rootserver /]# /etc/rsync.sh #放入后台运行脚本程序
[rootserver /]# jobs -l #-l选项 显示进程的pid
[1] 17707 运行中 /etc/rsync.sh
[rootserver /]# kill 17707 #停止脚本可以杀死进 案例编译安装软件包
问题
本例要求掌握常规源代码应用的安装过程通过编译的方式安装inotify-tools 软件工具完成下列任务 释放 inotify-tools-3.13.tar.gz 源码包 配置 ./configure 【生成makefile文件,指定安装位置 】 编译 make、安装 make install 测试inotifywait监控工具的用法及用途
方案
对于标准源码发布的C/C软件包编译安装一般包括以下过程 解包使用tar命令将下载的源代码释放至指定目录 配置执行源码目录内的 ./configure 脚本指定安装目录/功能模块等选项 编译在源码目录下执行 make 操作根据配置清单Makefile生成可执行的二进制程序文件 安装在源码目录下执行make install 操作将编译好的程序及相关文件复制到安装目录
步骤
实现此案例需要按照如下步骤进行。
步骤一确认已配置好编译环境 [rootsvr7 ~]# yum -y install gcc gcc-c make.. ..[rootsvr7 ~]# gcc --versiongcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)Copyright (C) 2015 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
步骤二编译安装inotify-tools软件包
1解包inotify-tools-3.13.tar.gz文件 [rootsvr7 ~]# ls inotify-tools-3.13.tar.gzinotify-tools-3.13.tar.gz[rootsvr7 ~]# tar xf inotify-tools-3.13.tar.gz -C /usr/src/
2配置 ./configure安装目录默认/usr/local/*/ [rootsvr7 ~]# cd /usr/src/inotify-tools-3.13/ //进入源码目录[rootsvr7 inotify-tools-3.13]# ./configure //配置操作checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for gawk... gawk.. ..configure: creating ./config.statusconfig.status: creating Makefile.. ..[rootsvr7 inotify-tools-3.13]# ls Makefile //检查配置结果Makefile
3编译 make [rootsvr7 inotify-tools-3.13]# make.. ..Making all in srcmake[2]: Entering directory /usr/src/inotify-tools-3.13/srcmake[3]: Entering directory /usr/src/inotify-tools-3.13make[3]: Leaving directory /usr/src/inotify-tools-3.13.. ..
4安装 make install [rootsvr7 inotify-tools-3.13]# make install.. ../usr/bin/install -c .libs/inotifywait /usr/local/bin/inotifywait/bin/sh ../libtool --modeinstall /usr/bin/install -c inotifywatch /usr/local/bin/inotifywatch.. ..[rootsvr7 inotify-tools-3.13]# find /usr/local/ -name inotify*/usr/local/bin/inotifywait //确认安装结果/usr/local/bin/inotifywatch/usr/local/include/inotifytools/usr/local/include/inotifytools/inotifytools.h
步骤三测试inotify-tools软件程序
软件包inotify-tools提供了一个主要程序inotifywait可以用来监控指定目录或文档的变化并及时给出通知。
1开启对/opt目录的事件监控 -m持续监控捕获一个事件后不退出 -r递归监控、包括子目录及文件 -q减少屏幕输出信息 [rootsvr7 ~]# inotifywait -mrq /opt //开启监控[1] 15568 2修改/opt/目录内容观察屏幕输出信息 [rootsvr7 ~]# touch /opt/a.txt //新建文件a.txt/opt/ CREATE a.txt/opt/ OPEN a.txt/opt/ ATTRIB a.txt/opt/ CLOSE_WRITE,CLOSE a.txt[rootsvr7 ~]# mv /opt/a.txt /opt/b.txt //将文件改名/opt/ MOVED_FROM a.txt/opt/ MOVED_TO b.txt 3结束inotifywait监控
杀死当前用户的第一个后台任务 [rootsvr7 ~]# kill -9 %1[1] Killed inotifywait -mrq /opt 案例rsync基本用法
问题
本例要求掌握远程同步的基本操作使用rsync命令完成下列任务 将目录 /boot 同步到目录 /todir 下 将目录 /boot 下的文档同步到目录 /todir 下 在目录 /boot 下新增文件 a.txt删除 /todir 下的子目录 grub2再次同步使 /todir 与 /boot 一致 验证 -a、-n、-v、--delete 选项的含义
方案
本地同步操作 rsync [选项...] 本地目录1 本地目录2 rsync [选项...] 本地目录1/ 本地目录2
rsync同步工具的常用选项 -n测试同步过程不做实际修改 --delete删除目标文件夹内多余的文档 -a归档模式相当于-rlptgoD -v显示详细操作信息 -z传输过程中启用压缩/解压 -X :不改变ACL策略
步实现此案例需要按照如下步骤进行。
步骤一rsync同步基本操作
1将目录 /boot 同步到目录 /todir 下 [rootsvr7 ~]# ls -l /todir //同步前ls: 无法访问/todir: 没有那个文件或目录[rootsvr7 ~]# rsync -a /boot /todir //将目录1作为目录2的子目录[rootsvr7 ~]# ls -l /todir //检查同步结果总用量 4dr-xr-xr-x. 4 root root 4096 11月 30 18:50 boot
2将目录 /boot 下的文档同步到目录 /todir 下 [rootsvr7 ~]# rm -rf /todir //清理掉目录2[rootsvr7 ~]# rsync -a /boot/ /todir //将目录1下的文档同步到目录2下[rootsvr7 ~]# ls -l /todir //检查同步结果总用量 126708-rw-r--r--. 1 root root 126426 10月 30 2015 config-3.10.0-327.el7.x86_64drwxr-xr-x. 2 root root 4096 11月 30 18:50 extlinuxdrwx------. 6 root root 104 12月 9 09:58 grub2.. ..
3同步效果测试
在目录/boot下新增文件a.txt删除/todir下的子目录 grub2 [rootsvr7 ~]# touch /boot/a.txt[rootsvr7 ~]# rm -rf /todir/grub2/ 现在目录/boot和/todir目录下的内容已经不一致了 [rootsvr7 ~]# ls -ld /boot/a.txt /todir/a.txtls: 无法访问/todir/a.txt: 没有那个文件或目录-rw-r--r--. 1 root root 0 1月 11 21:09 /boot/a.txt[rootsvr7 ~]# ls -ld /boot/grub2 /todir/grub2ls: 无法访问/todir/grub2: 没有那个文件或目录drwx------. 6 root root 104 12月 9 09:58 /boot/grub2再次同步使/todir与/boot一致 [rootsvr7 ~]# rsync -a /boot/ /todir/
确认同步结果 [rootsvr7 ~]# ls -ld /boot/a.txt /todir/a.txt-rw-r--r--. 1 root root 0 1月 11 21:09 /boot/a.txt-rw-r--r--. 1 root root 0 1月 11 21:09 /todir/a.txt[rootsvr7 ~]# ls -ld /boot/grub2 /todir/grub2drwx------. 6 root root 104 12月 9 09:58 /boot/grub2drwx------. 6 root root 104 12月 9 09:58 /todir/grub2 步骤二验证 -a、-v、-n、--delete 选项的含义
1验证-a选项
当目录1包含文件夹时若缺少-a或-r选项则文件夹会被忽略 [rootsvr7 ~]# rsync /home /testaskipping directory home[rootsvr7 ~]# ls -ld /testals: 无法访问/testa: 没有那个文件或目录
添加-a后才会执行同步 [rootsvr7 ~]# rsync -a /home/ /testa[rootsvr7 ~]# ls -ld /testadrwxr-xr-x. 4 root root 31 1月 6 17:33 /testa
类似的情况当目录1中的数据出现权限、归属、修改时间等变化时若文件内容不变默认不会同步若希望目录2也同步这些变化也需要-a选项。
2验证-v选项
创建测试目录及文档 [rootsvr7 ~]# mkdir /fdir[rootsvr7 ~]# touch /fdir/1.txt
添加-v选项时可以看到操作细节信息比如第一次同步时 [rootsvr7 ~]# rsync -av /fdir/ /tdirsending incremental file listcreated directory /tdir./1.txt //传输文档列表sent 82 bytes received 34 bytes 232.00 bytes/sectotal size is 0 speedup is 0.00
在目录/fdir/添加文件2.txt再次跟踪同步信息 [rootsvr7 ~]# touch /fdir/2.txtsending incremental file list./2.txt //传输文档列表sent 100 bytes received 34 bytes 268.00 bytes/sectotal size is 0 speedup is 0.00
确认目录1和目录2的内容已经一致 [rootsvr7 ~]# ls /fdir/ /tdir//fdir/:1.txt 2.txt/tdir/:1.txt 2.txt
再次跟踪同步信息已经无需传输文件 [rootsvr7 ~]# rsync -av /fdir/ /tdirsending incremental file listsent 58 bytes received 12 bytes 140.00 bytes/sectotal size is 0 speedup is 0.00
3验证-n选项
将-n、-v选项合用可以模拟同步过程显示需要做哪些操作但并不真的同步。
在目录/fdir下新建文件3.txt测试同步操作 [rootsvr7 ~]# touch /fdir/3.txt[rootsvr7 ~]# rsync -avn /fdir/ /tdir/sending incremental file list./3.txt //提示同步时会传输哪些文件sent 78 bytes received 18 bytes 192.00 bytes/sectotal size is 0 speedup is 0.00 (DRY RUN)[rootsvr7 ~]# ls -l /tdir/3.txt //但实际并未真的同步ls: 无法访问/tdir/3.txt: 没有那个文件或目录
去掉-n选项才会真正同步 [rootsvr7 ~]# rsync -av /fdir/ /tdir/sending incremental file list./3.txtsent 114 bytes received 34 bytes 296.00 bytes/sectotal size is 0 speedup is 0.00[rootsvr7 ~]# ls -l /tdir/3.txt-rw-r--r--. 1 root root 0 1月 11 21:46 /tdir/3.txt
4验证--delete选项
rsync同步操作默认只是将目录1的数据同步到目录2但如果目录2存在多余的文件却并不会去除除非添加—delete选项。
在目录/fdir、/tdir已经完成同步后删除/tdir/2.txt文件再次同步 [rootsvr7 ~]# rm -rf /fdir/2.txt [rootsvr7 ~]# rsync -a /fdir/ /tdir/
检查发现目标文件夹/tdir下的2.txt文件还在 [rootsvr7 ~]# ls /fdir/ /tdir//fdir/:1.txt 3.txt/tdir/:1.txt 2.txt 3.txt
这种情况下添加--delete选项再次执行同步两个目录的内容就一致了 [rootsvr7 ~]# rsync -a --delete /fdir/ /tdir/[rootsvr7 ~]# ls /fdir/ /tdir//fdir/:1.txt 3.txt/tdir/:1.txt 3.txtv 案例rsyncSSH同步
问题
本例要求掌握rsync与远程SSH资源的同步操作使用rsync命令访问远程主机svr7完成下列任务 查看远程主机的 / 目录下有哪些子目录 从远程主机下载 /etc/passwd 文件到当前目录 将远程主机的 /boot/ 目录同步为本地的 /fromssh 将本机的 /etc 目录同步到远程主机的 /opt/下
方案
列出 SSH 服务端资源 rsync userhost:远程目录/
rsyncSSH远程同步操作 rsync [...] userhost:远程目录 本地目录 rsync [...] 本地目录 userhost:远程目录
步骤
实现此案例需要按照如下步骤进行。
步骤一列出远程主机的SSH资源
查看远程主机svr7的/目录下有哪些子目录 [rootpc207 ~]# rsync root192.168.4.7:/root192.168.4.7s password: //验证对方的密码dr-xr-xr-x 4096 2016/12/15 10:39:34 .lrwxrwxrwx 7 2016/12/07 09:21:50 binlrwxrwxrwx 7 2016/12/07 09:21:50 liblrwxrwxrwx 9 2016/12/07 09:21:50 lib64lrwxrwxrwx 8 2016/12/07 09:21:50 sbindr-xr-xr-x 4096 2016/12/07 11:25:29 bootdrwxr-xr-x 6 2016/12/07 09:21:14 datadrwxr-xr-x 3200 2016/12/15 10:46:15 devdrwxr-xr-x 8192 2016/12/20 17:01:02 etc
步骤二rsyncSSH同步操作
1从远程主机svr7下载/etc/passwd文件到当前目录 [rootpc207 ~]# rsync root192.168.4.7:/etc/passwd ./root192.168.4.7s password: //验证对方的密码[rootpc207 ~]# cat passwd //检查同步结果root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologin.. ..
2将远程主机svr7的/boot/目录同步为本地的/fromssh [rootpc207 ~]# rsync -a root192.168.4.7:/boot/ /fromsshroot192.168.4.7s password: //验证对方的密码[rootpc207 ~]# ls /fromssh/ //检查同步结果config-3.10.0-327.el7.x86_64extlinuxgrub2initramfs-0-rescue-a19921505cc7e19d20dfcd5cea7d8aa2.imginitramfs-3.10.0-327.el7.x86_64.imginitramfs-3.10.0-327.el7.x86_64kdump.img.. ..
3将本机的/etc目录同步到远程主机svr7的/opt/下
确认目录大小 [rootpc207 ~]# du -sh /etc35M /etc
上行同步到远程主机svr7上 [rootpc207 ~]# rsync -a /etc root192.168.4.7:/opt/root192.168.4.7s password:
在远程主机上检查同步结果 [rootsvr7 ~]# du -sh /opt/etc35M /opt/etc 案例使用inotifywait工具
问题
本例要求安装inotify-tools工具并针对文件夹 /opt 启用 inotifywait 监控完成下列任务 当此目录下出现新建、修改、更改权限、删除文件等事件时能给出提示 验证上述监控事件的效果
方案
inotifywait监控操作 inotifywait [选项] 目标文件夹
inotifywait常用命令选项 -m持续监控捕获一个事件后不退出 -r递归监控、包括子目录及文件 -q减少屏幕输出信息 -e指定监视的 modify、move、create、delete、attrib 等事件类别
步骤
实现此案例需要按照如下步骤进行。
步骤一安装inotify-tools软件包
1解包 [rootsvr7 ~]# tar xf inotify-tools-3.13.tar.gz -C /usr/src/
2配置 [rootsvr7 ~]# cd /usr/src/inotify-tools-3.13/[rootsvr7 inotify-tools-3.13]# ./configure
3编译 [rootsvr7 inotify-tools-3.13]# make
4安装 [rootsvr7 inotify-tools-3.13]# make install
5检查安装结果inotifywait程序可用 [rootsvr7 ~]# inotifywait --helpinotifywait 3.13Wait for a particular event on a file or set of files.Usage: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ ... ]Options:-h|--help Show this help text... ..
步骤二测试inotifywait监控
1开启监控任务置入后台 [rootsvr7 ~]# inotifywait -mrq -e create,modify,move,attrib,delete /opt [1] 55564
2测试/opt/目录下的新建、修改、改名、更改权限、删除文件等事件的响应消息
观察新建文件时的监控信息 [rootsvr7 ~]# touch /opt/a.txt/opt/ CREATE a.txt/opt/ ATTRIB a.txt
观察修改文件内容时的监控信息 [rootsvr7 ~]# echo Hello /opt/a.txt[rootsvr7 ~]# /opt/ MODIFY a.txt/opt/ MODIFY a.txt
观察将文件改名时的监控信息 [rootsvr7 ~]# mv /opt/a.txt /opt/b.txt/opt/ MOVED_FROM a.txt/opt/ MOVED_TO b.txt
观察修改文件权限时的监控信息 [rootsvr7 ~]# chmod 600 /opt/b.txt/opt/ ATTRIB b.txt
观察删除文件时的监控信息 [rootsvr7 ~]# rm -rf /opt/b.txt /opt/ DELETE b.txt
3停止监控任务 [rootsvr7 ~]# kill -9 %1[1] 已杀死 inotifywait -mr -e create,modify,move,attrib,delete /opt