自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

TB級mysql數(shù)據(jù)之xtrabackup壓縮備份遷移方案

數(shù)據(jù)庫 MySQL
開始遷移數(shù)據(jù)了,因為歷史遺留的問題,又因為部門的數(shù)據(jù)統(tǒng)一性,多個不同的庫表都在一個節(jié)點上,然后后面好多個從…..

   開始遷移數(shù)據(jù)了,因為歷史遺留的問題,又因為部門的數(shù)據(jù)統(tǒng)一性,多個不同的庫表都在一個節(jié)點上,然后后面好多個從…..

  首先看下我們數(shù)據(jù)庫的大小… , 再加上一個binlog日志,會更大的…. 當然對于咱們數(shù)據(jù)遷移來說,只需要把數(shù)據(jù)就可以了. 既然是遷移,

  那么大家一定想做到無縫的遷移… 首先在mysql master做備份,我們在上海機房搭建一個從服務(wù)節(jié)點,把文件pull下來,然后跟master做同步… 當數(shù)據(jù)校驗ok后,修改所有配置的ip地址。

  老規(guī)矩,最近爬蟲太狠,經(jīng)常爬了我的頁面,然后作者換成他們自己的….. http://xiaorui.cc/?p=1755

  3.4T,可以說是我見過的最大的數(shù)據(jù)量了,我們公司本身就是大數(shù)據(jù)相關(guān)的,但大數(shù)據(jù)基本是在hbase和Elasticsearch、solr中。 可能有人問了,為毛分庫分表,因為以前的應(yīng)用實在太多,不可能把每個select的邏輯都做分庫分表的邏輯查詢 …. 其實最好的方法是中間件來承擔語句的時間range切分,但是這同樣需要開發(fā)的成本,一些開源的mysql proxy,也是無法做到這樣語句切分,是需要一定程度的二次開發(fā)的…. 話說開源的各種mysql 中間件,貌似還沒有給力到完美支持語句分庫分表…..

  廢話不多說,這是我們數(shù)據(jù)庫的大小….

 

  1. [root@bj-buzz-db01 ssd]# du -sh mysql/ 
  2. .4T mysql/ 

 

  mysql的備份肯定不會用mysqldump這種鎖表的渣渣,必須用Percona的備份工具.

  XtraBackup 有兩個工具:xtrabackup 和 innobackupex:

  xtrabackup 本身只能備份 InnoDB 和 XtraDB ,不能備份 MyISAM;

  innobackupex 本身是 Hot Backup 腳本修改而來,同時可以備份 MyISAM 和 InnoDB,但是備份 MyISAM 需要加讀鎖。

  官網(wǎng):http://www.percona.com/software/percona-xtrabackup

  文檔:http://www.percona.com/doc/percona-xtrabackup/2.2/index.html

  因為考慮到文件是在太大,必須要做好壓縮,不然 不管scp和rsync都是很痛苦的一件事情。

  首先用的是gzip進行壓縮,但是發(fā)現(xiàn)速度有些慢,linux 管道的速度沒啥好質(zhì)疑的…. 那瓶頸應(yīng)該是處在gzip壓縮上…

  innobackupex –defaults-file=/etc/mysql/my.cnf –stream=tar /data/7_15 | gzip > /data/7_15.tar.gz

  查了下percona關(guān)于壓縮的話題,官方是推薦用上面的方法的。 但是問題我剛才也說明白了,gzip只是個單進程的應(yīng)用,如何跑滿cpu… 其實xtrabackup本身也有壓縮的功能參數(shù).

  # 壓縮

  –compress # 開啟壓縮,目前只支持quicklz算法 壓縮級別在0-9.1快速壓縮,9最佳壓縮,0不壓縮。默認為1.

  –compress-threads=5 # 并發(fā)壓縮線程,默認為1

  –compress-chunk-size=64K # 每個壓縮線程使用的buffer,默認64K

  percona也是有加密的功能….

  # 加密

  –encrypt=AES256 # 開啟加密,目前支持的算法有AES128, AES192 和 AES256

  –encrypt-key=3c0efcea569021b49245e47b5d6a0e28 # 32位密鑰,不過不推薦這么使用,最好將密鑰存放在文件中,用encrypt-key-file參數(shù)引用

  –encrypt-threads=5 # 加密線程數(shù),默認為1

  使用tar模式

  innobackupex –defaults-file=/etc/mysql/my.cnf –stream=tar –compress ./ > 7_15

  使用xbstream

  innobackupex –defaults-file=/etc/mysql/my.cnf –stream=xbstream /tmp >/backup/bak.xbstream

  用了壓縮,也用了多線程,速度貌似不是很給力…

  緊接著,在xtrabackup help里面看到了 –parallel這個參數(shù),他是用來控制并發(fā)的… 但是經(jīng)過我的測試,效果一點都不明顯,說白了就是沒啥效果…. 當然也有可能我的場景不對付? 或者是使用方法不對?

  默認情況下 xtrabackup 備份時只會開啟一個進程進行數(shù)據(jù)文件的備份,若配置參數(shù) –parallel=N 可以讓 xtrabackup 開啟 N 個子進程對多個數(shù)據(jù)文件進行并發(fā)備份,這樣可以加快備份的速度。當然服務(wù)器的 IO 處理能力以及對服務(wù)器的影響也是要考慮的,所以另一個參數(shù) –throttle=IOS 會與它同時使用,這個參數(shù)用來限制備份過程中每秒讀寫的 IO 次數(shù),對服務(wù)器的 IO 是一個保護。

  innobackupex –defaults-file=/etc/mysql/my.cnf –parallel=10 –stream=tar /data/7_15 | gzip > /data/7_15.tar.gz

  這是最后的方式…. 既然是gzip速度慢,那么就用pigz這種gzip的多線程加強版來改造他,加強他…. 個人覺得 –parallel –compress-threads 看起來不錯,但是性能提升不是很滿意..

  innobackupex –defaults-file=/etc/mysql/my.cnf –stream=tar /data/7_15 | pigz -9 -p 32 > /data/7_15.tar.gz

  這是pigz的安裝方式.

  1. wget http://zlib.net/pigz/pigz-2.3.3.tar.gz 
  2. tar zxvf pigz-2.3.3.tar.gz 
  3. cd pigz-2.3.3/ 
  4. make 

 

  遇到一個make問題。

  [root@bj-buzz-db01 pigz-2.3.3]# make

  cc -O3 -Wall -Wextra -c -o pigz.o pigz.c

  pigz.c:365:73: error: zlib.h: No such file or directory

  pigz.c:372:4: error: #error Need zlib version 1.2.3 or later

  pigz.c: In function ‘put_header’:

  pigz.c:1000: error: ‘Z_DEFAULT_COMPRESSION’ undeclared (first use in this function)

  pigz.c:1000: error: (Each undeclared identifier is reported only once

  pigz.c:1000: error: for each function it appears in.)

  pigz.c: At top level:

  pigz.c:1459: error: expected ‘)’ before ‘*’ token

  pigz.c: In function ‘compress_thread’:

  pigz.c:1495: error: ‘z_stream’ undeclared (first use in this function)

  pigz.c:1495: error: expected ‘;’ before ‘strm’

  pigz.c:1502: error: ‘strm’ undeclared (first use in this function)

  pigz.c:1502: error: ‘Z_NULL’ undeclared (first use in this function)

  pigz.c:1505: warning: implicit declaration of function ‘deflateInit2’

  pigz.c:1505: error: ‘Z_DEFLATED’ undeclared (first use in this function)

  pigz.c:1505: error: ‘Z_DEFAULT_STRATEGY’ undeclared (first use in this function)

  pigz.c:1506: error: ‘Z_MEM_ERROR’ undeclared (first use in this function)

  pigz.c:1508: error: ‘Z_OK’ undeclared (first use in this function)

  pigz.c:1530: warning: implicit declaration of function ‘deflateReset’

  pigz.c:1531: warning: implicit declaration of function ‘deflateParams’

  pigz.c:1546: warning: implicit declaration of function ‘deflateSetDictionary’

  pigz.c:1595: warning: implicit declaration of function ‘deflate_engine’

  pigz.c:1595: error: ‘Z_NO_FLUSH’ undeclared (first use in this function)

  pigz.c:1620: error: ‘Z_SYNC_FLUSH’ undeclared (first use in this function)

  pigz.c:1624: error: ‘Z_FINISH’ undeclared (first use in this function)

  pigz.c:1687: warning: implicit declaration of function ‘adler32’

  pigz.c:1687: warning: implicit declaration of function ‘crc32’

  pigz.c:1706: warning: implicit declaration of function ‘deflateEnd’

  pigz.c: In function ‘write_thread’:

  pigz.c:1737: error: ‘Z_NULL’ undeclared (first use in this function)

  pigz.c: In function ‘single_compress’:

  pigz.c:2039: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

  pigz.c:2039: error: ‘strm’ undeclared (first use in this function)

  pigz.c:2062: error: ‘z_stream’ undeclared (first use in this function)

  pigz.c:2063: error: ‘Z_NULL’ undeclared (first use in this function)

  pigz.c:2066: error: ‘Z_DEFLATED’ undeclared (first use in this function)

  pigz.c:2066: error: ‘Z_DEFAULT_STRATEGY’ undeclared (first use in this function)

  pigz.c:2067: error: ‘Z_MEM_ERROR’ undeclared (first use in this function)

  pigz.c:2069: error: ‘Z_OK’ undeclared (first use in this function)

  pigz.c:2173: warning: implicit declaration of function ‘deflate’

  pigz.c:2173: error: ‘Z_NO_FLUSH’ undeclared (first use in this function)

  pigz.c:2198: error: ‘Z_SYNC_FLUSH’ undeclared (first use in this function)

  pigz.c:2202: error: ‘Z_FINISH’ undeclared (first use in this function)

  pigz.c: In function ‘infchk’:

  pigz.c:3044: error: ‘z_stream’ undeclared (first use in this function)

  pigz.c:3044: error: expected ‘;’ before ‘strm’

  pigz.c:3054: error: ‘Z_NULL’ undeclared (first use in this function)

  pigz.c:3055: error: ‘strm’ undeclared (first use in this function)

  pigz.c:3058: warning: implicit declaration of function ‘inflateBackInit’

  pigz.c:3059: error: ‘Z_MEM_ERROR’ undeclared (first use in this function)

  pigz.c:3061: error: ‘Z_OK’ undeclared (first use in this function)

  pigz.c:3067: warning: implicit declaration of function ‘inflateBack’

  pigz.c:3068: warning: implicit declaration of function ‘inflateBackEnd’

  pigz.c:3069: error: ‘Z_DATA_ERROR’ undeclared (first use in this function)

  pigz.c:3072: error: ‘Z_BUF_ERROR’ undeclared (first use in this function)

  pigz.c:3074: error: ‘Z_STREAM_END’ undeclared (first use in this function)

  pigz.c: In function ‘defaults’:

  pigz.c:3828: error: ‘Z_DEFAULT_COMPRESSION’ undeclared (first use in this function)

  make: *** [pigz.o] Error 1

  提示錯誤,是因為沒有zlib開發(fā)包原因….

  yum -y install zlib-devel

  然后我們再次用pigz進行壓縮,下面是cpu的使用率。

  Tasks: 446 total, 1 running, 444 sleeping, 0 stopped, 1 zombie

  Cpu0 : 69.2%us, 2.6%sy, 0.0%ni, 23.5%id, 4.6%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu1 : 45.4%us, 1.0%sy, 0.0%ni, 53.6%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu2 : 51.0%us, 5.0%sy, 0.0%ni, 29.1%id, 14.6%wa, 0.0%hi, 0.3%si, 0.0%st

  Cpu3 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu4 : 34.0%us, 3.0%sy, 0.0%ni, 60.4%id, 2.6%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu5 : 69.3%us, 0.7%sy, 0.0%ni, 30.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu6 : 33.4%us, 15.4%sy, 0.0%ni, 27.4%id, 17.4%wa, 0.0%hi, 6.4%si, 0.0%st

  Cpu7 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu8 : 55.6%us, 1.3%sy, 0.0%ni, 36.8%id, 6.3%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu9 : 87.8%us, 0.3%sy, 0.0%ni, 11.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu10 : 99.3%us, 0.0%sy, 0.0%ni, 0.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu11 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu12 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu13 : 99.7%us, 0.0%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu14 : 99.7%us, 0.0%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu15 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu16 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu17 : 99.7%us, 0.0%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu18 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu19 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu20 : 99.7%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st

  Cpu21 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  Cpu22 : 98.7%us, 0.0%sy, 0.0%ni, 0.3%id, 0.0%wa, 0.0%hi, 1.0%si, 0.0%st

  Cpu23 :100.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

  我們再來看看磁盤,毫無壓力…. 我這邊就不貼圖了,剛要想起把iostat -x 1的結(jié)果貼出來,發(fā)現(xiàn)備份已經(jīng)完成。。。 在下午xtrabackup備份壓縮的過程中,其他的訪問沒感受到有性能的影響…..

  

 

  我們再來看看大小…. 965G…… 壓縮的效果還是比較的滿意…. 消耗的時間是,7:38 – 1:18 ,將近6個半小時。。。。。

  

 

  那么我又在讀取mysql數(shù)據(jù)文件的時候,增加了并發(fā),使用了–parallel參數(shù)讓 xtrabackup 開啟 N 個子進程對多個數(shù)據(jù)文件進行并發(fā)備份。

  innobackupex –defaults-file=/etc/mysql/my.cnf –user=root –password=xxx –parallel=5 –stream=tar /data/7_15_p | pigz -8 -p 15 > /data/7_15_p.tar.gz

  首先看下他的io情況. 我們會發(fā)現(xiàn),數(shù)據(jù)盤無壓力,但是備份的存儲盤io已經(jīng)是報了…. 這說明啥? 說明xtrabackup在增加了并發(fā)讀取文件的時候,不僅考慮mysql數(shù)據(jù)盤的io,也要考慮目標存儲盤的io是否能抗住。。。。

  1. Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util 
  2. sda               0.00    35.00    0.00    7.00     0.00   328.00    46.86     0.01    1.43   1.43   1.00 
  3. sdb               0.00    31.00  460.00   15.00 172944.00   368.00   364.87     1.51    3.16   2.08  98.90 
  4. dm-0              0.00     0.00    0.00   41.00     0.00   328.00     8.00     0.23    5.51   0.24   1.00 
  5. dm-1              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00 
  6. dm-2              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00 
  7. memdiska          0.00     0.00   63.00   37.00  2672.00   296.00    29.68     0.01    0.07   0.06   0.60 

 

責任編輯:honglu 來源: 內(nèi)存溢出
相關(guān)推薦

2023-01-11 08:05:23

XtraBackupMySQL備份

2015-11-25 11:16:45

2023-05-31 08:54:14

MySQL邏輯備份

2024-08-22 14:16:08

2015-10-29 13:44:06

MySQLinnodb引擎備份

2015-10-29 13:52:53

MySQLinnodb引擎備份

2015-05-15 14:51:11

TB 級數(shù)據(jù)云備份

2018-08-24 13:58:13

數(shù)據(jù)庫MySQL備份

2011-03-31 12:17:07

Cacti備份

2019-08-08 15:05:26

HBase數(shù)據(jù)遷移命令

2010-05-31 16:10:30

MySQL備份

2011-08-15 09:19:22

2013-09-09 17:17:18

MYSQL自動備份

2017-04-24 15:12:53

西部數(shù)據(jù)硬盤

2009-07-03 09:44:30

Oracle Data

2021-04-07 10:20:31

MySQL數(shù)據(jù)庫命令

2024-08-23 11:50:45

2017-07-06 15:12:48

MySQLgtid特性數(shù)據(jù)恢復(fù)

2023-11-14 08:44:55

數(shù)倍數(shù)據(jù)

2011-09-23 09:09:38

數(shù)據(jù)庫遷移
點贊
收藏

51CTO技術(shù)棧公眾號