WEB服务器:
文件目录:/var/www/html
[root@web-server ~]#hostnamectl set-hostname web-server
[root@web-server ~]#yum install -y httpd php-fpm php-mysqlnd php-xml mysql-server -y
[root@web-server ~]#systemctl enable --now httpd php-fpm mysqld
[root@web-server ~]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 216
Server version: 8.0.21 Source distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database ultrax;
mysql> create user forum@'10.0.0.%' identified by 'magedu';
mysql> grant all on ultrax.* to forum@'10.0.0.%';
NFS服务器:
[root@nfs-server ~]#hostnamectl set-hostname nfs-server
[root@nfs-server ~]#mkdir /data/www
[root@nfs-server ~]#yum install nfs-utils -y
[root@nfs-server ~]#cat /etc/exports.d/web.exports
/data/web 10.0.0.0/24(rw,anonuid=48,anongid=48)
[root@nfs-server ~]#useradd -r -s /sbin/nologin -u 48 -M apache
[root@nfs-server ~]#chown -R apache.apache /data/web/
WEB服务器:
[root@web-server data]#cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Jan 6 00:05:43 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=577a4610-ee57-490d-be22-975e04962f9c / xfs defaults 0 0
UUID=21d7b90e-29ea-464a-9cfb-0c2e2c5672a8 /boot ext4 defaults 1 2
UUID=f4114d45-41ee-4c30-aa50-c872f4a285b2 /data xfs defaults 0 0
UUID=2d8f82ae-3bae-4770-8eef-e2de05c5773c swap swap defaults 0 0
10.0.0.7:/data/web /var/www/html nfs defaults 0 0
备份服务器:
[root@backup-server ~]#hostnamectl set-hostname backup-server
[root@backup-server ~]#yum install rsync -y
[root@backup-server ~]#cat /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = root
gid = root
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
[backup]
comment = backup dir
path = /data/backup
read only = no
auth users = rsyncuser
secrets file = /etc/rsync.pas
# [ftp]
# path = /home/ftp
# comment = ftp export area
[root@backup-server ~]#mkdir -pv /data/backup
[root@backup-server ~]#echo 'rsyncuser:magedu' > /etc/rsync.pas
[root@backup-server ~]#chmod 600 /etc/rsync.pas
[root@backup-server ~]#systemctl start rsyncd
NFS服务器:
[root@nfs-server ~]#yum install rsync -y
[root@nfs-server ~]#rsync rsync://10.0.0.7
[root@nfs-server ~]#rsync rsync://10.0.0.7/backup
[root@nfs-server ~]#echo "magedu" > /etc/rsync.pas
[root@nfs-server ~]#chmod 600 /etc/rsync.pas
[root@nfs-server ~]#yum install -y inotify-tools
[root@nfs-server ~]#cat inotify_rsync.sh
#!/bin/bash
SRC='/data/web/'
DEST='rsyncuser@10.0.0.7::backup'
rpm -q rsync &> /dev/null || yum -y install rsync
inotifywait -mrq --exclude=".*\.swp" --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %w %f' -e create,delete,moved_to,close_write,attrib ${SRC} |while read DATE TIME DIR FILE;do
FILEPATH=${DIR}${FILE}
rsync -az --delete --password-file=/etc/rsync.pas $SRC $DEST && echo "At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync" >> /var/log/changelist.log
done
[root@nfs-server ~]#bash inotify_rsync.sh