Source package installation, rsync synchronization, inotify monitoring

A source code package installation

  1. The role of the Source Package: yum rpm package is used, rpm package installation the installation location can not be specified

          Source packages can be selected as desired / customized, timely repair bug, for a variety of platforms

  2, the general process: Source Package -> make gcc source bag into the executable program ----> Run Setup

  3. This requires make, gcc software support, under the yum install gcc and make

  4. Download Source Package wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

  5, extract the source packet: [root @ localhost ~] # tar -xf inotify-tools-3.14.tar.gz -C / opt /

  You can view complete decompression in the decompression directory:

[root@localhost ~]# ls /opt
inotify-tools-3.14  rh
[root@localhost ~]# ls /opt/inotify-tools-3.14
aclocal.m4  ChangeLog     config.h.in  configure     COPYING  INSTALL     libinotifytools  Makefile.am  man      NEWS    src
AUTHORS     config.guess  config.sub   configure.ac  depcomp  install-sh  ltmain.sh        Makefile.in  missing  README

  6,. / Configure configuration {purpose is to specify the installation directory This command and the function module and installed, and can detect whether gcc}

    But we must note that the configuration in which the source code is in which to operate, that is, to just extract to the cd to the directory to

[root@localhost ~]# cd /opt/inotify-tools-3.14 #cd 不能忘
[root@localhost inotify-tools-3.14]# ls
aclocal.m4  ChangeLog     config.h.in  configure     COPYING  INSTALL     libinotifytools  Makefile.am  man      NEWS    src
AUTHORS     config.guess  config.sub   configure.ac  depcomp  install-sh  ltmain.sh        Makefile.in  missing  README

  Use ./configure --prefix = directory location specified install

  (For example, here designated / mnt / myrpm, but ended This command, / mnt / myrpm not generated, only where specified)

  If gcc is not installed, it will report a similar gcc ---> no errors

[root@localhost inotify-tools-3.14]# ./configure --prefix=/mnt/myrpm
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make sets $(MAKE)... (cached) yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o

  7.make compiler to generate an executable binary file

  #make command to

  8, make install to install the compiled files will be copied to the installation directory, there really generate the specified file before installing

  Look:

 

[root@localhost inotify-tools-3.14]# ls /mnt/myrpm/
bin  include  lib  share
[root@localhost inotify-tools-3.14]# ls /mnt/myrpm//bin
inotifywait  inotifywatch

Two, rsync synchronization

  rsync [options] source directory target directory

Copy: completely copied to the target file

Synchronization: incremental copying, transmitting only changes over the transmission of data

Options: -n: do not do the actual testing synchronization process modifications

   --delete: delete unnecessary documents from the destination folder

   -a: archive mode

   -v: display detailed information of the operation

   -z: during transmission enable compression / decompression

1. Local synchronization: rsync a local directory local directory 2 (the entire folder synchronization)

      1 rsync local directory / local directory 2 (synchronization file directory)

Such as:

[root@localhost ~]# mkdir -p /haha/happy /xixi

[root@localhost ~]# rsync -av /haha /xixi
sending incremental file list
haha/
haha/happy/
haha/happy/1.txt

sent 165 bytes received 47 bytes 424.00 bytes/sec
total size is 6 speedup is 0.03
[root@localhost ~]# ls /xixi
haha

Where / when the directory haha ​​haha ​​also sync

[root@localhost ~]# rsync -av /haha/ /xixi
sending incremental file list
./
happy/
happy/1.txt

sent 152 bytes received 46 bytes 396.00 bytes/sec
total size is 6 speedup is 0.03

[root@localhost ~]# ls /xixi
haha happy

Here we use / haha ​​/ sync content only under haha, such synchronization are generally

  2. Remote synchronization:

  Uplink: rsync [options] user @ host: remote directory local directory

  Downlink: rsync [options] Local directory user @ host: remote directory

[root@localhost ~]# rsync -av /haha/ [email protected]:/haha
[email protected]'s password:
sending incremental file list
created directory /haha
./
happy/
happy/1.txt

sent 156 bytes received 74 bytes 5.17 bytes/sec
total size is 6 speedup is 0.03
[root@localhost ~]#

Can be seen, need password authentication when remote synchronization, where you can use public and private keys to be synchronized password-free

As long as one of the synchronization hold the other of A's private key and the public key of A and B to achieve matching public and private keys, to avoid adhesion

Here ssh-keygen generates a public and private key

[root@localhost ~]# 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:
SHA256:8boQ5FfByR1t/kwWvsg5L70YqIOxNHy4xXLEdbfykrQ [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| o.o.o 
| +o..oo |
| . o o .oo o|
| o * o.oo|
| + S . o B=.|
| X * .E oo|
| o % . .= |
| = o. .oo |
| ... ....|
+----[SHA256]---

Using ssh-copy-id root @ B IP is used to send the public key A to B

Generating a public and private key position is /root/.ssh

B is the position of the public key present /root/.ssh/authorized-keys

[root@localhost ~]# ssh-copy-id [email protected]

At this point, you do not need to use sync password

[root@localhost ~]# rsync -av /haha/ [email protected]:/haha
sending incremental file list

sent 93 bytes received 13 bytes 70.67 bytes/sec
total size is 6 speedup is 0.06

Third, real-time monitoring

After synchronization, content to do only the source document changes, the document must be synchronized in real-time change, as to know how to change the content of the document, which need to be monitored to inotify

Usually this will inotify package placed in the / usr / local, inotify when the download package cp source to the / usr / local, and then through to ./configure make make install

This is the operation in A

[root@localhost ~]# ls /usr/local/bin
inotifywait inotifywatch

Observed inotifywait is a success, inotifywait is used to monitor changes in the program directory

For example, in the / haha ​​then create a directory (Open the terminal operation), a change can be seen under inotifywait

[root@localhost local]# inotifywait -rq /haha/
/haha/ CREATE,ISDIR xixixi

################################################################################

Currently only the monitoring is successful, how do changes in a monitored directory is automatically synchronized, there needs to be implemented by the shell script

Location where the shell script: /root/rsync.sh

#!/bin/bash
 while inotifywait -rqq /haha/
  do
    rsync -a --delete /haha/ root@192.168.142.138:/haha/
  done

[root@localhost ~]# ls -ld /root/rsync.sh
-rw-r--r--. 1 root root 112 9月 18 14:54 /root/rsync.sh
[root@localhost ~]# chmod +x /root/rsync.sh
[root@localhost ~]# ls -ld /root/rsync.sh
-rwxr-xr-x. 1 root root 112 9月 18 14:54 /root/rsync.sh

To give the script execution permissions

This time run this script [root @ localhost ~] # /root/rsync.sh

A change to open a terminal inside / haha ​​B in / haha ​​immediately change

 

Guess you like

Origin www.cnblogs.com/zhanglei97/p/11542309.html