Original: 100 Cluster Storage Systems and real-time data backup, real-time Cluster
Server description Internet IP (NAT) Intranet IP (NAT) Host Name
Apache web Server 10.0.0.7/24 172.16.1.7/24 web02
Nginx web Server 10.0.0.8/24 172.16.1.8/24 web01
NFS storage server 10.0.0.31/24 172.16.1.31/24 nfs01
Rsync backup Server 10.0.0.41/24 172.16.1.41/24 backup
Requirements:
Build a website cluster with backend NFS shared storage and optimize the solution
1. Configure the NFS service:
Requirements:
1) share the/data directory on the NFS server nfs01, and allow mounting a total
.
2) when data is written to the mount point/data on the NFS client web01, data can be deleted on the NFS client web02.
Except or modifying.
(3) Build a backup server for the whole network of the website Cluster
Requirement: configure the Rsync Data Synchronization Service on the backup server, which can be pushed from the nfs01 server.
The/backup Directory of the backup server. Ben
Specific requirements: the backup Directory of the backup server must be/backup.
(4) solves the problem of single point of storage shared by the backend NFS of the website cluster for Real-time Data Synchronization
1. Real-time Data Synchronization requirements:
When a user writes data to the NFS server nfs01 through any web server, the data is copied to the backup server.
Backup.
NFS server
First Track: Check whether the nfs rpc service software is installed
Rpm-qa | grep nfs
Rpm-qa | grep rpc
Note: nfs and rpc service software is not installed in centos by default.
The second milestone: Installing nfs and rpc service software in yum
Yum install-y nfs-utils rpcbind
# Yum install-y nfs-utils rpcbind
Third milestone: compiling the NFS configuration file
NFS service configuration file
Cat>/etc/exports <EOF
/Data 172.16.1.0/24 (rw, sync)
EOF
Step 4: create a shared directory
Mkdir-p/data
Chown-R nfsnobody. nfsnobody/data
The fifth milestone: start the service
/Etc/init. d/rpcbind start
View NFS service registration information
#/Usr/sbin/rpcinfo
# Rpcinfo-p localhost
Set auto-start
Chkconfig rpcbind on
Chkconfig nfs on
View the rpcbind auto start number
Head-10/etc/init. d/rpcbind
Chkconfig: 2345 13 87
View nfs boot auto-start number
# Head-10/etc/init. d/nfs
Chkconfig:-30 60
Sixth history: Check NFS service configuration and local test mounting
# Showmount-e
# Df-h
# Cd/mnt
# Echo "momoda"> oldoy.txt
# Ll
Total 4
-Rw-r -- 1 nfsnobody 7 Aug 31 10:57 oldoy.txt
# Cd/data
# Cat oldboy.txt
Momoda
What the web server does
First Track: Check whether the nfs rpc service software is installed
Rpm-qa | grep nfs
Rpm-qa | grep rpc
Note: nfs and rpc service software is not installed in centos by default.
The second milestone: Installing nfs and rpc service software in yum
Yum install-y nfs-utils rpcbind
The third historical monument: checks whether shared directories exist and mounts shared directories.
# Showmount-e 172.16.1.31
Mount-t nfs 172.16.1.31:/data/mnt
Df-h
Rsync server
First milestone: Check whether this software is available
# Rpm-qa rsync
Second milestone: Installing rsync Software
# Yum install-y rsync
The third milestone: Compile the configuration file (compile the configuration file and follow the configuration file for subsequent steps)
# Cat>/etc/rsyncd. conf <EOF
# Created by HQ 2017
# Rsyncd. conf start ##
Uid = rsync
Gid = rsync
Use chroot = no
Max connections = 200
Timeout = 300
Pid file =/var/run/rsyncd. pid
Lock file =/var/run/rsync. lock
Log file =/var/log/rsyncd. log
Ignore errors
Read only = false
List = false
Hosts allow = 172.16.1.0/24
Hosts deny = 0.0.0.0/32
Auth users = rsync_backup
Secrets file =/etc/rsync. password
[Backup]
Comment = "backup dir by oldboy"
Path =/backup
EOF
The fourth historical monument: management users who create backup directories
Useradd-s/sbin/nologin-M rsync
Step 5: create security authentication documents
Echo "rsync_backup: oldboy123">/etc/rsync. password
Chmod 600/etc/rsync. password
Sixth history: creating a backup directory
Mkdir-p/backup
Chown-R rsync. rsync/backup
The seventh milestone: starting the rsync Service
Rsync -- daemon
NFS server
2.5.3 client deployment
First milestone: Check whether this software is available
Rpm-qa rsync
Second milestone: Installing rsync Software
Yum install-y rsync
Third milestone: Creating Security Authentication Files
Echo "oldboy123">/etc/rsync. password
Chmod 600/etc/rsync. password
Test 4
Rsync-avz/etc rsync_backup@172.16.1.41: backup
Inotify Server:
Deploy and install inotify-tools software
Yum install-y inotify-tools
Rpm-ql inotify-tools
Third milestone: Writing inotify + rsync combined with scripts
[Root @ nfs01 server] # cd/server/scripts
[Root @ nfs01 scripts] # vim tongbu. sh
#! /Bin/bash
###########
Inotifywait-mrq/data -- format' % w % F'-e create, delete, close_write, moved_to | \
While read line
Do
Rsync-az -- delete/data/rsync_backup@172.16.1.41: backup -- password-file =/etc/rsync. password
Done
Sh tongbu. sh