• 10.32/10.33 rsync通过服务同步 10.34 linux系统日志 10.35 screen工具


    [root@lizhipenglinux01 ~]# mkdir /tmp/rsync
    [root@lizhipenglinux01 ~]# chmod 777 /tmp/rsync

    第二个机器

    [root@lizhipeng02 ~]# rsync -avP /tmp/lizhipeng.txt 192.168.5.128::test/lizhipeng0129.txt
    rsync: failed to connect to 192.168.5.128 (192.168.5.128): No route to host (113)                 不通,检查下原因
    rsync error: error in socket IO (code 10) at clientserver.c(122) [sender=3.0.9]
    [root@lizhipeng02 ~]# ping 192.168.5.128
    PING 192.168.5.128 (192.168.5.128) 56(84) bytes of data.                                                     能ping通,再检查下telent
    64 bytes from 192.168.5.128: icmp_seq=1 ttl=64 time=0.351 ms
    64 bytes from 192.168.5.128: icmp_seq=2 ttl=64 time=0.218 ms
    64 bytes from 192.168.5.128: icmp_seq=3 ttl=64 time=1.08 ms
    ^C
    --- 192.168.5.128 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2001ms
    rtt min/avg/max/mdev = 0.218/0.552/1.089/0.384 ms

    [root@lizhipeng02 ~]# telnet 192.168.5.128 873           检查端口是否通,不通,检查一下iptables
    Trying 192.168.5.128...
    telnet: connect to address 192.168.5.128: No route to host

    [root@lizhipeng02 ~]# systemctl stop firewalld    关闭firewalld,机器1同样

    [root@lizhipeng02 ~]# telnet 192.168.5.128 873         通了
    Trying 192.168.5.128...
    Connected to 192.168.5.128.
    Escape character is '^]'.
    @RSYNCD: 30.0

    [root@lizhipeng02 ~]# rsync -avP /tmp/lizhipeng.txt 192.168.5.128::test/lizhipeng0129.txt
    Password:

    密码关闭

    [root@lizhipeng02 ~]# rsync -avP /tmp/lizhipeng.txt 192.168.5.128::test/lizhipeng0129.txt               同步成功
    sending incremental file list
    lizhipeng.txt
    1244 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)

    sent 1321 bytes received 27 bytes 898.67 bytes/sec
    total size is 1244 speedup is 0.92

    [root@lizhipenglinux01 ~]# ls /tmp/rsync/     1机器下有这个文件
    lizhipeng0129.txt

    [root@lizhipeng02 ~]# rsync -avP 192.168.5.128::test/lizhipeng0129.txt          /tmp/123.txt      机器1同步到机器2
    receiving incremental file list
    lizhipeng0129.txt
    1244 100% 1.19MB/s 0:00:00 (xfer#1, to-check=0/1)

    sent 45 bytes received 1356 bytes 2802.00 bytes/sec
    total size is 1244 speedup is 0.89

    [root@lizhipenglinux01 ~]# cd /tmp/rsync/
    [root@lizhipenglinux01 rsync]# ls
    lizhipeng0129.txt
    [root@lizhipenglinux01 rsync]# ln -s /etc/passwd ./12.txt                      机器1创建软链接12.txt指向/etc/passwd
    [root@lizhipenglinux01 rsync]# ls -l
    总用量 4
    lrwxrwxrwx 1 root root 11 1月 30 07:32 12.txt -> /etc/passwd
    -rw-r--r-- 1 root root 1244 1月 29 01:06 lizhipeng0129.txt

    机器2同步目录

    [root@lizhipeng02 ~]# rsync -avP 192.168.5.128::test/ /tmp/test/
    receiving incremental file list
    created directory /tmp/test
    ./
    12.txt -> /etc/passwd
    lizhipeng0129.txt
    1244 100% 1.19MB/s 0:00:00 (xfer#1, to-check=0/3)

    sent 51 bytes received 1407 bytes 2916.00 bytes/sec
    total size is 1255 speedup is 0.86

    没有同步成功

    改成false

    [root@lizhipeng02 ~]# rsync -avP 192.168.5.128::test/ /tmp/test/                同步成功了
    receiving incremental file list
    12.txt -> /etc/passwd

    sent 29 bytes received 117 bytes 292.00 bytes/sec
    total size is 1255 speedup is 8.60
    [root@lizhipeng02 ~]# ls -l /tmp/test/
    总用量 4
    lrwxrwxrwx. 1 root root 11 1月 30 07:32 12.txt -> /etc/passwd
    -rw-r--r--. 1 root root 1244 1月 29 01:06 lizhipeng0129.txt
    [root@lizhipeng02 ~]#

     

    [root@lizhipeng02 ~]# rsync -avLP 192.168.5.128::test/ /tmp/test/                              机器2同步出错,因为端口号不对
    rsync: failed to connect to 192.168.5.128 (192.168.5.128): Connection refused (111)
    rsync error: error in socket IO (code 10) at clientserver.c(122) [Receiver=3.0.9]

    [root@lizhipeng02 ~]# rsync -avLP --port 8730 192.168.5.128::test/ /tmp/test/      --port 8730指定端口号
    receiving incremental file list
    ./
    12.txt
    1244 100% 1.19MB/s 0:00:00 (xfer#1, to-check=2/4)
    lizhipeng0130.txt
    1244 100% 1.19MB/s 0:00:00 (xfer#2, to-check=0/4)

    sent 67 bytes received 2701 bytes 5536.00 bytes/sec
    total size is 3732 speedup is 1.35

    [root@lizhipenglinux01 ~]# vim /etc/rsyncd.conf

    权限不够

    [root@lizhipenglinux01 ~]# vim /etc/rsyncd.conf        uid,gid改成root
    [root@lizhipenglinux01 ~]# cd /tmp/rsync/
    [root@lizhipenglinux01 rsync]# ls
    12.txt lizhipeng0129.txt lizhipeng0130.txt

    [root@lizhipenglinux01 rsync]# chmod 600 !$
    chmod 600 /etc/rsyncd.passwd

    [root@lizhipeng02 ~]# rsync -avP /tmp/test/ --port=8730 test@192.168.5.128::test/
    Password:
    sending incremental file list
    ./

    sent 105 bytes received 20 bytes 19.23 bytes/sec
    total size is 3732 speedup is 29.86
    [root@lizhipeng02 ~]# touch /tmp/test/1.txt
    [root@lizhipeng02 ~]# rsync -avP /tmp/test/ --port=8730 test@192.168.5.128::test/
    Password:
    sending incremental file list
    ./
    1.txt
    0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=3/5)

    sent 149 bytes received 30 bytes 32.55 bytes/sec
    total size is 3732 speedup is 20.85

    客户端填写密码

    [root@lizhipeng02 ~]# vim /etc/rsync_pass.txt
    [root@lizhipeng02 ~]# chmod 600 !$
    chmod 600 /etc/rsync_pass.txt

    [root@lizhipeng02 ~]# touch /tmp/test/2.txt
    [root@lizhipeng02 ~]# rsync -avP /tmp/test/ --port=8730 --password-file=/etc/rsync_pass.txt test@192.168.5.128::test/                           不需要输入密码
    sending incremental file list
    ./
    2.txt
    0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=2/6)

    sent 163 bytes received 30 bytes 386.00 bytes/sec
    total size is 3732 speedup is 19.34

    [root@lizhipenglinux01 ~]# ls /var/log/message*
    /var/log/messages /var/log/messages-20180108 /var/log/messages-20180114 /var/log/messages-20180121 /var/log/messages-20180128

    [root@lizhipenglinux01 ~]# dmesg -c  清空日志 内存中的

    [root@lizhipenglinux01 ~]# last 记录正确的登陆时间

    [root@lizhipenglinux01 ~]# lastb   登陆失败

    btmp begins Wed Jan 31 05:37:48 2018

    [root@lizhipenglinux01 ~]# ls /var/log/btmp
    /var/log/btmp
    [root@lizhipenglinux01 ~]# ls /var/log/secure
    /var/log/secure

    [root@lizhipenglinux01 ~]# screen                 ctrl+a同时按,然后按d
    [detached from 3389.pts-0.lizhipenglinux01]

    [root@lizhipenglinux01 ~]# screen -ls
    There is a screen on:
    3389.pts-0.lizhipenglinux01 (Detached)
    1 Socket in /var/run/screen/S-root.

    [root@lizhipenglinux01 ~]# screen -r 3389. 回去

    [root@lizhipenglinux01 ~]# screen
    [detached from 3430.pts-0.lizhipenglinux01]
    [root@lizhipenglinux01 ~]# screen
    [detached from 3449.pts-0.lizhipenglinux01]
    [root@lizhipenglinux01 ~]# screen
    [detached from 3468.pts-0.lizhipenglinux01]
    [root@lizhipenglinux01 ~]# screen -lsn
    There are screens on:
    3468.pts-0.lizhipenglinux01 (Detached)
    3449.pts-0.lizhipenglinux01 (Detached)
    3430.pts-0.lizhipenglinux01 (Detached)
    3 Sockets in /var/run/screen/S-root.

    [root@lizhipenglinux01 ~]# screen -r 3468.
    [detached from 3468.pts-0.lizhipenglinux01]
    [root@lizhipenglinux01 ~]# screen -lsn
    There are screens on:
    3468.pts-0.lizhipenglinux01 (Detached)
    3449.pts-0.lizhipenglinux01 (Detached)
    3430.pts-0.lizhipenglinux01 (Detached)
    3 Sockets in /var/run/screen/S-root.

    [root@lizhipenglinux01 ~]# screen -S "test_screen"
    [detached from 3499.test_screen]
    [root@lizhipenglinux01 ~]# screen -ls
    There are screens on:
    3499.test_screen (Detached)
    3468.pts-0.lizhipenglinux01 (Detached)
    3449.pts-0.lizhipenglinux01 (Detached)
    3430.pts-0.lizhipenglinux01 (Detached)
    4 Sockets in /var/run/screen/S-root.

  • 相关阅读:
    C#各版本新特性
    ubantu操作积累
    C# System.Net.Http.HttpClient使用说明
    IIS下VUE跳转
    融合主流的技术 分布式中间件+微服务+微架构架构
    论减少代码中return语句的骚操作
    shell脚本--多个代码库批量pull最新master代码
    SpringBoot单元测试
    Qt音视频开发36-USB摄像头解码qcamera方案
    Qt音视频开发35-Onvif图片参数
  • 原文地址:https://www.cnblogs.com/sisul/p/8387833.html
Copyright © 2020-2023  润新知