In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces rsync+inotify how to achieve multiple web data dynamic synchronization operation, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
* background: since there is no storage sharing device, the codes in the web cluster are stored locally, resulting in data inconsistency between web nodes.
* solution: using rsync+inotify to realize the dynamic synchronization of multiple web data
* solution: for example, there are four web (a, b, c, d). In order to determine which server is the source data server, we install rsync+inotify on server A, and then point a second-level domain name to server A, so that website editors and developers visit the second-level domain name to update the website on a daily basis. Server A will dynamically (trigger) send update data to other servers when it detects local data updates.
* Note: be sure to use the same version of rsync, otherwise an unknown error will occur.
* reasons for choosing rsync+inotify: in regular data synchronization application cases, most people will choose to use rsync to complete data synchronization. The reasons for choosing rsync+inotify are as follows
The code is as follows:
1. Server performance: rsync can only achieve regular updates. Regardless of whether the website has a file update or not, rsync will check whether the file is updated according to the scheduled task, which will degrade the server performance when the data file is large, while rsync+inotify
It is a trigger update, that is, it is updated only when a file is changed, which has little impact on server performance.
2. Real-time data: if you choose rsync, how often to synchronize data is a problem. The shorter the time, the greater the impact on performance. The time is too long for the user / editor to accept. Real-time update can be realized by using rsync+inotify
When the A server file is updated, other servers update immediately
* Environment Topology
The code is as follows:
A:192.168.1.101
B:192.168.1.102
C:192.168.1.103
D:192.168.1.104
Note: the data source server is An and the target servers are B, C, D
* 1. Install rsync on the target server (operate on B, C, D servers with the same installation configuration)
* install rsync download address: http://rsync.samba.org/
The code is as follows:
Cd / data/software
Wget https://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
Tar zxvf rsync-3.0.9.tar.gz
Cd rsync-3.0.9
. / configure
Make
Make install
* display information after installation is complete
The code is as follows:
Mkdir-p / usr/local/bin
/ usr/bin/install-c-m 755 rsync / usr/local/bin
Mkdir-p / usr/local/share/man/man1
Mkdir-p / usr/local/share/man/man5
If test-f rsync.1; then / usr/bin/install-c-m 644 rsync.1 / usr/local/share/man/man1; fi
If test-f rsyncd.conf.5; then / usr/bin/install-c-m 644 rsyncd.conf.5 / usr/local/share/man/man5; fi
* configure rsync
* # add the following content to vi / etc/rsync.conf
The code is as follows:
Uid = root
Gid = root
Use chroot = no
Max connections = 20
Strict modes = yes
Log file = / data/logs/rsyncd/rsyncd.log
Pid file = / data/logs/rsyncd/rsyncd.pid
Lock file = / data/logs/rsyncd/rsync.lock
Log format =% t% a% m f% b
[web]
Path = / data/vhosts/it121net/
Auth users = username
Read only = no
Hosts allow = 192.168.1.0 hosts allow 24 # can be an IP segment or an IP address
List = no
Uid = root
Gid = root
Secrets file = / etc/rsync.passwd
Ignore errors = yes
* create a directory to store logs.
The code is as follows:
Mkdir / data/logs/rsyncd
* create certification
* # vi / etc/rsync.passwd
The code is as follows:
Username:passwd
* # chmod 600 / etc/rsync.passwd
* start rsync. Use netstat to check after startup, and you will find that the system has started port 873.
The code is as follows:
# rsync-daemon-config=/etc/rsync.conf
* join boot boot
The code is as follows:
# echo "rsync-- daemon-- config=/etc/rsync.conf" > > / etc/rc.local
* close
The code is as follows:
Killall rsync
* install rsync+inotify on the source server (operate on a server)
* install rsync (just install it, no configuration required)
The code is as follows:
Cd / data/software
Wget https://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
Tar zxvf rsync-3.0.9.tar.gz
Cd rsync-3.0.9
. / configure
Make
Make install
* echo "passwd" > / etc/rsync-client.passwd
* chmod 600 / etc/rsync-client.passwd
* install inotify download address: https://github.com/rvoicilas/inotify-tools/wiki/
The code is as follows:
Cd / data/software
Wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
Tar zxvf inotify-tools-3.14.tar.gz
Cd inotify-tools-3.14
. / configure
Make
Make install
* create a startup script
* # add the following content to vi / etc/rsync-web.sh
The code is as follows:
#! / bin/sh
SRC=/data/vhosts/it121net/
DES=web
WEB2=192.168.1.102
WEB3=192.168.1.103
WEB4=192.168.1.104
USER=username
/ usr/local/bin/inotifywait-mrq-e create,move,delete,modify $SRC | while read D E F
Do
Rsync- ahqzt-- password-file=/etc/rsync-client.passwd-- delete $SRC $USER@$WEB2::$DES
Rsync- ahqzt-- password-file=/etc/rsync-client.passwd-- delete $SRC $USER@$WEB3::$DES
Rsync- ahqzt-- password-file=/etc/rsync-client.passwd-- delete $SRC $USER@$WEB4::$DES
Done
# Note: most of the network shows a middle bar, which may be a matter of coding, but it should actually be two bars.
* increase permissions
The code is as follows:
# chmod + x / etc/rsync-web.sh
* Startup script
The code is as follows:
# nohup / etc/rsync-web.sh & / / must be executed in the background using nohup, otherwise the script process will end automatically after the terminal is closed
/ etc/rsync-web.sh &
* close the script
The code is as follows:
Sudo pkill rsync
Sudo pkill inotifywait
* @ ERROR: chdir failed rsync error: error starting client-server protocol (code 5) at main.c (1503) [sender=3.0.6] solution
The code is as follows:
Setsebool-P rsync_disable_trans on
* rsync installation path (check it out)
The code is as follows:
/ usr/bin/rsync
/ usr/local/bin/rsync
/ etc/xinetd.d/rsync
Thank you for reading this article carefully. I hope the article "how to realize the dynamic synchronization of multiple web data by rsync+inotify" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.