rsync nfs web01總結

rsync nfs web01總結

要求

1.部署rsync服務端,部署rsync客戶端(web01,nfs)html

配合腳本,天天凌晨1點作備份git

2.部署上傳做業的代碼(嘗試)github

3.部署nfs服務端(nfs,backup)部署nfs客戶端(web01)web

4.部署sersync,給nfs的共享存儲目錄,實時同步到backup服務器(解決單點故障)express

全部的服務,都須要通過:apache

1.下載vim

2.安裝windows

3.配置瀏覽器

4.啓動

部署rsync服務端(172.16.1.41)

1)安裝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 = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
#####################################
[zls]
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/

6)啓動rsync服務並加入開機自啓

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

部署rsync客戶端(172.16.1.3一、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.conf
User www
Group www

4)啓動httpd並加入開機自啓

[root@web01 ~]# systemctl start httpd
[root@web01 ~]# systemctl enable httpd
#檢查
[root@web01 ~]# netstat -lntup|grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      10427/httpd
#檢查啓動用戶
[root@web01 ~]# ps -ef|grep httpd
root      10427      1  0 17:09 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
www       10428  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
www       10429  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
www       10430  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
www       10431  10427  0 17:10 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
www       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";

打開瀏覽器訪問:提交做業

1565173908142

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 111
tcp        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 -w
root       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 111
tcp        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 -w
root       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.31
Export list for 172.16.1.31:
/data 172.16.1.0/24

[root@web01 ~]# showmount -e 172.16.1.41
Export 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@nfs ~]# chown -R www.www /data/

5)掛載nfs的服務端

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

在nfs下:backup實時同步nfs的data目錄:

1.編寫腳本

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=/backup
export 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::zls
find ${BD} -type d -mtime +7|xargs rm -fr

2.客戶端天天凌晨1點定時執行該腳本

[root@web01 ~]# crontab -e
#天天凌晨一點備份重要數據 By:zls  At:2019-08-02
00 01 * * * /bin/sh /root/rsync.sh &>/dev/null

#腳本中需加入,以防定時任務時。目錄中缺乏ip
[root@web01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin


#驗證
yum -y install nptdate
ntpdate time1.aliyun.com
date -s 20190803
[root@web01 ~]# tail -f /var/log/cron #查看

backup服務端需求

1.服務端部署rsync,用於接收客戶端推送過來的備份數據
2.服務端須要天天校驗客戶端推送過來的數據是否完整
3.服務端須要天天校驗的結果通知給管理員

#安裝mailx
yum install -y mailx

#配置mail.rc
vim /etc/mail.rc

Shift + g

set from=123@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=123@qq.com
set smtp-auth-password=受權碼
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/

#檢測下郵箱是否通
mail -s "rsync check $DATE" ***@qq.com </etc/passwd

4.服務端僅保留6個月的備份數據,其他的所有刪除

vim check_md5.sh
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
H=`hostname`
IP=`ifconfig eth1|awk 'NR==2{print $2}'`
DATE=`date +%F`
SRC=${H}_${IP}_${DATE}

md5sum -c /backup/res/*|mail -s "${DATE} check backup" 133411023@qq.com

find /backup -type d -mtime +180|xargs rm -fr
crontab -e
#xxx by:zls at:xx
01 00 * * * /bin/sh /root/check_md5.sh &>/dev/null
 
驗證

在客戶端web01下面執行,切換備胎backup,

解決單點故障腳本,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/tupian
        else
                mount -t nfs 172.16.1.41:/data /var/www/html/tupian
        fi
fi
注意:腳本有問題,先umount,在切換服務,驗證,執行sh nfs.sh

sersync項目實戰,達到實時同步的要求

環境準備

角色 外網IP(NAT) 內網IP(LAN) 安裝工具
web01 eth0:10.0.0.7 eth1:172.16.1.7 部署代碼(提交做業)
nfs-server eth0:10.0.0.31 eth1:172.16.1.31 rsync+inotify+sersync
backup eth0:10.0.0.41 eth1:172.16.1.41 rsync-server

1.實時同步哪臺服務器的目錄,那麼就在哪臺服務器上安裝sersync

2.只要安裝sersync 就必須安裝rsyncinotify

安裝rsync的服務端(backup)

1)安裝rsync服務

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

2)配置文件

[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 = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
#####################################
[zls]
comment = welcome to oldboyedu backup!
path = /backup

[nfs]
comment = welcome to oldboyedu backup!
path = /data

3)建立用戶

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

4)建立目錄並受權

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

5)建立虛擬用戶的密碼文件並受權

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

6)啓動rsync服務

[root@backup ~]# systemctl start rsyncd

NFS服務端部署sersync

1)安裝sersync須要依賴rsyncinotify

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

2)下載sersync

[root@nfs ~]# wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz

3)部署sersync

​ 源碼包:解壓 生成 編譯 安裝

​ 解壓:

[root@nfs ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz

4)移動並更名

[root@nfs ~]# mv GNU-Linux-x86 /usr/local/sersync

5)編輯配置文件

[root@nfs ~]# vim /usr/local/sersync/confxml.xml
    <inotify>
        <delete start="true"/>
        <createFolder start="true"/>
        <createFile start="true"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="true"/>
        <modify start="true"/>
    </inotify>
-----------------------------------------------------------------------------------------
    <sersync>
        #監控的目錄,改爲/data
        <localpath watch="/opt/tongbu">
            #推送的IP(backup服務的IP)172.16.1.41 ,name是模塊名
            <remote ip="127.0.0.1" name="tongbu1"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            #執行rsync的參數改爲 -az
            <commonParams params="-artuz"/>
            #虛擬用戶的用戶名和密碼文件,開啓認證start=true  rsync_backup    /etc/rsync.passwd
            <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            #設置超時時間
            <timeout start="true" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
        </rsync>
        <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
        <crontab start="false" schedule="600"><!--600mins-->
            <crontabfilter start="false">
                <exclude expression="*.php"></exclude>
                <exclude expression="info/*"></exclude>
            </crontabfilter>
        </crontab>
        <plugin start="false" name="command"/>
    </sersync>


#完整配置文件
[root@nfs ~]# cat /usr/local/sersync/confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="false"/>
    <fileSystem xfs="false"/>
    <filter start="false">
    <exclude expression="(.*)\.svn"></exclude>
    <exclude expression="(.*)\.gz"></exclude>
    <exclude expression="^info/*"></exclude>
    <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="true"/>
    <modify start="true"/>
    </inotify>

    <sersync>
    <localpath watch="/data">
        <remote ip="172.16.1.41" name="nfs"/>
        <!--<remote ip="192.168.8.39" name="tongbu"/>-->
        <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    </localpath>
    <rsync>
        <commonParams params="-az"/>
        <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.pass"/>
        <userDefinedPort start="false" port="874"/><!-- port=874 -->
        <timeout start="true" time="100"/><!-- timeout=100 -->
        <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    <crontab start="false" schedule="600"><!--600mins-->
        <crontabfilter start="false">
        <exclude expression="*.php"></exclude>
        <exclude expression="info/*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/>
    </sersync>

    <plugin name="command">
    <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->
    <filter start="false">
        <include expression="(.*)\.php"/>
        <include expression="(.*)\.sh"/>
    </filter>
    </plugin>

    <plugin name="socket">
    <localpath watch="/opt/tongbu">
        <deshost ip="192.168.138.20" port="8009"/>
    </localpath>
    </plugin>
    <plugin name="refreshCDN">
    <localpath watch="/data0/htdocs/cms.xoyo.com/site/">
        <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
        <sendurl base="http://pic.xoyo.com/cms"/>
        <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
    </localpath>
    </plugin>
</head>

6)建立虛擬用戶的密碼文件,並受權

[root@nfs sersync]# echo '123' > /etc/rsync.passwd
[root@nfs sersync]# chmod 600 /etc/rsync.passwd

7)查看幫助

[root@nfs sersync]# /usr/local/sersync/sersync2 -h
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
_______________________________________________________
參數-d:啓用守護進程模式
參數-r:在監控前,將監控目錄與遠程主機用rsync命令推送一遍
c參數-n: 指定開啓守護線程的數量,默認爲10個
參數-o:指定配置文件,默認使用confxml.xml文件
參數-m:單獨啓用其餘模塊,使用 -m refreshCDN 開啓刷新CDN模塊
參數-m:單獨啓用其餘模塊,使用 -m socket 開啓socket模塊
參數-m:單獨啓用其餘模塊,使用 -m http 開啓http模塊
不加-m參數,則默認執行同步程序
________________________________________________________________

8)啓動sersync

[root@nfs data]# /usr/local/sersync/sersync2 -rdo /usr/local/sersync/confxml.xml

9)達到效果,上傳圖片web01,當前掛載共享目錄nfs下的/data,查看/data下是否有圖片,在查看備份backup下/data,有無圖片,如有,則OK,不然有問題,從新排錯,密碼文件保持一致

單獨實現實時同步

1)安裝sersync(rsync+inotify)

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

2)安裝sersync

下載:

[root@nfs ~]# wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz

解壓:

[root@nfs ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz

移動並更名:

[root@nfs ~]# mv GNU-Linux-x86 /usr/local/sersync

3)修改配置文件

[root@nfs ~]# vim /usr/local/sersync/confxml.xml
    <inotify>
        <delete start="true"/>
        <createFolder start="true"/>
        <createFile start="true"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="true"/>
        <modify start="true"/>
    </inotify>

    <sersync>
        <localpath watch="/zls">
            <remote ip="172.16.1.41" name="zls"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-az"/>
            <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.pas"/>
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <timeout start="true" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
        </rsync>

4)建立目錄

[root@nfs ~]# mkdir /zls

5)建立密碼文件並受權

[root@nfs ~]# echo '123' > /etc/rsync.pas
[root@nfs ~]# chmod 600 /etc/rsync.pas

6)啓動sersync

[root@nfs ~]# /usr/local/sersync/sersync2 -rdo /usr/local/sersync/confxml.xml

sersync 就是rsync的客戶端

底層調用:rsync和inotify

一鍵部署rsync,nfs,seraync,web

準備環境

主機名 做用 外網IP 內網IP
web01 客戶端 10.0.0.7 172.16.1.7
backup 服務端 10.0.0.41 172.16.1.41
nfs 共享存儲 10.0.0.31 172.16.1.31
m01 遠程管理 10.0.0.61 172.0.0.61

m01下建立目錄 /scripts/http_file,rsync_file,sersync_file,配置文件

[root@m01 scripts]# ll httpd_file/
total 412
-rw-r--r-- 1 root root   1245 Aug 13 01:10 upload_file.php
-rw-r--r-- 1 root root 413973 Aug  5 14:23 windows-提交做業代碼.zip

[root@m01 scripts]# ll rsync_file/
total 4
-rw-r--r-- 1 root root 393 Aug 13 04:56 rsyncd.conf

[root@m01 scripts]# ll sersync_file/
total 716
drwxr-xr-x 2 root root     41 Oct 26  2011 GNU-Linux-x86
-rw-r--r-- 1 root root 727290 Aug  7 11:42 sersync2.5.4_64bit_binary_stable_final.tar.gz
-rw-r--r-- 1 root root   2209 Aug 13 04:22 sersync_server
#!/bin/bash
for IP in 31 41 7;do
        ssh 172.16.1.$IP 'yum install -y rsync rpcbind nfs-utils httpd php unzip inotify-tools'
        ssh 172.16.1.$IP 'groupadd www -g 666 && useradd www -u 666 -g 666 -s /sbin/nologin -M'
done
#--------------------------------部署rsync和nfs服務端---------------------
scp /scripts/rsync_file/rsyncd.conf  172.16.1.41:/etc/rsyncd.conf
ssh 172.16.1.41 'mkdir -p /{backup,data} && chown -R www.www /backup /data'
ssh 172.16.1.41 'echo rsync_backup:123 > /etc/rsync.passwd && chmod 600 /etc/rsync.passwd'
ssh 172.16.1.41 'echo "/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" >/etc/exports'
ssh 172.16.1.41 'systemctl start rsyncd rpcbind nfs-server && systemctl enable rsyncd rpcbind nfs-server'


#--------------------------------部署nfs和sersync服務端---------------------------
ssh 172.16.1.31 'echo "/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" > /etc/exports'
ssh 172.16.1.31 'mkdir -p /data && chown www.www -R /data'
ssh 172.16.1.31 'systemctl start rpcbind nfs-server && systemctl enable rpcbind nfs-utils'
scp /scripts/sersync_file/sersync2.5.4_64bit_binary_stable_final.tar.gz 172.16.1.31:/root
ssh 172.16.1.31 'tar xf /root/sersync2.5.4_64bit_binary_stable_final.tar.gz'
ssh 172.16.1.31 'mv /root/GNU-Linux-x86 /usr/local/sersync'
scp /scripts/sersync_file/sersync_server 172.16.1.31:/usr/local/sersync/confxml.xml
ssh 172.16.1.31 'echo 123 > /etc/rsync.passwd && chmod 600 /etc/rsync.passwd'

#----------------------------------部署web服務端-------------------------------------
scp /scripts/httpd_file/windows-提交做業代碼.zip 172.16.1.7:/var/www/html && ssh 172.16.1.7 'cd /var/www/html/ && unzip windows-提交做業代碼.zip' && scp /scripts/httpd_file/upload_file.php 172.16.1.7:/var/www/html
ssh 172.16.1.7 'sed -i "s#User apache#User www#g" /etc/httpd/conf/httpd.conf'
ssh 172.16.1.7 'sed -i "s#Group apache#Group www#g" /etc/httpd/conf/httpd.conf'
ssh 172.16.1.7 'chown -R www.www /var/www/html'
ssh 172.16.1.7 'systemctl start httpd'
ssh 172.16.1.7 'showmount -e 172.16.1.31' >/dev/null
if [ $? -eq 0 ];then
        ssh 172.16.1.7 'mount -t nfs 172.16.1.31:/data /var/www/html/upload'
fi

ssh 172.16.1.31 '/usr/local/sersync/sersync2 -rdo /usr/local/sersync/confxml.xml'&
相關文章
相關標籤/搜索