1、從新初始化建庫mysql
[root@etiantian data]# mkdir mysql [root@etiantian data]# chown -R mysql.mysql mysql [root@etiantian data]# /install/mysql/scripts/mysql_install_db--basedir=/install/mysql/ --datadir=/data/mysql/ --user=mysql Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /install/mysql//bin/mysqladmin -u root password 'new-password' /install/mysql//bin/mysqladmin -u root -h etiantian.cn password'new-password' Alternatively you can run: /install/mysql//bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /install/mysql/ ; /install/mysql//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /install/mysql//mysql-test ; perl mysql-test-run.pl Please report any problems with the /install/mysql//scripts/mysqlbugscript!
二、啓動數據庫測試登陸linux
[root@etiantian data]# /etc/init.d/mysqld start Starting MySQL.......................... SUCCESS! [root@etiantian data]# mysql mysql:Collation'utf8-general_ci' is not a compiled collation and is not specifiedin the '/install/mysql/share/charsets/Index.xml' file Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.33-log Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement. mysql> quit -> Ctrl-C -- exit! Aborted
提示:能夠登陸可是報了一個錯誤。Collation'utf8-general_ci' is not a compiled collationweb
字符集校對規則沒有編譯進去。奇怪了。因爲着急這塊當時沒有詢問客戶,浪費了一點時間。只詢問了客戶數據庫備份的命令,由於涉及到建庫問題:sql
老男孩 19:07:07 數據庫
你當時的備份命令bash
XX 19:07:10 less
好運維
XX 19:07:12 ssh
稍等ide
XX 19:07:40
mysqldump -u root -ptest110oldboyeshop_ett100 >eshop_ett100.0624.sql
XX 19:08:49
是的
老男孩 19:09:29
之後加 -B
老男孩 19:09:43
mysql庫的用戶你知道吧。
XX 19:09:46
哦,就是這個選項是嗎
XX 19:09:48
知道
老男孩 19:09:51
就是web用戶鏈接的用戶及密碼
XX 19:10:00
etiantian,test110oldboy
老男孩 19:18:18
因爲你備份沒有加-B,因此須要建庫,整個命令及字符集呢
XX 19:18:28
utf-8
XX 19:18:34
沒任何別的東西
XX 19:19:18
create database eshop_ett100 utf8
老男孩 19:19:44
你這是完整命令麼
XX 19:20:18
不是,那個utf-8是這個db的默認字符集,沒其餘任何選項
XX 19:20:22
完整的等下我找找
老男孩 19:21:35
我寫好了,create database eshop_ett100 CHARACTER SET utf8 COLLATE utf8_general_ci;
XX 19:21:43
create database test2 DEFAULT CHARACTER SET utf8
詢問完畢
下面是老男孩操做的過程,查看建庫字符集
[root@etiantian data]# cat /root/.mysql_history |grep create create\040database\040eshop_ett100\040DEFAULT\040CHARACTER\040SET\040utf8\040COLLATE\040utf8_general_ci;肯定建庫的命令。 [root@etiantian data]# mysql mysql: Collation 'utf8-general_ci' is not a compiled collation andis not specified in the '/install/mysql/share/charsets/Index.xml' file Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.33-log Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement. mysql> create database eshop_ett100 CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.00 sec) mysql> quit Bye
三、開始正式嘗試恢復故障數據庫。
[root@etiantian data]# mysql eshop_ett100 </home/xxx/eshop_ett100.0624.sql mysql: Collation 'utf8-general_ci' is not acompiled collation and is not specified in the'/install/mysql/share/charsets/Index.xml' file ERROR 1030 (HY000) at line 46: Got error -1from storage engine
我暈,報錯!看來這個字符集校對規則必須重編了。因而詢問客戶:
老男孩 19:22:16
mysql: Collation 'utf8-general_ci' is not a compiled collation andis not specified in the '/install/mysql/share/charsets/Index.xml' file
XX 19:22:19
utf8_general_ci這個東西我編譯myhsql的時候寫錯了,寫成utf8-general_ci
下劃線寫成中線了
XX 19:23:23
我重編安裝下,你以爲好很差
老男孩 19:24:28
確實提示不支持
XX 19:24:43
應該是下劃線
老男孩 19:24:55
你重編吧
XX 19:24:56
utf8_general_ci
老男孩 19:25:01
我等你
老男孩 19:25:18
也能夠免編譯
老男孩 19:25:52
mysql-5.5.32-linux2.6-x86_64.tar.gz 沒下載地址上傳太慢
老男孩 19:26:00
你仍是從新編譯吧
XX 19:26:07
立刻重編好了
老男孩 19:26:09
刪掉安裝目錄我都備好了
XX 19:26:26
好,/data須要不須要刪除
老男孩 19:29:22
都刪掉
老男孩 19:29:28
安裝目錄都刪掉
老男孩 19:29:32
配置文件不要動
XX 19:29:45
裝好了
老男孩 19:29:47
到了make install便可
XX 19:29:51
配置文件沒動,我cp了一下
XX 19:29:55
好了
老男孩 19:30:28
OK
四、數據庫從新編譯後,老男孩開始進行二次故障恢復。
[root@etiantian data]# pwd /data [root@etiantian data]# rm -fr mysql [root@etiantian data]# mkdir mysql [root@etiantian data]# chown -R mysql.mysql <==這是着急的傑做,連目標都沒加,偶也緊張啊。 chown: missing operand after `mysql.mysql' Try `chown --help' for more information. [root@etiantian data]# chown -R mysql.mysql mysql [root@etiantian data]# /install/mysql/scripts/mysql_install_db--basedir=/install/mysql/ --datadir=/data/mysql/ --user=mysql Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /install/mysql//bin/mysqladmin -u root password 'new-password' /install/mysql//bin/mysqladmin -u root -h etiantian.cn password'new-password' Alternatively you can run: /install/mysql//bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /install/mysql/ ; /install/mysql//bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /install/mysql//mysql-test ; perl mysql-test-run.pl Please report any problems with the /install/mysql//scripts/mysqlbugscript!
從新初始化完畢
[root@etiantian data]# /etc/init.d/mysqld start Starting MySQL......................... SUCCESS! [root@etiantian data]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.33-log Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.
啓動成功,而且數據庫的登陸也徹底正常了。
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)
建庫
mysql> create database eshop_ett100 CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.00 sec) mysql> quit Bye
命令行數據全備恢復:
[root@etiantian data]# mysql eshop_ett100</home/xxx/eshop_ett100.0624.sql ERROR 1030 (HY000) at line 46: Got error -1 from storage engine
暈,報錯。到這裏,說實話,當時內心忽然一涼,原本很自信的答應客戶,100%能夠恢復。如今全備有問題。。。。。。完蛋了。這是當時真心的想法。夥伴們勿笑。
停頓了一下,立刻冷靜,下意識的看看數據庫備分內容沒發現異常。
[root@etiantian data]# less /home/xxx/eshop_ett100.0624.sql -- MySQL dump 10.13 Distrib5.5.33, for Linux (x86_64) ......
停頓一下,下意識的感受這個錯誤很熟悉,曾經遇到過。而後谷歌了下,找到了答案。解決過程以下:
[root@etiantian data]# mysql eshop_ett100 </home/xxx/eshop_ett100.0624.sql ERROR 1030 (HY000) at line 46: Got error -1 from storage engine [root@etiantian data]# /etc/init.d/mysqld stop Shutting down MySQL. SUCCESS! [root@etiantian data]# vi /etc/my.cnf <==此處順便調整相關其餘參數 innodb_force_recovery= 0 調整這個參數爲0 skip-external-locking key_buffer_size = 256M max_allowed_packet = 1M table_open_cache = 614 sort_buffer_size = 1M read_buffer_size = 1M read_rnd_buffer_size = 4M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size= 16M query_cache_limit = 1M query_cache_min_res_unit = 2k # Try number of CPU's*2 for thread_concurrency thread_concurrency = 8 ........ "/etc/my.cnf" 159L, 4948C written
重啓服務
[root@etiantian data]# /etc/init.d/mysqld start Starting MySQL. . SUCCESS! [root@etiantian data]# [root@etiantian data]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.33-log Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | eshop_ett100 | | test | +--------------------+ 5 rows in set (0.00 sec)
五、爲了防止數據問題,從新建庫。
mysql> drop database eshop_ett100; Query OK, 1 row affected (0.01 sec) mysql> create database eshop_ett100 CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.00 sec) mysql> quit Bye
最後一擊。
[root@etiantian data]# mysql eshop_ett100 </home/xxx/eshop_ett100.0624.sql
到此,全備恢復成功。內心終於舒坦了。親們。。。
接下來開始準備增量數據的恢復。
1、檢查備份好的用於恢復的增量文件
[root@etiantian data]# cd /server/backup/ [root@etiantian backup]# ll total 84832 drwxr-xr-x 7 mysql mysql 4096 Jun 24 19:09 mysql -rw-r----- 1 root root 14935771 Jun 24 19:27 mysql-bin.000014 -rw-r----- 1 root root 56588034 Jun 24 19:27 mysql-bin.000015 -rw-r--r-- 1 root root 15331635 Jun 24 19:06 mysql.tar.gz
2、根據全備的時間點設置增量恢復條件(這裏要看全備的時間點)
[root@etiantian backup]# mysqlbinlog mysql-bin.000014mysql-bin.000015 --start-datetime='2014-06-24 02:23:00' >bin.sql mysqlbinlog: unknown variable 'default-character-set=utf8' [root@etiantian backup]# which mysqlbinlog /install/mysql/bin/mysqlbinlog [root@etiantian backup]# /install/mysql/bin/mysqlbinlogmysql-bin.000014 mysql-bin.000015 --start-datetime='2014-06-24 02:23:00'>bin.sql /install/mysql/bin/mysqlbinlog: unknown variable'default-character-set=utf8' [root@etiantian backup]# /install/mysql/bin/mysqlbinlogmysql-bin.000014 mysql-bin.000015 --start-datetime='2014-06-24 02:23:00'>bin.sql /install/mysql/bin/mysqlbinlog: unknown variable'default-character-set=utf8'
我暈,又報錯,定了定神一看,你X,這個錯誤瞞不了我,老男孩給學生講課常遇到。
添加--no-defaults參數開始增量恢復。
[root@etiantian backup]# /install/mysql/bin/mysqlbinlog --no-defaultsmysql-bin.000014 mysql-bin.000015 --start-datetime='2014-06-24 02:23:00'>bin.sql [root@etiantian backup]# less bin.sql [root@etiantian backup]# mysql eshop_ett100 < bin.sql
到此,增量恢復完畢,即數據庫故障問題所有恢復完成。
1、登陸數據庫查看
[root@etiantian backup]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.5.33-log Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement. mysql> showdatabases; 看到了多緊張了吧。 ERROR 1064 (42000): You have an error in your SQL syntax; check themanual that corresponds to your MySQL server version for the right syntax touse near 'showdatabases' at line 1 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | eshop_ett100 | | test | +--------------------+ 5 rows in set (0.00 sec) mysql> use eshop_ett100 Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +-----------------------------+ | Tables_in_eshop_ett100 | +-----------------------------+ | eshop_ett_activity | ...... | eshop_ett_web | | eshop_ett_web_code | +-----------------------------+ 185 rows in set (0.00 sec)
全部的表都存在。退出,對恢復完畢的數據庫作全備,這塊很是關鍵,不要讓恢復過程付諸東流。
mysql> quit Bye [root@etiantian backup]# mysql -B –F eshop_ett100|gzip>new.sql.gz
<==我暈忙中出錯,恢復命令開始都搞錯了,結果,處於等待狀態,回車也不結束。
正確恢復命令以下:
[root@etiantian backup]# mysqldump -B -F eshop_ett100|gzip>new.sql.gz
2、通知客戶,先改web端口,開啓web服務內部測試看看
目的:該端口目的是不讓用戶訪問,內部先看下是否恢復正常。與客戶回報原話:
老男孩 19:41:53
親,恢復完畢了。
老男孩 19:42:00
先別起WEB
老男孩 19:42:04
你等進去
老男孩 19:42:15
等進去設置下鏈接帳號吧
XX 19:42:17
好
老男孩 19:42:28
root沒密碼
XX 19:42:44
好
老男孩 19:43:39
須要我幫忙你就提供用戶和密碼
XX 19:43:41
客戶端進不去mysql
XX 19:43:51
哦,沒密碼
XX 19:43:57
etiantian,test110oldboy
XX 19:44:14
權限是本機增刪查改eshop_ett
老男孩 19:45:28
grant select,insert,update,delete on eshop_ett100.* to'etiantian'@'localhost' identified by 'test110oldboy'
XX 19:45:39
yes
老男孩 19:46:30
WEB目錄在哪
XX 19:46:36
/www
老男孩 19:46:37
咱們改個端口起來
XX 19:46:44
好
XX 19:46:47
用多少端口
XX 19:46:51
我在web裏面改
老男孩 19:46:53
9000
3、測試web服務,竟然403,有連續調整了web目錄許可,以及首頁文件,最後成功打開網站,通過客戶仔細測試。
提示:在老男孩恢復期間,還有客戶公司的2我的,添亂,一直在改東西。因此致使了web也403。
老男孩 19:47:05
你改吧就是不讓用戶登陸
老男孩 19:47:10
咱們看下數據是否正常
老男孩 19:47:21
一切OK了 就能夠改回端口用了
XX 19:47:30
好
XX 19:47:40
你說的是httpd的端口是嗎
老男孩 19:47:49
對的
老男孩 19:47:59
數據庫密碼改了?
XX 19:47:59
我覺得mysql的端口
XX 19:48:19
好了
XX 19:48:21
改了
XX 19:48:23
全是那個密碼
老男孩 19:48:33
哪一個
XX 19:48:35
今天在網上暴露了,回頭我得改密碼
XX 19:48:40
test110oldboy
XX 19:48:46
root,etiantian都這個
XX 19:48:56
我如今起web?
老男孩 19:50:04
改過的HTTP的端口 就重啓吧
XX 19:50:29
好
老男孩 19:51:05
登陸web檢查點
一、看看亂碼不。
二、看看用戶註冊記錄量, 夠不夠,是否是連續的,訂單對不對 包括白天有沒有
XX 19:51:42
恩
XX 19:53:10
說的沒權限訪問根目錄,我看看
老男孩 19:54:24
提示呢
XX 19:54:36
[Tue Jun 24 19:53:57 2014] [error] [client 110.75.102.99] Directoryindex forbidden by Options directive: /www/
XX 19:54:38
httpd
XX 19:54:43
沒事這個,我能搞定
老男孩 19:56:16
仍是80 了?
XX 19:56:31
恩
XX 19:56:39
有領導來了要看,擦
老男孩 19:57:00
不行目錄給我 403 我來幫你
老男孩 19:57:21
站點目錄 http配置路徑告訴我
XX 19:57:36
httpd安裝目錄 /install/httpd
XX 19:57:43
其他全是默認
XX 19:59:32
你等下,我大約知道什麼問題了
老男孩 20:00:00
首頁文件是哪一個
老男孩 20:00:03
趕忙告訴我
XX 20:00:17
改掉了,等下,我替換回來看看
老男孩 20:00:36
我改好好了
老男孩 20:00:41
你別亂改了。
老男孩 20:00:45
直接打開網站就好了
老男孩 20:00:54
測試好了之後你再弄
老男孩 20:00:59
我這個打開了
老男孩 20:01:04
你登陸檢查數據庫吧
XX 20:01:07
好了
老男孩 20:01:14
以前大家都改錯了
XX 20:01:16
我從別的主機上拿了個文件來了
老男孩 20:01:23
站點目錄和許可的不一致還沒首頁文件
XX 20:01:44
有我的改了這個東西
XX 20:01:46
是的
老男孩 20:01:56
趕忙檢查數據庫吧
XX 20:02:01
咱們經理一直在旁邊看着,太撐面子了
XX 20:02:02
哈哈
老男孩 20:02:15
趕忙檢查 沒事 我就下了,下課了,我還沒吃飯呢,有朋友等着呢。
老男孩 20:02:20
必須支持大家啊。
老男孩 20:02:26
不支持大家支持誰
老男孩 20:02:45
整個恢復過程應該是數據無損失
XX 20:02:54
哈哈,太感謝了
老男孩 20:04:05
剛纔我寫了個備份腳本 被刪了。
老男孩 20:04:23
改天你讓運維都搞好寫個優化文檔 回頭我給你審覈下。
XX 20:04:33
我只刪了install/mysql
老男孩 20:04:34
備份容災措施
XX 20:04:42
等下,我看看你說的有個文件許可
老男孩 20:05:11
看看都正常了不
XX 20:05:27
都正常了
老男孩 20:05:34
ll /server/backup/
老男孩 20:05:40
恢復以後的全備目錄
老男孩 20:05:45
大家趕忙全備吧
XX 20:05:58
全備就仍是我那個命令對吧
老男孩 20:07:05
!#/bin/sh
bakpath=/server/scripts
[ ! -d $bakpath ] &&mkdir $bakpath
mysqldump -uroot -ptest110oldboy -B eshop_ett100|gzip>$bakpath/eshop_ett100_$(date +%F).sql.gz
mysqldump -uroot -ptest110oldboy -B mysql --events |gzip>$bakpath/mysql_$(date +%F).sql.gz
老男孩 20:07:20
必定要加-B 否則恢復麻煩
XX 20:08:16
我把全備就放在那個/server/backup/下面就好了是吧
XX 20:08:44
好,我按你這個備
老男孩 20:08:51
mysqldump -uroot -ptest110oldboy -B -F --single-transaction eshop_ett100|gzip>$bakpath/eshop_ett100_$(date +%F).sql.gz
老男孩 20:09:01
最後這個吧。
XX 20:09:04
好
老男孩 20:09:19
備好寫個定時任務,而後頭幾天檢查報警看。
老男孩 20:09:44
增量直接本地rsync 推就能夠
老男孩 20:09:52
對
老男孩 20:10:02
注意目錄是變量要定義
老男孩 20:10:07
我要下了
老男孩 20:10:11
還有事麼?
XX 20:10:11
本地沒其餘虛擬機,其餘的都在我內網,像我剛拽index文件過去
XX 20:10:14
好的,你休息
XX 20:10:24
我寫備份腳本+cron
XX 20:10:26
沒事了
XX 20:10:28
太感謝了
老男孩 20:10:59
我下了。有事電話。
XX 20:11:02
好的
XX 20:11:04
你先下吧
XX 20:11:09
我慢慢研究會
XX 20:11:10
呵呵
老男孩 20:11:12
不注意規範
XX 20:11:14
水平如此噻
老男孩 20:11:23
恢復的過程有空我給你
XX 20:11:23
手仍是太糙
老男孩 20:11:26
我都保留了
XX 20:11:28
好的
老男孩 20:11:33
你是開發大拿
老男孩 20:11:43
各有專攻
XX 20:11:46
哎,如今開發少了,主要靠這個
XX 20:11:57
你抓緊時間休息吧
老男孩 20:12:02
好 88
XX 20:12:06
上一天課也累了
XX 20:12:08
好,88哦
老男孩 20:12:56
另外之後不要killall殺庫,我估計你是參數給大了,特別是innodb buffer。停庫時間較長是正常的,多等,另外要作好主從複製,爲恢復爭取時間。
後記:整個恢復過程持續了將近1個小時。比計劃解決時間多出了半小時,看來不少時間仍是始料不及的,特別是做爲第三方公司,老男孩對客戶的業務不瞭解也是故障恢復進度慢的一個緣由,好多要和客戶溝通交流的,另外,不在一個城市,靠QQ聊天解決問題,效率確實仍是低了一些,幸虧客戶的配合仍是不錯。
解決問題容易,寫故障報告難,能主動寫報告給客戶更難,老男孩作到了。
一、ssh事先配好記錄LOG,便於過後總結。
二、服務於客戶,要儘量超越客戶的期待。
老男孩和你們一塊兒努力。。。謝謝你們觀看。
LINUX技術交流羣 246054962 208160987(標明51CTO)