Article catalog
preface
Experimental environment
- Configure ssh keyless login and time synchronization
2 . Set the rsync configuration file to ensure that the two servers can push and monitor each other
a. Configuration of server 1:
- Install xinetd and start
- Modify profile
3) Modify password file and modify permissions
4) Launch and view
b. Configuration of server 2 - Install xinetd and start
- Modify profile
3) Modify password file and modify permissions
4) Launch and view
- Configure inotify
1) Download epel source
2) Install inotify
5 . test
summary
preface
We can use rsync to realize triggered file synchronization, but when triggered by the crontab daemon, there will be a delay in synchronizing data. inotify just makes up for the defect of crontab. It can monitor the addition, deletion, modification and change of the file system in real time. When there is any change in the file, rsync synchronization will be triggered. It solves the real-time problem of rsync synchronization.
Experimental environment
Server 1 192.168.1.64 gaosh-64
Server 2 192.168.1.22 gaosh-1
Experimental steps:
- Configure ssh keyless login and time synchronization
- Set the rsync configuration file to ensure that the two servers can push and monitor each other
- Configure inotify
- Test for synchronization
1. Configure ssh keyless login and time synchronization
[root@gaosh-1 ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): 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: 04:12:28:0a:04:3e:33:09:b7:c9:36:73:9b:ae:e3:de root@gaosh-1 The key's randomart image is: +--[ RSA 2048]----+ |=...o.. | |=ooo . . | |oBB . . | |..++ o . | | o S | | . | | . | | .o | | o+.E | +-----------------+ [root@gaosh-1 ~]#
[root@gaosh-1 ~]# ssh-copy-id 192.168.1.64 The authenticity of host '192.168.1.64 (192.168.1.64)' can't be established. RSA key fingerprint is 3a:13:d9:39:09:d1:7a:5c:0f:a7:08:ad:f9:ee:85:b5. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.1.64' (RSA) to the list of known hosts. root@192.168.1.64's password: Now try logging into the machine, with "ssh '192.168.1.64'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
Configure time synchronization:
Server 1:
[root@gaosh-1 ~]# yum install ntpdate [root@gaosh-1 ~]# ntpdate -u 0.pool.ntp.org
Server 2:
[root@gaosh-64 ~]# ntpdate -u 0.pool.ntp.org 17 Jul 08:34:01 ntpdate[11325]: adjust time server 84.16.67.12 offset -0.032762 sec [root@gaosh-64 ~]# date 2020 Friday, July 17, 2008:34:04 CST
2 . Set the rsync configuration file to ensure that the two servers can push and monitor each other
a. Configuration of server 1:
1) Install xinetd and start
[root@gaosh-1 ~]# mkdir /gitbackup [root@gaosh-1 ~]# yum install xinetd [root@gaosh-1 ~]# service xinetd restart stop it xinetd: [fail] Starting xinetd: [determine] [root@gaosh-1 ~]#
2) Modify profile
Create backup directory
mkdir /gitbackup [root@gaosh-1 ~]# chmod 600 /gitbackup
[root@gaosh-1 ~]# vim /etc/rsyncd.conf uid = root gid = root usechroot = no max connections = 20 timeout = 600 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log [backup] path = /gitbackup ignore errors read only = false writeonly = false list = false hosts allow = 192.168.1.0/24 hosts deny = 0.0.0.0/32 auth users = backuser secrets file = /etc/rsync.passwd
3) Modify password file and modify permissions
[root@gaosh-1 ~]# cat /etc/rsync.passwd backuser:123456 [root@gaosh-1 ~]# chmod 600 /etc/rsync.passwd
4) Launch and view
[root@gaosh-1 ~]# rsync --daemon [root@gaosh-1 ~]# ps -ef |grep rsync root 45336 1 0 08:45 ? 00:00:00 rsync --daemon root 45338 45151 0 08:45 pts/2 00:00:00 grep rsync [root@gaosh-1 ~]#
b. Configuration of server 2
1) Install xinetd and start
[root@gaosh-1 ~]# mkdir /gitbackup [root@gaosh-1 ~]# yum install xinetd [root@gaosh-1 ~]# systemctl restart xinetd stop it xinetd: [fail] Starting xinetd: [determine] [root@gaosh-1 ~]#
2) Modify profile
Create backup directory
mkdir /gitbackup [root@gaosh-1 ~]# chmod 600 /gitbackup
[root@gaosh-1 ~]# vim /etc/rsyncd.conf uid = root gid = root usechroot = no max connections = 20 timeout = 600 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log [backup] path = /gitbackup ignore errors read only = false writeonly = false list = false hosts allow = 192.168.1.0/24 hosts deny = 0.0.0.0/32 auth users = backuser secrets file = /etc/rsync.passwd
3) Modify password file and modify permissions
[root@gaosh-1 ~]# cat /etc/rsync.passwd backuser:123456 [root@gaosh-1 ~]# chmod 600 /etc/rsync.passwd
4) Launch and view
[root@gaosh-64 ~]# rsync --daemon [root@gaosh-64 ~]# ps -ef |grep rsync root 11524 1 0 08:49 ? 00:00:00 rsync --daemon root 11527 11158 0 08:49 pts/0 00:00:00 grep --color=auto rsync
4. Configure inotify
Server 1:
1) Download epel source
[root@gaosh-1 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2) Install inotify
yum install inotify-tools -y
5 . test
Server 2:
[root@gaosh-1 gitbackup]# pwd /gitbackup [root@gaosh-1 gitbackup]# touch test1 [root@gaosh-64 gitbackup]# rsync -avz /gitbackup/ backuser@192.168.1.17::backup Password:
Server 2
Check whether the directory is synchronized successfully
[root@gaosh-64 gitbackup]# ls test1
summary
rysnc+inotify realizes the real-time synchronization of code or files, which solves the problem of crontab delay.
Because we haven't learned the shell script at this time, we have omitted the content of the shell script for the time being. After learning the shell script later, we will add the script content in this article. Trigger mechanism for automatic synchronization.
I am Gao Shenghan, a person who never forgets his original heart in the education and training industry. If you have better ideas, you can leave a message to communicate with me. See you in the next article
rsync series:
[Linux] step by step learning operation and maintenance - service part - rysnc principle
[Linux] step by step operation and maintenance - Services - rysnc installation and use
[Linux] step by step operation and maintenance - Services - rsync configuration file
[Linux] step by step operation and maintenance - Services - rsync actual combat
[Linux] step by step operation and maintenance - Services - inotify deployment and Application
[Linux] step by step operation and maintenance - Services - rysnc+inotify actual combat