架构期day11-NFS+Rsync+Inotify+Nginx+php

一、回顾

1.搭建LNMP环境

#搭建nginx
1.配置yum源
2.安装nginx
3.配置nginx
4.创建用户
5.启动服务

#搭建php
1.上传服务包
2.解压包
3.安装本地rpm包
4.配置php
5.启动

#搭建mariadb
1.安装
2.启动
3.连接测试
4.设置数据库的用户名密码

2.搭建wordpress

1.配置nginx
2.创建站点目录
3.上传代码包
4.解压
5.授权代码
6.重启nginx
7.配置hosts访问测试
8.数据库建库
9.根据页面提示配置数据库信息
10.使用博客

二、搭建LNMP

1.配置官方源

[root@web01 ~]# cat /etc/yum.repos.d/nginx.repo 
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

2.yum安装nginx

[root@web01 ~]# yum install -y nginx

3.配置nginx

[root@web03 ~]# vim /etc/nginx/nginx.conf 
user  www;
...
http {
    client_max_body_size 200m;
}

4.创建用户

[root@web03 ~]# groupadd www -g 666
[root@web03 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M

5.启动

[root@web03 ~]# systemctl start nginx
[root@web03 ~]# systemctl enable nginx

6.上传php包

[root@web03 ~]# rz
[root@web03 ~]# ll
-rw-r--r--  1 root root 19889622 Nov 22 15:52 php.tar.gz

7.安装

[root@web03 ~]# tar xf php.tar.gz 
[root@web03 ~]# yum localinstall -y *.rpm

8.配置PHP

[root@web03 ~]# vim /etc/php-fpm.d/www.conf 
user = www
group = www

[root@web03 ~]# vim /etc/php.ini
upload_max_filesize = 200M
post_max_size = 200M

9.启动

[root@web03 ~]# systemctl start php-fpm
[root@web03 ~]# systemctl enable php-fpm

10.安装mariadb

[root@web03 ~]# yum install -y mariadb-server

11.启动

[root@web03 ~]# systemctl start mariadb
[root@web03 ~]# systemctl enable mariadb

12.设置数据库密码

[root@web03 ~]# mysqladmin -uroot password
New password: 123
Confirm new password: 123

13.使用密码连接数据库测试

[root@web03 ~]# mysql -uroot -p
Enter password: 123

三、搭建wordpress、知乎、edusoho

1.上传代码包

[root@web03 ~]# mkdir /code
[root@web03 ~]# cd /code/
[root@web03 code]# rz
[root@web03 code]# ll
total 86372
-rw-r--r-- 1 root root 68889387 Dec  1 09:07 edusoho-8.3.36.tar.gz
-rw-r--r-- 1 root root  8451194 Dec  1 09:07 WeCenter_3-2-1.zip
-rw-r--r-- 1 root root 11098483 Sep 12 17:52 wordpress-5.0.3-zh_CN.tar.gz

2.解压代码包

[root@web03 code]# tar xf edusoho-8.3.36.tar.gz
[root@web03 code]# tar xf wordpress-5.0.3-zh_CN.tar.gz
[root@web03 code]# unzip WeCenter_3-2-1.zip

[root@web03 code]# mv WeCenter_3-2-1 zhihu

[root@web03 code]# ll
drwxr-xr-x 10  501 games      115 Jul 18  2019 edusoho
drwxr-xr-x  5 1006  1006     4096 Jan 11  2019 wordpress
drwx------ 14 root root       296 Jun  4  2018 zhihu

3.授权代码

[root@web03 code]# chown -R www.www /code/

4.配置nginx

1)配置wordpress的nginx

[root@web03 ~]# vim /etc/nginx/conf.d/linux.wp.com.conf
server {
    listen 80;
    server_name linux.wp.com;

    location / {
        root /code/wordpress;
        index index.php;
    }

    location ~* \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /code/wordpress/$fastcgi_script_name;
        include fastcgi_params;
    }
}

2)配置知乎的nginx配置

[root@web03 ~]# vim /etc/nginx/conf.d/linux.zh.com.conf
server {
    listen 80;
    server_name linux.zh.com;
    root /code/zhihu;

    location / {
        index index.php;
    }

    location ~* \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

3)配置edusoho的nginx配置(代码有误,暂时不配)

[root@web03 ~]# vim /etc/nginx/conf.d/linux.edu.com.conf
server {
    listen 80;
    server_name linux.edu.com;
    root /code/edusoho/web;
    
    location / {
    	index app.php;
    	try_files $uri @rewriteapp;
    }
    location @rewriteapp {
    	rewrite ^(.*)$ /app.php/$1 last;
    }
    location ~ ^/udisk {
    	internal;
    	root /var/www/edusoho/app/data/;
    }
    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
        fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
        fastcgi_param HTTP_X-Accel-Mapping /udisk=/code/edusoho/app/data/udisk;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 8 128k;
    }
    # 配置设置图片格式文件
    location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {
    	# 过期时间为3年
    	expires 3y;
    	# 关闭日志记录
    	access_log off;
    	# 关闭gzip压缩,减少CPU消耗,因为图片的压缩率不高。
    	gzip off;
    }
    # 配置css/js文件
    location ~* \.(css|js)$ {
    	access_log off;
    	expires 3y;
    }
    # 禁止用户上传目录下所有.php文件的访问,提高安全性    
    location ~ ^/files/.*\.(php|php5)$ {
    	deny all;
    }
    # 以下配置允许运行.php的程序,方便于其他第三方系统的集成。
    location ~ \.php$ {
    	# [改] 请根据实际php-fpm运行的方式修改
    	fastcgi_pass 127.0.0.1:9000;
    	fastcgi_split_path_info ^(.+\.php)(/.*)$;
    	include fastcgi_params;
    	fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    	fastcgi_param HTTPS off;
    }
}

4)重启nginx

[root@web03 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web03 ~]# systemctl restart nginx

5.配置本地hosts访问测试

10.0.0.9 linux.wp.com linux.zh.com

10.0.0.9 linux.wp.com 
10.0.0.9 linux.zh.com

6.数据库建库

[root@web03 ~]# mysql -uroot -p
Enter password: 123

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create database zhihu;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| wordpress          |
| zhihu              |
+--------------------+
6 rows in set (0.00 sec)

7.创建数据库用户并授权

MariaDB [(none)]> grant all on wordpress.* to wp@'localhost' identified by '123';
Query OK, 0 rows affected (0.07 sec)

MariaDB [(none)]> grant all on zhihu.* to zh@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)

#查看用户
MariaDB [(none)]> select user,host from mysql.user;
+------+------------+
| user | host       |
+------+------------+
| wp   | localhost |
| zh   | localhost |
+------+------------+
8 rows in set (0.00 sec)

8.根据页面提示操作

四、拆分数据库

1.为什么要拆分

由于单台服务器运行LNMP架构会导致网站访问缓慢,当内存被占满时,很容易导致系统出现out of memory从而kill掉MySQL数据库,所以要将web和数据库进行独立部署。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-12hoYJtE-1606833675375)(C:\Users\Administrator.DESKTOP-7PQVV6E\AppData\Roaming\Typora\typora-user-images\1606790132560.png)]

2.数据库拆分后解决了什么问题

1.缓解web网站的压力
2.增强数据库读写性能
3.提高用户访问速度

3.环境准备

主机IP部署的服务
web0110.0.0.7,172.16.1.7nginx+php
db01172.16.1.51mariadb

4.在新的服务器上搭建数据库(盖新房子)

[root@db01 ~]# yum install -y mariadb-server

5.配置数据库密码(装修)

[root@db01 ~]# systemctl start mariadb
[root@db01 ~]# mysqladmin -uroot password
New password: 123
Confirm new password: 123

6.测试连接远程数据库(测试房子能不能住人)

不能住~~
[root@web01 ~]# mysql -uroot -p -h 172.16.1.51
Enter password: 
ERROR 1130 (HY000): Host '172.16.1.7' is not allowed to connect to this MariaDB server

mysql 			#数据库命令
-u				#指定用户
root 			#root用户
-p 				#使用数据库root用户的密码
123				#数据库root用户的密码
-h				#指定数据库的主机
172.16.1.51		#主机IP

7.db数据库端授权用户远程连接(想办法住,db端操作)

想办法住~~
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on wordpress.* to wp@'172.16.1.%' identified by '1';
Query OK, 0 rows affected (0.00 sec)

grant 				#数据库授权命令
all 				#所有权限
on					#在...上面
wordpress.* 		 #wordpress下面的所有表   库.表
to					#给...
wp@'172.16.1.%' 	 #数据库用户
identified			#设置密码
by 					#密码是...
'1qaz@WSX';			 #密码内容

8.再次测试连接(房子可以住了)

[root@web01 ~]# mysql -uwp -p -h 172.16.1.51
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
| wordpress          |
+--------------------+
3 rows in set (0.00 sec)

9.旧数据库导出数据(打包行李搬出房子)

[root@web01 ~]# mysqldump -uroot -p -B wordpress > /tmp/wp.sql
Enter password: 123
[root@web01 ~]# mysqldump -uroot -p -B zhihu > /tmp/zh.sql
Enter password: 123

10.将数据推送到新服务器(汽车运送行李)

[root@web01 ~]# scp /tmp/wp.sql 172.16.1.51:/tmp/
[root@web01 ~]# scp /tmp/zh.sql 172.16.1.51:/tmp/

11.将数据导入新数据库(将行李放入新房子)

1)库外导入

[root@db01 ~]# mysql -uroot -p < /tmp/wp.sql 
Enter password: 
[root@db01 ~]# mysql -uroot -p < /tmp/zh.sql 
Enter password: 

2)库内读取

MariaDB [wordpress]> source /tmp/wp.sql;
MariaDB [zhihu]> source /tmp/zh.sql;

3)任意门方式导数据

[root@web01 ~]# mysql -uwp -p -h 172.16.1.51 < /tmp/wp.sql 
Enter password: 1qaz@WSX
[root@web01 ~]# mysql -uwp -p -h 172.16.1.51 < /tmp/zh.sql 
Enter password: 1qaz@WSX

12.查看数据

MariaDB [(none)]> use wordpress;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [wordpress]> show tables;
+-----------------------+
| Tables_in_wordpress   |
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+
12 rows in set (0.00 sec)

13.修改项目中数据库地址(告知亲戚新家地址)

[root@web01 ~]# vim /code/wordpress/wp-config.php
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */
define('DB_USER', 'wp');

/** MySQL数据库密码 */
define('DB_PASSWORD', '1qaz@WSX');

/** MySQL主机 */
define('DB_HOST', '172.16.1.51');

[root@web03 ~]# vim /code/zhihu/system/config/database.php

14.停掉旧数据库(拆迁旧家)

[root@web01 ~]# systemctl stop mariadb

15.访问页面测试

http://linux.wp.com/

五、扩展web服务器

1.环境准备

主机IP部署服务
web0110.0.0.7,172.16.1.7nginx+php
web0210.0.0.8,172.16.1.8nginx+php
db01172.16.1.51mariadb

2.web02搭建nginx

1)配置官方源

[root@web01 ~]# scp /etc/yum.repos.d/nginx.repo 172.16.1.8:/etc/yum.repos.d/

2)安装nginx

[root@web02 ~]# yum install -y nginx

3)创建用户

[root@web02 ~]# groupadd www -g 666
[root@web02 ~]# useradd www -u 666 -g 666

4)上传php包

[root@web02 ~]# rz

5)解压安装php

[root@web02 ~]# tar xf php.tar.gz 
[root@web02 ~]# yum localinstall -y *.rpm

6)同步web01的配置文件到web02

#同步nginx配置文件
[root@web01 ~]# scp /etc/nginx/nginx.conf 172.16.1.8:/etc/nginx/ 
[root@web01 ~]# scp /etc/nginx/conf.d/linux.wp.com.conf 172.16.1.8:/etc/nginx/conf.d/

#同步php的配置
[root@web01 ~]# scp /etc/php-fpm.d/www.conf 172.16.1.8:/etc/php-fpm.d/ 
[root@web01 ~]# scp /etc/php.ini 172.16.1.8:/etc/

7)启动nginx和php服务

[root@web02 ~]# systemctl start nginx
[root@web02 ~]# systemctl enable nginx
[root@web02 ~]# systemctl start php-fpm
[root@web02 ~]# systemctl enable php-fpm

8)推送web01站点目录到web02

[root@web01 ~]# scp -r /code 172.16.1.8:/

9)授权站点目录

[root@web02 ~]# chown -R www.www /code/

10)修改本地hosts访问测试

#10.0.0.7 linux.wp.com
10.0.0.8 linux.wp.com

六、搭建文件共享

1.环境准备

主机IP部署服务
web0110.0.0.7nginx+php
web0210.0.0.8nginx+php
db01172.16.1.51mariadb
nfs172.16.1.31nfs

2.搭建NFS服务器

1)安装nfs

[root@nfs ~]# yum install -y nfs-utils

2)创建挂载目录

[root@nfs ~]# mkdir /data/wp -p

3)配置NFS

[root@nfs ~]# vim /etc/exports
/data/wp 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

4)创建用户

5)授权

[root@nfs ~]# chown -R www.www /data/

6)启动NFS

[root@nfs ~]# systemctl start nfs

7)检查配置

[root@nfs ~]# cat /var/lib/nfs/etab 
/data/wp	172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)

3.配置客户端

1)安装nfs和rpcbind

[root@web01 ~]# yum install -y nfs-utils rpcbind

2)启动rpcbind

3)查看挂载点

[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data/wp 172.16.1.0/24

4)确定挂载目录

[root@web01 ~]# ll /code/wordpress/wp-content/uploads/

5)先推送挂载目录下的文件

[root@web01 ~]# rsync -avz /code/wordpress/wp-content/uploads/ 172.16.1.31:/data/wp/
[root@web02 ~]# rsync -avz /code/wordpress/wp-content/uploads/ 172.16.1.31:/data/wp/

#验证文件
[root@nfs ~]# ll /data/wp/2020/12/

6)挂载

[root@web01 ~]# mount -t nfs 172.16.1.31:/data/wp /code/wordpress/wp-content/uploads
[root@web02 ~]# mount -t nfs 172.16.1.31:/data/wp /code/wordpress/wp-content/uploads

七、实时备份

作业:

1.恢复快照
2.搭建lnmp架构
3.搭建博客与知乎
4.两台web服务器实现文件同步
5.nfs文件实时备份到backup

题目:
1.搭建lnmp架构
2.搭建博客与知乎
3.两台web服务器实现文件同步
4.nfs文件实时备份到backup

解:
一、web01与web02客户端操作
1.安装nginx和PHP服务
(1)配置官方源
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
(2)yum安装nginx
[root@web01 ~]# yum install -y nginx
(3)配置nginx
[root@web01 ~]# vim /etc/nginx/nginx.conf
user www;

http {
client_max_body_size 200m;
}
(4)创建用户
[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
(5)启动
[root@web01 ~]# systemctl start nginx
[root@web01 ~]# systemctl enable nginx #开机自启动
(6)上传php包
[root@web01 ~]# rz
[root@web01 ~]# ll
-rw-r–r-- 1 root root 19889622 Nov 22 15:52 php.tar.gz
(7)安装
[root@web01 ~]# tar xf php.tar.gz
[root@web01 ~]# yum localinstall -y *.rpm
(8)配置PHP
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
user = www
group = www

[root@web01 ~]# vim /etc/php.ini
upload_max_filesize = 200M
post_max_size = 200M
(9)启动
[root@web01 ~]# systemctl start php-fpm
[root@web01 ~]# systemctl enable php-fpm #开机自启动
2.搭建wordpress、知乎
(1)上传代码包
[root@web01 ~]# mkdir /code
[root@web01 ~]# cd /code/
[root@web01 code]# rz
[root@web01 code]# ll
total 86372
-rw-r–r-- 1 root root 8451194 Dec 1 09:07 WeCenter_3-2-1.zip
-rw-r–r-- 1 root root 11098483 Sep 12 17:52 wordpress-5.0.3-zh_CN.tar.gz
(2)解压代码包
[root@web01 code]# tar xf wordpress-5.0.3-zh_CN.tar.gz
[root@web01 code]# unzip WeCenter_3-2-1.zip

[root@web01 code]# mv WeCenter_3-2-1 zhihu

[root@web01 code]# ll
drwxr-xr-x 5 1006 1006 4096 Jan 11 2019 wordpress
drwx------ 14 root root 296 Jun 4 2018 zhihu
(3)授权代码
[root@web01 code]# chown -R www.www /code/
(4)配置wordpress的nginx
[root@web01 ~]# vim /etc/nginx/conf.d/linux.wp.com.conf
server {
listen 80;
server_name linux.wp.com;

location / {
    root /code/wordpress;
    index index.php;
}

location ~* \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME /code/wordpress/$fastcgi_script_name;
    include fastcgi_params;
}

}
(5)配置知乎的nginx配置
[root@web03 ~]# vim /etc/nginx/conf.d/linux.zh.com.conf
server {
listen 80;
server_name linux.zh.com;
root /code/zhihu;

location / {
    index index.php;
}

location ~* \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

}
(6)重启nginx
[root@web03 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web03 ~]# systemctl restart nginx
(7)配置本地hosts访问测试
10.0.0.7 linux.zh.com linux.wp.com
10.0.0.8 linux.zh.com linux.wp.com

二、db01 mariadb数据库服务端操作
1.安装 mariadb
[root@db01 ~]# yum install -y mariadb-server
2.启动
[root@db01 ~]# systemctl start mariadb
[root@db01 ~]# systemctl enable mariadb
3.设置数据库密码
[root@db01 ~]# mysqladmin -uroot password
New password: 123
Confirm new password: 123
4.使用密码连接数据库测试
[root@db01 ~]# mysql -uroot -p
Enter password: 123
5.查看数据库
MariaDB [(none)]> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
±-------------------+
6.数据库建库
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create database zhihu;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
±-------------------+
| Database           |
±-------------------+
| information_schema |
| mysql             |
| performance_schema |
| test               |
| wordpress         |
| zhihu             |
±-------------------+
6 rows in set (0.00 sec)
7.创建数据库用户并授权
MariaDB [(none)]> grant all on wordpress.* to wp@‘172.16.1.%’ identified by ‘123’;
Query OK, 0 rows affected (0.07 sec)

MariaDB [(none)]> grant all on zhihu.* to zh@‘172.16.1.%’ identified by ‘123’;
Query OK, 0 rows affected (0.00 sec)

#查看用户
MariaDB [(none)]> select user,host from mysql.user;
±-----±-----------+
| user | host |
±-----±-----------+
| root | 127.0.0.1 |
| wp | 172.16.1.% |
| zh | 172.16.1.% |
| root | ::1 |
| | db01 |
| root | db01 |
| | localhost |
| root | localhost |
| wp | localhost |
| zh | localhost |
±-----±-----------+
10 rows in set (0.00 sec)
8.浏览器搜索:linux.zh.com.install 或 linux.wp.com ===》根据页面提示操作

三、Nfs服务端共享操作
(1)关闭防火墙和selinux
(2)安装NFS
[root@nfs ~]# yum install -y nfs-utils
(3)创建挂载目录
[root@nfs ~]# mkdir /data/wp -p
(4)配置NFS
[root@nfs ~]# vim /etc/exports
/data/wp 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/zh 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
(5)创建用户
[root@nfs ~]# groupadd www -g 666
[root@nfs ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
(6)授权与启动nfs
[root@nfs ~]# chown -R www.www /data
[root@nfs ~]# systemctl start nfs
(7)检查配置
[root@nfs ~]# cat /var/lib/nfs/etab
/data/zh 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)
/data/wp 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)

四、web01与web02客户端挂载到NFS
(1)安装nfs和rpcbind
[root@web01 ~]# yum install -y nfs-utils rpcbind
(2)启动nfs、rpcbind
[root@web01 ~]# systemctl start nfs rpcbind
(3)查看挂载点
[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data/wp 172.16.1.0/24
(4)确定挂载目录
[root@web01 ~]# ll /code/wordpress/wp-content/uploads/
(5)先推送挂载目录下的文件
[root@web01 ~]# rsync -avz /code/wordpress/wp-content/uploads/ 172.16.1.31:/data/wp/
[root@web02 ~]# rsync -avz /code/wordpress/wp-content/uploads/ 172.16.1.31:/data/wp/

#验证文件
[root@nfs ~]# ll /data/wp/2020/12/
(6)挂载
[root@web01 ~]# mount -t nfs 172.16.1.31:/data/wp /code/wordpress/wp-content/uploads
[root@web02 ~]# mount -t nfs 172.16.1.31:/data/wp /code/wordpress/wp-content/uploads
(7) 检查挂载
[root@web01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 1.7G 17G 10% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 119M 896M 12% /boot
tmpfs 98M 0 98M 0% /run/user/0
172.16.1.31:/data/wp 18G 1.3G 17G 8% /code/wordpress/wp-content/uploads
172.16.1.31:/data/zh 18G 1.3G 17G 8% /code/zhihu/uploads

五、backup服务端配置rsync实时备份
(1)安装inotify-tools、rsync
[root@backup ~]# yum install -y rsync
(2)修改rsync配置文件
[root@backup ~]# vim /etc/rsyncd.conf
uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = true
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
#####################################
[web_data]
comment = “该备份文件是web端挂载到nfs服务器的文件”
path = /data
(3)创建用户、修改权限
[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
[root@backup ~]# chmod 600 /etc/rsync.passwd
(4)创建共享目录、授权
[root@backup ~]# mkdir /data
[root@backup ~]# chown -R www.www /data
(5)启动rsync服务
[root@backup ~]# systemctl start rsyncd

六、NFS配置rsync实时备份
(1)下载inotify-tools
[root@nfs ~]# yum install -y inotify-tools
(2)编写实时备份脚本

posted @ 2022-06-09 18:19  秋风お亦冷  阅读(49)  评论(0编辑  收藏  举报