1. 程式人生 > >10.32/10.33 rsync通過服務同步 10.34 linux系統日誌 10.35 screen工具

10.32/10.33 rsync通過服務同步 10.34 linux系統日誌 10.35 screen工具

rec var cti 服務 error ota director com directory

技術分享圖片

技術分享圖片

技術分享圖片

[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 [email protected]::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 [email protected]::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 [email protected]::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.

10.32/10.33 rsync通過服務同步 10.34 linux系統日誌 10.35 screen工具