rsync通过服务同步、Linux系统日志、screen
作者:快盘下载 人气:
rsync通过服务同步
Linux文件同步工具-rsync
rsync通过服务同步
Linux文件同步工具-rsync
更改rsync配置文件
其中[test]为模块名字
模块代表路径为path=/tmp/rsync
这里没有用密码
日志路径
[root@wsl-001 ~]# vim /etc/rsyncd.conf 添加如下内容 port=873 log file=/var/log/rsync.log pid file=/var/run/rsyncd.pid address=192.168.133.130 [test] path=/tmp/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.133.132 [root@wsl-001 ~]# rsync --daemon [root@wsl-001 ~]# ps aux |grep rsync root 4505 0.0 0.0 114652 524 ? Ss 22:13 0:00 rsync --daemon root 4509 0.0 0.0 112676 984 pts/2 R+ 22:13 0:00 grep --color=auto rsync [root@wsl-001 ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 904/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1125/master tcp 0 0 172.16.79.140:873 0.0.0.0:* LISTEN 4505/rsync tcp6 0 0 :::22 :::* LISTEN 904/sshd tcp6 0 0 ::1:25 :::* LISTEN 1125/master [root@wsl-001 ~]# mkdir /tmp/rsync [root@wsl-001 ~]# chmod 777 /tmp/rsync/ [root@wsl-001 tmp]# systemctl stop firewalld [root@wsl-001 rsync]# cat /var/log/rsync.log |head 2018/03/26 22:13:24 [4505] rsyncd version 3.0.9 starting, listening on port 873 2018/03/27 20:01:18 [4505] sent 0 bytes received 0 bytes total size 0 2018/03/27 23:36:52 [1218] rsyncd version 3.0.9 starting, listening on port 873 2018/03/27 23:38:03 [1231] name lookup failed for 172.16.79.142: Name or service not known 2018/03/27 23:38:03 [1231] connect from UNKNOWN (172.16.79.142) 2018/03/27 23:38:11 [1231] auth failed on module test from unknown (172.16.79.142): unauthorized user 2018/03/27 23:38:30 [1234] name lookup failed for 172.16.79.142: Name or service not known 2018/03/27 23:38:30 [1234] connect from UNKNOWN (172.16.79.142) 2018/03/27 23:38:33 [1234] auth failed on module test from unknown (172.16.79.142): unauthorized user 2018/03/27 23:40:52 [1244] name lookup failed for 172.16.79.142: Name or service not known
切换到要备份的机器上
会发现873端口不通
查看是firewalld规则的原因
关闭掉firewalld
[root@wsl-001 tmp]# yum install telnet [root@wsl-001 tmp]# telnet 172.16.79.140 873 Trying 172.16.79.140... telnet: connect to address 172.16.79.140: No route to host [root@wsl-001 tmp]# systemctl stop firewalld [root@wsl-001 ~]# telnet 172.16.79.140 873 Trying 172.16.79.140... Connected to 172.16.79.140. Escape character is '^]'. @RSYNCD: 30.0 q @ERROR: protocol startup error Connection closed by foreign host. [root@wsl-001 ~]# rsync -av /tmp/1.txt 172.16.79.140::test/2.txt sending incremental file list 1.txt sent 86 bytes received 27 bytes 75.33 bytes/sec total size is 17 speedup is 0.15 [root@wsl-001 ~]# rsync -av 172.16.79.140::test/2.txt /tmp/123.txt receiving incremental file list 2.txt sent 45 bytes received 117 bytes 324.00 bytes/sec total size is 17 speedup is 0.10
rsync中L选项同步软连接源文件问题
源机器操作
[root@wsl-001 rsync]# ln -s /etc/passwd /tmp/rsync/12.txt
备份机操作
会发现报错
需要修改源机器中的配置文件为
use chroot=false
更改配置文件只要不更改端口就不用重启服务
[root@wsl-001 rsync]# rsync -avLP 172.16.79.140::test/ /tmp/test receiving incremental file list symlink has no referent: "/12.txt" (in test) created directory /tmp/test ./ 2.txt 17 100% 16.60kB/s 0:00:00 (xfer#1, to-check=0/2) sent 48 bytes received 185 bytes 466.00 bytes/sec total size is 17 speedup is 0.07 rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1518) [generator=3.0.9] [root@wsl-001 rsync]# ls /tmp/test/ 2.txt
修改源文件后
[root@wsl-001 rsync]# rsync -avLP 172.16.79.140::test/ /tmp/test receiving incremental file list 12.txt 1055 100% 1.01MB/s 0:00:00 (xfer#1, to-check=1/3) sent 45 bytes received 1184 bytes 819.33 bytes/sec total size is 1072 speedup is 0.87 [root@wsl-001 rsync]# ls /tmp/test/ 12.txt 2.txt [root@wsl-001 rsync]# cat /tmp/test/12.txt |head root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin
源机器更改端口为8730,重启服务
[root@wsl-001 rsync]# vim /etc/rsyncd.conf [root@wsl-001 rsync]# killall rsync [root@wsl-001 rsync]# !ps ps aux |grep rsync root 1653 0.0 0.0 112676 984 pts/0 S+ 16:22 0:00 grep --color=auto rsync [root@wsl-001 rsync]# rsync --daemon [root@wsl-001 rsync]# !ps ps aux |grep rsync root 1655 0.0 0.0 114652 524 ? Ss 16:22 0:00 rsync --daemon root 1657 0.0 0.0 112676 984 pts/0 R+ 16:22 0:00 grep --color=auto rsync [root@wsl-001 rsync]# !net netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 874/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1093/master tcp 0 0 172.16.79.140:8730 0.0.0.0:* LISTEN 1655/rsync tcp6 0 0 :::22 :::* LISTEN 874/sshd tcp6 0 0 ::1:25 :::* LISTEN 1093/master
备份机器
需要加上端口号
[root@wsl-001 rsync]# rsync -avLP 172.16.79.140::test/ /tmp/test rsync: failed to connect to 172.16.79.140 (172.16.79.140): Connection refused (111) rsync error: error in socket IO (code 10) at clientserver.c(122) [Receiver=3.0.9] [root@wsl-001 rsync]# rsync -avLP --port 8730 172.16.79.140::test/ /tmp/test receiving incremental file list created directory /tmp/test ./ 12.txt 1055 100% 1.01MB/s 0:00:00 (xfer#1, to-check=1/3) 2.txt 17 100% 16.60kB/s 0:00:00 (xfer#2, to-check=0/3) sent 67 bytes received 1247 bytes 2628.00 bytes/sec total size is 1072 speedup is 0.82
Linux文件同步工具-rsync
最大连接数是限制同时链接到服务器的数量
不列出模块名,更改配置文件参数list=false(避免被上传木马文件)
操作备份机器
[root@wsl-001 rsync]# rsync -avLP --port 8730 172.16.79.140:: test [root@wsl-001 rsync]# rsync -avLP --port 8730 172.16.79.140::
uid和gid的改变会导致权限的改变
密码文件
去掉auth和secrets注释
auth要和/etc/rsync.passwd 中的用户名一样
操作源机器
[root@wsl-001 rsync]# vim /etc/rsyncd.passwd [root@wsl-001 rsync]# chmod 600 /etc/rsyncd.passwd 添加 root:123
备份机器
[root@wsl-001 rsync]# rsync -avLP --port 8730 /tmp/test/ test@172.16.79.140::test/ Password: sending incremental file list ./ 12.txt 1055 100% 0.00kB/s 0:00:00 (xfer#1, to-check=1/3) sent 1156 bytes received 30 bytes 474.40 bytes/sec total size is 1072 speedup is 0.90 [root@wsl-001 rsync]# vim /etc/rsync-pass.txt [root@wsl-001 rsync]# chmod 600 /etc/rsync-pass.txt [root@wsl-001 rsync]# rsync -avLP --port 8730 /tmp/test/ --password-file=/etc/rsync-pass.txt test@172.16.79.140::test/ sending incremental file list sent 55 bytes received 8 bytes 126.00 bytes/sec total size is 1072 speedup is 17.02
Linux系统日志配置文件中的hosts allow可以添加多个
Linux系统日志
系统日志
[root@wsl-001 rsync]# ls -lh /var/log/messages -rw------- 1 root root 388K 3月 28 20:51 /var/log/messages [root@wsl-001 rsync]# ls -lh /var/log/messages* -rw------- 1 root root 388K 3月 28 20:51 /var/log/messages -rw-------. 1 root root 505K 2月 28 12:45 /var/log/messages-20180228 -rw-------. 1 root root 126K 3月 4 03:42 /var/log/messages-20180304 -rw-------. 1 root root 323K 3月 11 19:20 /var/log/messages-20180311 -rw-------. 1 root root 341K 3月 25 19:27 /var/log/messages-20180325
screen工具
安装进入screen
[root@wsl-001 rsync]# yum install screen [root@wsl-001 rsync]# screen [root@wsl-001 rsync]# vmstat 1 Ctrl + a + d (顺序组合) [detached from 2219.pts-0.wsl-001] [root@wsl-001 rsync]# screen -ls There is a screen on: 2219.pts-0.wsl-001 (Detached) 1 Socket in /var/run/screen/S-root. [root@wsl-001 rsync]# screen -r 2219 (回到刚才) [root@wsl-001 ~]# screen -ls There is a screen on: 2239.test1 (Detached) 1 Socket in /var/run/screen/S-root. [root@wsl-001 ~]# screen -r test1
扩展
Linux日志文件总管logrotate http://linux.cn/article-4126-1.html xargs用法详解 http://blog.csdn.net/zhangfn2011/article/details/6776925
加载全部内容