rsync nfs web 的部署

落爺英雄遲暮 提交于 2019-11-27 16:39:38

rsync nfs web01

 

所有的服务,都需要经过:

1.下载

2.安装

3.配置

4.启动

 

部署rsync服务端(172.16.1.41)

1)安装rsync

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

2)配置rsync

[root@backup ~]# vim /etc/rsyncd.confuid = wwwgid = wwwport = 873fake super = yesuse chroot = nomax connections = 200timeout = 600ignore errorsread only = falselist = falseauth users = rsync_backupsecrets file = /etc/rsync.passwdlog file = /var/log/rsyncd.log#####################################[zhp]comment = welcome to oldboyedu backup!path = /backup​[nfs]comment = welcome to oldboyedu backup!path = /data

3)创建系统用户(www),为了和web nfs统一

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

4)创建虚拟的认证用户和密码文件并授权

[root@backup ~]# echo 'rsync_backup:123' > /etc/rsync.passwd[root@backup ~]# chmod 600 /etc/rsync.passwd

5)创建目录

[root@backup ~]# mkdir /backup /data[root@backup ~]# chown -R www.www /backup/ /data/#检查[root@backup ~]# ll -d /backup/ /data/drwxr-xr-x 2 www www 6 Aug  7 16:56 /backup/drwxr-xr-x 2 www www 6 Aug  7 16:56 /data/[root@backup backup]#  vim /etc/exports/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)[root@backup backup]# systemctl start rpcbind nfs-server[root@backup backup]# systemctl enable rpcbind nfs-server[root@backup backup]# cat /var/lib/nfs/etab [root@backup ~]# yum install -y nfs-utils rpcbind​​

6)启动rsync服务并加入开机自启

[root@backup ~]# systemctl start rsyncd[root@backup ~]# systemctl enable rsyncd

部署rsync客户端(172.16.1.31、172.16.1.7)

1)安装rsync

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

2)免密码方式

#方式一:[root@nfs ~]# echo '123' > /etc/rsync.pass[root@nfs ~]# chmod 600 /etc/rsync.pass​[root@web01 ~]# echo '123' > /etc/rsync.pass[root@web01 ~]# chmod 600 /etc/rsync.pass​[root@nfs ~]# rsync -avz /etc/passwd rsync_backup@172.16.1.41::zls --password-file=/etc/rsync.pass​#方式二(推荐):[root@nfs ~]# export RSYNC_PASSWORD=123[root@web01 ~]# export RSYNC_PASSWORD=123[root@nfs ~]# rsync -avz /etc/passwd rsync_backup@172.16.1.41::zls

部署web代码

1)安装httpd和php

[root@web01 ~]# yum install -y httpd php

2)创建用户

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

3)修改配置文件

[root@web01 ~]# vim /etc/httpd/conf/httpd.confUser wwwGroup www

4)启动httpd并加入开机自启

[root@web01 ~]# systemctl start httpd[root@web01 ~]# systemctl enable httpd#检查[root@web01 ~]# netstat -lntup|grep 80tcp6       0      0 :::80                   :::*                    LISTEN      10427/httpd#检查启动用户[root@web01 ~]# ps -ef|grep httpdroot      10427      1  0 17:09 ?        00:00:00 /usr/sbin/httpd -DFOREGROUNDwww       10428  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUNDwww       10429  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUNDwww       10430  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUNDwww       10431  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUNDwww       10432  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND

5)部署代码,将代码上传至httpd的站点目录

#查找站点目录[root@web01 ~]# rpm -ql httpd|grep html/var/www/html​#进入站点目录,上传代码[root@web01 ~]# cd /var/www/html/[root@web01 html]# rz windows-提交作业代码.zip​#安装unzip[root@web01 html]# yum install -y unzip​#解压代码[root@web01 html]# unzip windows-提交作业代码.zip Archive:  windows-提交作业代码.zip  inflating: 1.png                     inflating: 2.png                     inflating: 3.png                     inflating: bg.jpg                    inflating: index.html                inflating: info.php                  inflating: upload_file.php ​#授权[root@web01 html]# chown -R www.www /var/www/html/​#修改用户上传文件的目录[root@web01 html]# vim upload_file.php$wen="/var/www/html/upload";[root@web01 html]# ll upload/    发现图片传过来了​

打开浏览器访问:提交作业

 

 

NFS服务端部署

1)安装nfs和rpcbind

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

2)配置nfs

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

3)创建www用户(uid和gid是666的用户)

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

4)创建共享目录/data并授权

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

5)启动服务并加入开机自启

[root@nfs ~]# systemctl start rpcbind nfs-server[root@nfs ~]# systemctl enable rpcbind nfs-server

6)检查nfs

#检查文件[root@nfs ~]# cat /var/lib/nfs/etab /data   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)​#检查端口[root@nfs ~]# netstat -lntup|grep 111tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           udp        0      0 0.0.0.0:111             0.0.0.0:*                           1/systemd           udp6       0      0 :::111                  :::*                                1/systemd  #检查进程[root@nfs ~]# ps -ef|grep -E '(nfs|rpcbind)'rpc        8081      1  0 17:27 ?        00:00:00 /sbin/rpcbind -wroot       8140      2  0 17:27 ?        00:00:00 [nfsd4_callbacks]root       8146      2  0 17:27 ?        00:00:00 [nfsd]root       8147      2  0 17:27 ?        00:00:00 [nfsd]root       8148      2  0 17:27 ?        00:00:00 [nfsd]root       8149      2  0 17:27 ?        00:00:00 [nfsd]root       8150      2  0 17:27 ?        00:00:00 [nfsd]root       8151      2  0 17:27 ?        00:00:00 [nfsd]root       8152      2  0 17:27 ?        00:00:00 [nfsd]root       8153      2  0 17:27 ?        00:00:00 [nfsd]

 

部署nfs备胎服务端

1)安装nfs和rpcbind

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

2)配置nfs

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

3)启动服务并加入开机自启

[root@nfs ~]# systemctl start rpcbind nfs-server[root@nfs ~]# systemctl enable rpcbind nfs-server

4)检查nfs

#检查文件[root@nfs ~]# cat /var/lib/nfs/etab /data   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)​#检查端口[root@nfs ~]# netstat -lntup|grep 111tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           udp        0      0 0.0.0.0:111             0.0.0.0:*                           1/systemd           udp6       0      0 :::111                  :::*                                1/systemd  #检查进程[root@nfs ~]# ps -ef|grep -E '(nfs|rpcbind)'rpc        8081      1  0 17:27 ?        00:00:00 /sbin/rpcbind -wroot       8140      2  0 17:27 ?        00:00:00 [nfsd4_callbacks]root       8146      2  0 17:27 ?        00:00:00 [nfsd]root       8147      2  0 17:27 ?        00:00:00 [nfsd]root       8148      2  0 17:27 ?        00:00:00 [nfsd]root       8149      2  0 17:27 ?        00:00:00 [nfsd]root       8150      2  0 17:27 ?        00:00:00 [nfsd]root       8151      2  0 17:27 ?        00:00:00 [nfsd]root       8152      2  0 17:27 ?        00:00:00 [nfsd]root       8153      2  0 17:27 ?        00:00:00 [nfsd]

部署nfs的客户端web01

1)安装nfs和rpcbind

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

2)只启动rpcbind

[root@web01 ~]# systemctl start rpcbind[root@web01 ~]# systemctl enable rpcbind

3)查看可挂载点

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

4)挂载前,要保证数据一致

[root@web01 ~]# scp -r /var/www/html/upload/ 172.16.1.31:/data  (输密码的时候输那个root的密码)[root@nfs ~]# chown -R www.www /data/

5)挂载nfs的服务端

[root@web01 ~]# mount -t nfs 172.16.1.31:/data /var/www/html/upload

 

backup实时同步nfs的data目录

编写脚本

[root@backup ~]#  vim rsync.sh #!/bin/bash​PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin'H=`hostname`I=`ifconfig eth1|awk 'NR==2{print $2}'`D=`date +%F`S=${H}_${I}_${D}BD=/backupexport RSYNC_PASSWORD=123​mkdir -p ${BD}/${S}​tar zcf ${BD}/${S}/conf.tar.gz /etc/passwd &>/dev/null​md5sum ${BD}/${S}/conf.tar.gz  > /backup/${I}.txt​rsync -az ${BD}/ rsync_backup@172.16.1.41::zhpfind ${BD} -type d -mtime +7|xargs rm -fr

 

切换备胎backup

[root@web01 ~]# vim nfs.sh​#!/bin/bash​check_nfs=`df -h|grep '/var/www/html/tupian'|wc -l`if [ $check_nfs -eq 0 ];then        showmount -e 172.16.1.31 &>/dev/null        if [ $? -eq 0 ];then                mount -t nfs 172.16.1.31:/data /var/www/html/upload​        else                mount -t nfs 172.16.1.41:/data /var/www/html/upload​        fifi
[root@web01 ~]# sh nfs.sh[root@web01 ~]# df -hFilesystem         Size  Used Avail Use% Mounted on/dev/sda3           19G  1.4G   18G   8% /devtmpfs           476M     0  476M   0% /devtmpfs              487M     0  487M   0% /dev/shmtmpfs              487M  7.7M  479M   2% /runtmpfs              487M     0  487M   0% /sys/fs/cgroup/dev/sda1          497M  120M  378M  25% /boottmpfs               98M     0   98M   0% /run/user/0172.16.1.31:/data   19G  1.4G   18G   8% /var/www/html/upload[root@web01 ~]# umount -lf /var/www/html/upload[root@backup ~]# systemctl stop t nfs-server[root@nfs01 ~]# systemctl start nfs-server[root@web01 ~]# sh nfs.sh[root@web01 ~]# df -hFilesystem         Size  Used Avail Use% Mounted on/dev/sda3           19G  1.4G   18G   8% /devtmpfs           476M     0  476M   0% /devtmpfs              487M     0  487M   0% /dev/shmtmpfs              487M  7.7M  479M   2% /runtmpfs              487M     0  487M   0% /sys/fs/cgroup/dev/sda1          497M  120M  378M  25% /boottmpfs               98M     0   98M   0% /run/user/0172.16.1.31:/data   19G  1.4G   18G   8% /var/www/html/upload​​

 

 

 

 

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!