系统集群架构(5)

写在前面

  今天介绍项目后期的全网数据备份规划与配置过程,整个过程包括备份规划、脚本编写、数据同步等

 

01全网数据备份规划

数据备份规划如下

数据库

从库开启binlog,通过全备与增量备份来进行,每天00:00全备一次,每天12:00增量备份一次,初期数据量不大的情况,后期根据数据量进行调整

本地备份目录

/server/backup/mysql/data

/server/backup/mysql/binlog

 

FTP数据

实时同步上传数据,防止服务故障,可以快速切换

/www/ftp 同步至 /www/ftp

 

其它服务器数据实行实时同步

比如说配置文件备份、代码包备份

本地备份目录

/server/backup/app

/server/backup/sjapp

/server/backup/admin

/server/backup/shangjia

/server/backup/web

 

所有数据本地保留一周,远端备份服务器保留30天

 

02数据库服务备份配置

mkdir /server/backup/mysql/data

mkdir /server/backup/mysql/binlog

mkdir /server/scripts/

                       

 

 

脚本写好了,就需要写个定时任务定时执行,然后手工检查

Cat>>/var/spool/cron/root<<EOF

00 00 * * * /bin/sh /server/scripts/fullbak.sh >/dev/null 2>&1

00 12 * * * /bin/sh /server/scripts/binlog_bak.sh >/dev/null 2>&1

EOF

 

03静态资源服务器数据同步

同步服务器创建对等目录

mkdir /www/ftp 

安装rsync服务

Yum install rsync –y

配置rsync配置文件

vim /etc/rsyncd.conf

##rsync.conf config start

uid = rsync

gid = rsync

use chroot = no

max connetctions = 200

timeout = 100

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

[backup]

path = /www/ftp

ignore errors

read only = false

list = false

hosts allow = 10.0.0.8

auth users = rsync_backup

secrets file = /etc/rsync.password

##rsync config  end

创建用户 

useradd rsync -s /sbin/nologin -M

配置权限设置密码

chown -R rsync:rsync /www/ftp

echo "rsync_backup:rsync.conf">/etc/rsync.password

chmod 600 /etc/rsync.password

启动服务

rsync –daemon

[root@resources ~]# netstat -lntup|grep rsync

tcp  0 0 0.0.0.0:873  0.0.0.0:*  LISTEN  26280/rsync

客户端配置密码

echo "rsync.conf">/etc/rsync.password

chmod 600 /etc/rsync.password

测试手工同步数据是否成功

[root@resources ~]# rsync -avzP /etc/hosts rsync_backup@10.0.0.11::backup --password-file=/etc/rsync.password

sending incremental file list

hosts

473 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 314 bytes  received 27 bytes  682.00 bytes/sec

total size is 473  speedup is 1.39

[root@ftp-bakserver ~]# ll /www/ftp

total 4

-rw-r--r-- 1 rsync rsync 473 May 26 13:24 hosts

客户端安装sersync服务

tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/

[root@resources ~]# cd /usr/local/

[root@resources local]# mv GNU-Linux-x86 sersync

规范文件目录

[root@resources sersync]# mkdir -p conf bin logs

拷贝配置文件并修改

[root@resources sersync]# mv confxml.xml conf/

[root@resources sersync]# mv sersync2 bin/sersync

修改配置文件内容(confxml.xml)

1、修改24-28行

<localpath watch="/opt/tongbu">

 <remote ip="10.0.0.11" name="tongbu1"/>

 <!--<remote ip="192.168.8.39" name="tongbu"/>-->注释内容

 <!--<remote ip="192.168.8.40" name="tongbu"/>-->注释内容

        </localpath>

修改后的内容为

 <localpath watch="/www/ftp"> 本地数据的路径

  <remote ip="10.0.0.11" name="backup"/>远端IP与模块名称

         </localpath>

 <!#################################### -->注释内容

2、修改31-34行内容——认证

<commonParams params="-artuz"/>

<auth start="false" users="root" passwordfile="/etc/rsync.pass"/>

<userDefinedPort start="false" port="874"/><!-- port=874 -->

<timeout start="false" time="100"/><!-- timeout=100 -->

<ssh start="false"/>

修改后的内容为

<commonParams params="-aruz"/>

<auth start="true" users="rsync_backup"  passwordfile="/etc/rsync.password"/>

<userDefinedPort start="false" port="874"/><!-- port=874 -->

<timeout start="true" time="100"/><!-- timeout=100 -->

<ssh start="false"/>

3、修改36-37行

<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default

 every 60mins execute once-->

修改成我们刚刚创建好的logs目录

<failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecut

e="60"/><!--default every 60mins execute once-->

配置环境变量

echo 'export PATH=$PATH:/usr/local/sersync/bin'>>/etc/profile

[root@resources sersync]# source /etc/profile

[root@resources sersync]# which sersync

/usr/local/sersync/bin/sersync

启动服务

[root@resources sersync]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml

测试实时同步

[root@resources opt]# cd backup/

[root@resources backup]# ll

total 0

[root@ftp-bakserver ~]# cd /www/ftp

[root@ftp-bakserver backup]# ll

total 0

[root@resources ftp]# for i in `seq 10`;do mkdir -p /opt/backup/$i;done

[root@resources ftp]# ll

1 5 10 6 2 7 3 8 4 9 

[root@ftp-bakserver ftp]# ls

1 5 10 6 2 7 3 8 4 9

可以同步

 

04全网服务器数据同步配置

备份服务器配置

[user-app]

path = /mnt/backup/user-app

ignore errors

read only = false

list = false

hosts allow = 10.0.0.4

auth users = rsync_backup

secrets file = /etc/rsync.password

 

[sj-app]

path = /mnt/backup/sj-app

ignore errors

read only = false

list = false

hosts allow = 10.0.0.5

auth users = rsync_backup

secrets file = /etc/rsync.password

 

[admin]

path = /mnt/backup/admin

ignore errors

read only = false

list = false

hosts allow = 10.0.0.6

auth users = rsync_backup

secrets file = /etc/rsync.password

 

[shangjia]

path = /mnt/backup/shangjia

ignore errors

read only = false

list = false

hosts allow = 10.0.0.7

auth users = rsync_backup

secrets file = /etc/rsync.password

 

[web]

path = /mnt/backup/web

ignore errors

read only = false

list = false

hosts allow = 10.0.0.8

auth users = rsync_backup

secrets file = /etc/rsync.password 

其它同步客户端安装与配置sersync按上述操作进行

备份脚本基本都是打包备份或直接拷贝文件到本地备份目录



其它项目文章可查看往期回顾

-----至此,整个项目过程都已经介绍完成-----

 

posted @ 2018-08-13 10:35  禾子、  阅读(146)  评论(0编辑  收藏  举报