rsync,linux系统日志,screen工具

linux 文件同步工具rsync

安装rsync:yum install -y rsynclinux

rsync能够远程和本地同步数据,可是和cp或者scp不一样的是,他不会覆盖之前的数据,而是先判断已经存在的数据和新的数据的差别,只有数据不一样时,才会把不相同的部分覆盖。安全

把passwd备份到tmp下1.txt: rsync -av /etc/passwd /tmp/1.txt网络

[root@aminglinux-01 ~]# rsync -av /etc/passwd /tmp/1.txt 
sending incremental file list
passwd

sent 1238 bytes  received 31 bytes  2538.00 bytes/sec
total size is 1164  speedup is 0.92
[root@aminglinux-01 ~]#

远程同步:rsync -av /etc/passwd 用户名@IP:路径ssh

[root@aminglinux-01 ~]# rsync -av /etc/passwd root@192.168.245.128:/tmp/1.txt 
The authenticity of host '192.168.245.128 (192.168.245.128)' can't be established.
ECDSA key fingerprint is 2c:de:ff:09:8f:e8:d7:06:04:a7:7b:22:48:71:cd:86.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.245.128' (ECDSA) to the list of known hosts.
root@192.168.245.128's password: 
Permission denied, please try again.
root@192.168.245.128's password: 
sending incremental file list

sent 31 bytes  received 12 bytes  1.06 bytes/sec
total size is 1164  speedup is 27.07
[root@aminglinux-01 ~]#
  • rsync的命令格式

rsync [OPTION] SRC DEST工具

rsync [OPTION] SRC [USER@]HOST:DESTui

rsync [OPTION] [USER@]HOST:SRC DESTthis

rsync [OPTION] [USER@]HOST::DEST.net

rsync [OPTION] SRC [USER@]HOST::DEST设计

  • rsync经常使用选项

-a : 这是归档模式,表示以递归方式输出文件,并保持全部属性,它等同于-rlptgoD。-a选项后面能够跟一个--no-OPTION ,表示关闭-rlptgoD 中的某一个,好比-a--no-l等同于-rptgoD。日志

-r :表示以递归模式处理子目录。它主要是针对目录来讲的,若是单独传一个文件不须要加-r选项,可是输出目录时必须加。

-v : 表示打印一些信息,好比文件列表,文件数量。

-l : 表示保留软链接。

-L : 表示像对待常规文件同样处理软链接,若是是SRC 中有软链接文件,则加上该选项后,将会把软链接指向的目标文件复制到DST。

-p : 表示保持文件权限。

-o : 表示保持文件属主信息。

-g : 表示保持文件属组信息。

-D : 保持设备文件信息。

-t : 表示保持文件时间信息。

--delete :表示删除DST当中SRC没有的文件。

--exclude=PATTERN :表示指定排除不须要传输的文件,等号后面跟文件名,能够是万用字符模式(如*.txt)。

--progress : 表示在同步的过程当中能够看到同步的过程状态,好比统计要同步的文件数量,同步的文件传速度等。

-u : 表示把DST中比SRC还新的文件排除掉,不会覆盖。

-z : 加上该选项,将会在传输过程当中压缩。

  • rsync经过ssh方式同步

推文件:rsync -av /etc/passwd 用户名@IP:路径

拉文件:rsync -avP 192.168.133.132:/tmp/aming.txt /tmp/123.txt

指定22端口:rsync -avP -e "ssh -p 22" /etc/passwd 192.168.133.132:/tmp/aming.txt

rsync经过服务的方式同步

  • 首先要编辑配置文件/etc/rsyncd.conf

[root@aminglinux-01 ~]# vi /etc/rsyncd.conf 

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area
port=873
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
address=192.168.245.128
[test]
path=/root/rsync
use chroot=true
max connections=4
read only=no
list=true
uid=root
gid=root
auth users=test
secrets file=/etc/rsyncd.passwd
hosts allow=192.168.245.130
:wq

rsyncd.conf 配置文件详解

port : 指定在哪一个端口启动rsyncd服务。默认是873端口。

log file :指定日志文件。

pid file :指定pid文件,这个文件的做用设计服务的启动、中止等进程曾管理操做。

address : 指定启动rsyncd 服务的IP。假如你的机器有多个IP,就能够指定由其中一个启动rsyncd服务,若是不指定该参数,默认是在所有IP上启动。

[]:指定模块名,里面内容自定义。

path: 指定数据存放的路径。

use chroot true|false :表示在传输文件前首先chroot到path参数所指定的目录下。这样作的缘由是实现格外的安全防御,但缺点是须要以roots权限,而且不能备份指向外部的符号链接所指向的目录文件。默认状况下chroot值为true,若是你的数据当中有软链接文件,建议设置成false。

  • 启动服务 rsync --daemon

[root@aminglinux-01 ~]# rsync --daemon
[root@aminglinux-01 ~]# 
检测一下:
[root@aminglinux-01 ~]# ps aux |grep rsync
root       2403  0.0  0.0 114644   552 ?        Ss   21:07   0:00 rsync --daemon
root       2434  0.0  0.0 112664   976 pts/0    S+   21:09   0:00 grep --color=auto rsync
[root@aminglinux-01 ~]#
  • 格式: rsync -av test1/ 192.168.245.128::module/dir/

linux系统日志

/var/log/messages 系统日志,里面有各类各样的日志,网络系统内核等等不少

为了防止日志无限制的增长,系统有一个服务logrotate 来进行切割

[root@aminglinux-01 ~]# ls /var/log/messages*
/var/log/messages  /var/log/messages-20170829  /var/log/messages-20170904  /var/log/messages-20170911  /var/log/messages-20170917
[root@aminglinux-01 ~]#
能够看一下 cat /etc/logrotate.conf

[root@aminglinux-01 ~]# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly  一周分割一次

# keep 4 weeks worth of backlogs
rotate 4  分割为四个

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
	minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.
[root@aminglinux-01 ~]#

dmesg 系统硬件的日志,这个日志是在内存中的,能够-c清空。通常有问题会有error等关键字

/var/log/dmesg 与上面的dmesg日志无关联,记录系统启动的日志

last命令 调用的文件 /var/log/wtmp 用来查看正确登录的历史。

lastb命令 查看登录失败的历史。调用的/var/log/btmp

安全日志 :/var/log/secure

screen工具

为了避免让一个任务意外中断 ,

能够把任务丢到后台去:nohup command &

可是后台不能实时的看到输出

screen 是一个虚拟终端

安装yum install -y screen

安装好后直接敲screen

Ctrl+a 再按d 把screen丢到后台。

screen -ls 列出screen

screen -r 加上指定的id或者名字就能回去

exit 杀死 screen

screen -S "test_screen" 自定义 screen名字

相关文章
相关标签/搜索