sersync+rsync同步

Server B (備份服務器)

#!/bin/bash
#====================================================
# Author: Mr.Song
# Create Date: 2019-03-03
# Description:install rsync server
#====================================================
#創建備份目錄
mkdir  -p /app/data/site/
#安裝rsync
yum install -y rsync

#設置rsync的配置文件
mv  /etc/rsyncd.conf  /etc/rsyncd.conf.bak
cat > /etc/rsyncd.conf <<- EOF

#服務器B上的rsyncd.conf文件內容
uid=root
gid=root
#最大連接數
max connections=36000
#默認爲true,修改爲no,增加對目錄文件軟連接的備份 
use chroot=no
#定義日誌存放位置
log file=/var/log/rsyncd.log
#忽略無關錯誤
ignore errors = yes
#設置rsync服務端文件爲讀寫權限
read only = no 
#認證的用戶名與系統帳戶無關在認證文件做配置,如果沒有這行則表明是匿名
auth users = rsync
#密碼認證文件,格式(虛擬用戶名:密碼)
secrets file = /etc/rsync.pass
#這裏是認證的模塊名,在client端需要指定,可以設置多個模塊和路徑
[rsync]
#自定義註釋
comment  = rsync
#同步到B服務器的文件存放的路徑
path=/app/data/site/
#[img]
#comment  = img
#path=/app/data/site/img
EOF

#創建rsync認證文件  可以設置多個,每行一個用戶名:密碼,注意中間以“:”分割
echo "rsync:rsync" > /etc/rsync.pass

#設置文件所有者讀取、寫入權限
chmod 600 /etc/rsyncd.conf /etc/rsync.pass 
#啓動服務器B上的rsync服務
systemctl start rsyncd

#設置rsync爲服務啓動項
systemctl enable rsyncd

Server A (源服務器)

#!/bin/bash
#====================================================
# Author: Mr.Song
# Create Date: 2019-03-03
# Description:install sersync+rsync server
#====================================================
APP_INSTALL_DIR="/app/local"
BAK_DIR="/app/data"
BACK_SERVER="192.168.10.12"
SRC_BAK_DIR="/home"
yum install -y automake autoconf libtool git rsync

mkdir -p $APP_INSTALL_DIR && cd $APP_INSTALL_DIR

#下載軟件包
git clone https://github.com/wsgzao/sersync.git && mv $APP_INSTALL_DIR/sersync $APP_INSTALL_DIR/sersync-git
#cd  $APP_INSTALL_DIR/sersync-git

#安裝inotify
#tar  zxf inotify-tools-3.14.tar.gz
#cd inotify-tools-3.14
#./configure --prefix=/app/local/inotify
#make && make install

#安裝sersync
cd  $APP_INSTALL_DIR
tar zxf $APP_INSTALL_DIR/sersync-git/sersync2.5.4_64bit_binary_stable_final.tar.gz -C $APP_INSTALL_DIR

mv $APP_INSTALL_DIR/GNU-Linux-x86/ $APP_INSTALL_DIR/sersync
cd $APP_INSTALL_DIR/sersync
#配置下密碼文件,因爲這個密碼是要訪問服務器B需要的密碼和上面服務器B的密碼必須一致
echo "rsync" > $APP_INSTALL_DIR/sersync/user.pass
#修改權限
chmod 600 $APP_INSTALL_DIR/sersync/user.pass
#修改confxml.conf
sed -i "24s#/opt/tongbu#$SRC_BAK_DIR#;s#127.0.0.1#$BACK_SERVER#;s#tongbu1#rsync#;s#/etc/rsync.pas#/app/local/sersync/user.pass#;s#root#rsync#;/auth/s#false#true#"  confxml.xml

#運行sersync:
nohup /app/local/sersync/sersync2 -r -d -o /app/local/sersync/confxml.xml >/app/local/sersync/rsync.log 2>&1 &

#nohup /app/local/sersync/sersync2 -r -d -o /app/local/sersync/img.xml >/app/local/sersync/img.log 2>&1 &
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章