For data synchronization through rsycn

First, the experimental requirements

/ App 1. Back up all files in the machine needs early in the morning 1:03 minutes daily timing synchronization MIS server / under java_project directory.
2. Records synchronization log, easy synchronization fails analyze the reasons.

Second, task analysis

1. Use the crontab scheduled tasks to write

2. Use rsync to synchronize remotely

3. Because it is timed task, rsync ssh-based services, you need two servers to set up ssh login-free secret

Third, the experimental topology

image

Fourth, the experimental environment Introduction

IP server 128 to the MIS server, code storage directory is / app / java_project, this directory needs to go back up

IP server 129 to the backup server to the code, the code needs to be backed up to the server 128 on / backup / app / java_project

Five experiments concrete steps

1. Two server configuration ssh login-free secret

     129 Free adhesion can be required to log on to the server 128

[root@back ~]# ssh-keygen         //生成密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0d:8c:ee:fe:38:88:44:f9:1c:a3:8f:18:23:01:06:83 root@back
The key's randomart image is:
+--[ RSA 2048]----+
|=                |
|Eo     o         |
|o  .  . o        |
|. o o.   o       |
| o + o. S .      |
|+ o o.           |
|.= + ..          |
|. o o...         |
|      oo.        |
+-----------------+
 
[root@back .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.189.128        //把公钥远程拷贝到128主机上
The authenticity of host '192.168.189.128 (192.168.189.128)' can't be established.
RSA key fingerprint is df:28:9d:09:a3:bf:52:a6:e5:ce:f2:a4:04:0d:b8:cc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.189.128' (RSA) to the list of known hosts.
root@192.168.189.128's password: 
Now try logging into the machine, with "ssh '[email protected]'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
[. root @ the Back ssh ] # ssh root @ 192.168 . 189.128 
Last the Login : Sun Jul 21  22 : 45 : 44  2019 from 192.168 . 189.1 
// test ssh-free secret registration is completed


2. Turn on the rsync service (on MIS server)

Documents related to watch https://www.cnblogs.com/feng0919/p/11223473.html

[root@MIS .ssh]# yum install rsync
已安装:
  rsync.x86_64 0:3.0.6-12.el6                                                                                                                                                         
完毕!

[root@MIS .ssh]# vim /etc/rsyncd.conf

[java]
path = /app/java_project/
log file = /tmp/rsync.log

[root@MIS .ssh]# rsync --daemon


3. by scripting a scheduled task

[root@back ~]# vim rstnc.sh

#!/bin/bash
rsync -a 192.168.189.128::java /backup/app/java_project/

[root@back ~]# chmod +x rstnc.sh 
[root@back ~]# crontab -e
no crontab for root - using an empty one

03 01 * * * /root/rsync.sh &>/dev/null

Guess you like

Origin www.cnblogs.com/feng0919/p/11223537.html