rsync,linux系统日志,screen工具
2018-06-18 11:40
246 查看
linux 文件同步工具rsync
安装rsync:yum install -y rsyncrsync可以远程和本地同步数据,但是和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:路径
[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 DESTrsync [OPTION] SRC [USER@]HOST:DEST
rsync [OPTION] [USER@]HOST:SRC DEST
rsync [OPTION] [USER@]HOST::DEST
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名字
相关文章推荐
- rsync 通过服务的方式同步 linux系统日志 screen工具
- rsync 通过服务的方式同步 linux系统日志 screen工具
- rsync通过服务同步、Linux系统日志、screen工具
- Linux学习第三十四篇:rsync通过服务同步,Linux系统日志,screen工具
- 171206 8周3次课 rsync通过服务同步、linux系统日志、screen工具
- 10.32/10.33 rsync通过服务同步 10.34 linux系统日志 10.35 scre
- rsync通过服务同步、linux日志、screen工具
- rsync通过服务同步、 linux系统日志 、screen工具
- rsync通过服务同步、linux系统日志
- 12.6 rsync通过服务同步 linux系统日志 screen工具
- linux的rsync服务同步、系统日志及screen工具介绍
- 32.rsync服务同步,Linux系统日志,screen工具
- rsync通过服务同步、linux系统日志、screen工具
- rsync通过服务同步、linux系统日志、screen工具
- 10.32/10.33 rsync通过服务同步 10.34 linux系统日志 screen工具
- 10.32-10.33 rsync服务同步;10.34 Linux系统日志10.35screen工具
- rsync通过服务的方式同步、linux系统日志、screen工具
- rsync通过服务同步、linux系统日志和screen工具
- rsync通过服务同步,Linux系统日志,screen工具