Linux 学习笔记(八)
编程语言
2018-08-13 04:57:26
阅读次数: 0
1、Rsync远程同步
//Rsync远程同步
//常用rsync -a ,rsync 比ssh 更高效,例如,第一次复制了1,第二次复制1,2时,rsync会只复制2,它底层会识别已经复制了1
一款快速增量备份工具 Remote Sync,远程同步;
采用rsync算法,使一个客户机和远程服务器之间文件同步,可以在中断后恢复传输;
支持本地复制,或者与其他SSH、rsync主机同步;
只传输源文件和目标文件之间不一致的部分;
可以执行完整备份或增量备份;
//Rsync功能特性
可以镜像保存整个目录树和文件系统
可以增量同步数据,文件传输效率高,因而同步时间很短 可以保持原有文件的权限、时间等属性 加密传输数据,保证了数据的安全性
可以使用rcp、ssh等方式来传输文件,当然也可以直接通过Socket连接传输文件 支持匿名传输
//rsync应用模式
Shell应用模式,也称为本地模式;
远程shell模式,它利用SSH执行底层连接和加密传输
查询(也叫列表)模式
服务器模式
//本地shell模式主要用于复制指定目录到另一个
//目录st后面有没有/的区别,有/不会复制st目录
sending incremental file list
st/
st/sa/
st/sb/
st/sc/
sent 90 bytes received 28 bytes 236.00 bytes/sec
total size is 0 speedup is 0.00
sending incremental file list
./
sa/
sb/
sc/
sent 83 bytes received 27 bytes 220.00 bytes/sec
total size is 0 speedup is 0.00
sa sb sc
st
//远程shell模式可以把本地目录复制到另一个系统中
//在默认情况下,rsync使用SSH作为传输机制
[root@localhost one]# rsync -av st 192.168.126.155:cisco/
sending incremental file list
created directory cisco
st/
st/sa/
st/sb/
st/sc/
sent 90 bytes received 28 bytes 236.00 bytes/sec
total size is 0 speedup is 0.00
[root@localhost one]# rsync -av st/ 192.168.126.155:cisco1/
sending incremental file list
created directory cisco1
./
sa/
sb/
sc/
sent 83 bytes received 27 bytes 220.00 bytes/sec
total size is 0 speedup is 0.00
总用量 4
drwxr-xr-x. 5 root root 4096 12月 27 10:13 st
总用量 12
drwxr-xr-x. 2 root root 4096 12月 27 10:13 sc
drwxr-xr-x. 2 root root 4096 12月 27 10:12 sb
drwxr-xr-x. 2 root root 4096 12月 27 10:13 sa
//rsync列表模式
//这个模式下,rsync与ls命令有相似的功能
[root@localhost one]# rsync -a 192.168.126.155:cisco
drwxr-xr-x 4096 2015/12/27 10:26:16 cisco
drwxr-xr-x 4096 2015/12/27 10:13:03 cisco/st
drwxr-xr-x 4096 2015/12/27 10:13:00 cisco/st/sa
drwxr-xr-x 4096 2015/12/27 10:12:57 cisco/st/sb
drwxr-xr-x 4096 2015/12/27 10:13:03 cisco/st/sc
//类似于ssh **** "ls -lR **"
[root@localhost one]# ssh 192.168.126.155 "ls -lR /root/cisco"
/root/cisco:
总用量 4
drwxr-xr-x. 5 root root 4096 12月 27 10:13 st
/root/cisco/st:
总用量 12
drwxr-xr-x. 2 root root 4096 12月 27 10:13 sa
drwxr-xr-x. 2 root root 4096 12月 27 10:12 sb
drwxr-xr-x. 2 root root 4096 12月 27 10:13 sc
/root/cisco/st/sa:
总用量 0
/root/cisco/st/sb:
总用量 0
/root/cisco/st/sc:
总用量 0
//服务器模式
这种模式是基于C/S模式的
rsync在后台启用一个守护进程,这个守护进程在rsync服务器端永久运行,用于接收文件传输请求
客户端既可以把文件发送给守护进程,也可以向守护进程请求文件
这种模式非常适合作为 /异地的中心备份服务器\ 或 /数据异地存储库\ 来使用
//配置rsync源服务器
rsync同步源 指:备份操作的远程服务器,也称为备份源 主要包括两种:rsync源、SSH源
基本思路:启用sshd服务,并分别建立上传、下载用户 为需要同步的目录设置访问权限
2、SELinux基础知识
//SELinux基础知识
SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统。NSA是在Linux社区的帮助下开发了一种访问控制体系,在这种访问控制体系的限制下,进程只能访问那些在他的任务中所需要文件。SELinux 默认安装在 Fedora 和 Red Hat Enterprise Linux 上,也可以作为其他发行版上容易安装的包得到。
大部分使用 SELinux 的人使用的都是 SELinux 就绪的发行版,例如 Fedora、Red Hat Enterprise Linux (RHEL)、Debian或 Centos。它们都是在内核中启用 SELinux 的,并且提供一个可定制的安全策略,还提供很多用户层的库和工具,它们都可以使用 SELinux 的功能。
SELinux是一种基于 域-类型 模型(domain-type)的强制访问控制(MAC)安全系统,它由NSA编写并设计成内核模块包含到内核中,相应的某些安全相关的应用也被打了SELinux的补丁,最后还有一个相应的安全策略。任何程序对其资源享有完全的控制权。假设某个程序打算把含有潜在重要信息的文件扔到/tmp目录下,那么在DAC情况下没人能阻止他。SELinux提供了比传统的UNⅨ权限更好的访问控制。
SELinux的配置文件:/etc/selinux/config
SELinux支持三种模式:
enforcing:强制模式,代表 SELinux 运作中,且已经正确的开始限制 domain/type 了;
permissive:宽容模式,代表 SELinux 运作中,不过仅会有警告讯息并不会实际限制 domain/type 的存取。这种模式可以运来作为 SELinux 的 debug 之用;
disabled:关闭,SELinux 并没有实际运作
Enforcing //执行
Permissive //宽容
Enforcing
3、常见故障排查
//常见故障排查
修复MBR扇区故障
1.备份MBR扇区数据 :
dd if=/dev/sda of=/backup/sda.mbr.bak bs=512 count=1
2.模拟MBR被破坏的故障:
dd if=/dev/zero of=/dev/sda bs=512 count=1
3.CentOS6光盘引导,进入急救模式
4.从备份文件中恢复MBR扇区:
dd if=/tempdir/sda.mbr.bak of=/dev/sda bs=512 count=1
//rpm数据库损坏
重建RPM数据库
rpm --rebuilddb 或 rpm --initdb
//修复损坏的文件系统
模拟对/dev/sdb1分区的破坏操作 :
dd if=/dev/zero of=/dev/sdb1 bs=512 count=4
检查是否能挂载该分区 报错:
mount: you must specify the filesystem type
对/dev/sdb1分区进行修复 :
fsck -yt ext4 /dev/sdb1
再次挂载该分区
//无法卸载已挂载的设备
故障原因:
需要卸载的设备正在被使用
故障现象:
无法卸载设备,提示“... device is busy”
解决思路:
将工作目录切换到挂载点以外
退出正在使用该设备的程序
或使用fuser命令找出相关进程,并终止该进程
[root@localhost mnt]# fuser -mv /media/cdrom
USER PID ACCESS COMMAND
/media/cdrom: root 3297 ..c.. bash
[root@localhost mnt]# fuser -k /media/cdrom
//检测硬盘中的坏道
检测硬盘中是否存在坏道:
mkfs -t ext4 -c /dev/sdb1 或 badblocks -sv /dev/sdb1
//系统性能监控 —— 查看CPU负载
05:33:11 up 7:22, 2 users, load average: 0.04, 0.09, 0.08
0.15 0.03 0.01 4/84 25697
//系统性能监控 —— 查看内存使用情况
procs ---------memory--------- --swap-- --io-- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 304280 27084 145844 0 0 29 8 1007 20 0 2 98 0 0
total used free shared buffers cached
Mem: 515600 211320 304280 0 27264 145852
-/+ buffers/cache: 38204 477396
Swap: 1048568 0 1048568
//系统性能监控 —— 磁盘I/O性能监控
iostat命令 用于查看系统磁盘I/O统计信息
Linux 2.6.18-8.el5 (localhost.localdomain) 2009年05月24日
Time: 16时17分49秒
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 1.28 15.12 6.54 167183 72314
sdb 0.83 11.95 1.95 132182 21526
dm-0 2.40 14.95 6.54 165325 72312
dm-1 0.01 0.04 0.00 456 0
hdc 0.02 0.07 0.00 746 0
Linux 2.6.18-8.el5 (localhost.localdomain) 2009年05月25日
05时18分11秒 CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
05时18分11秒 all 0.45 0.02 1.93 3.08 0.02 0.07 0.00 94.43 1010.03
转载自blog.csdn.net/weixin_42325841/article/details/81501444