Linux系統集羣架構線上項目配置實戰 (完結篇)

Linux系統集羣架構線上項目配置實戰(四)mysql

寫在前面 web

  今天介紹項目後期的全網數據備份規劃與配置過程,整個過程包括備份規劃、腳本編寫、數據同步等sql

全網數據備份規劃數據庫

數據備份規劃以下vim

數據庫segmentfault

從庫開啓binlog,經過全備與增量備份來進行,天天00:00全備一次,天天12:00增量備份一次,初期數據量不大的狀況,後期根據數據量進行調整服務器

本地備份目錄架構

/server/backup/mysql/dataapp

/server/backup/mysql/binlogssh

FTP數據

實時同步上傳數據,防止服務故障,能夠快速切換

/www/ftp 同步至 /www/ftp

其它服務器數據實行實時同步

好比說配置文件備份、代碼包備份

本地備份目錄

/server/backup/app

/server/backup/sjapp

/server/backup/admin

/server/backup/shangjia

/server/backup/web

全部數據本地保留一週,遠端備份服務器保留30天

數據庫服務備份配置

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

靜態資源服務器數據同步

同步服務器建立對等目錄

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

一、修改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>

 <!#################################### -->註釋內容

二、修改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"/>

三、修改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

能夠同步

全網服務器數據同步配置

備份服務器配置

[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按上述操做進行

備份腳本基本都是打包備份或直接拷貝文件到本地備份目錄

其它項目文章可查看往期回顧

-----至此,整個項目過程都已經介紹完成-----

相關文章
相關標籤/搜索