這篇文章主要介紹了MySQL容器啟動(dòng)失敗恢復(fù)的示例分析,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
讓客戶(hù)滿(mǎn)意是我們工作的目標(biāo),不斷超越客戶(hù)的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶(hù),將通過(guò)不懈努力成為客戶(hù)在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名申請(qǐng)、網(wǎng)絡(luò)空間、營(yíng)銷(xiāo)軟件、網(wǎng)站建設(shè)、江陽(yáng)網(wǎng)站維護(hù)、網(wǎng)站推廣。
Mysql容器啟動(dòng)失敗恢復(fù)案例
昨天重啟完NAS后,今天早上發(fā)現(xiàn)NAS又死機(jī)了。只能再次強(qiáng)制關(guān)機(jī),重啟。
啟動(dòng)docker容器之前,我把mysql容器的內(nèi)存調(diào)整了一下,調(diào)整成了512M。 然后就悲劇的發(fā)現(xiàn)啟動(dòng)不了了。后來(lái)發(fā)現(xiàn),啟動(dòng)不了不是我調(diào)內(nèi)存的關(guān)系。
查看日志,顯示如下:
2020-12-27T02:43:53.375776Z 0 mysqld: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.
2020-12-27T02:43:53.375776Z 0 mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2020-12-27T02:43:53.375776Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2020-12-27T02:43:53.376005Z 0 [ERROR] [MY-010119] [Server] Aborting
百度了下,解決辦法是重新run一個(gè)mysql容器,并且在之前的配置上加上-v /mnt/md0/User/wzp/home/www/mysql-files:/var/lib/mysql-files/
。
現(xiàn)在問(wèn)題來(lái)了,之前run mysql容器時(shí),我并沒(méi)有記錄下完整的run 命令。還好,通過(guò)rekcod工具可以查看。更喜的是,這個(gè)工具可以通過(guò)docker來(lái)運(yùn)行。因?yàn)槲业腘AS的系統(tǒng)不是發(fā)行版的linux,npm,yum好多工具都沒(méi)法安裝。
關(guān)于rekcod的使用可以參考linuxea:如何復(fù)現(xiàn)查看docker run參數(shù)命令
簡(jiǎn)單來(lái)說(shuō),用法如下:
1 docker 安裝rekcod
$ docker pull nexdrew/rekcod $ alias rekcod="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod"
2 使用方法:
[root@TNAS-012664 ~]# rekcod mysql ==>mysql是我的容器名 docker run --name mysql --runtime runc -v /mnt/md0/User/wzp/home/www/mysql/:/var/lib/mysql -p 3306:3306/tcp --net bridge --restart no -h 39964e9e508a --expose 3306/tcp --expose 33060/tcp -e 'MYSQL_ROOT_PASSWORD=123456' -e 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -e 'GOSU_VERSION=1.12' -e 'MYSQL_MAJOR=5.7' -e 'MYSQL_VERSION=5.7.30-1debian10' -d -t -i --entrypoint "docker-entrypoint.sh" mysql 'mysqld'
可以看到我的數(shù)據(jù)庫(kù)文件都是放在/mnt/md0/User/wzp/home/www/mysql/
目錄下,我查看了下該目錄文件,數(shù)據(jù)應(yīng)該是沒(méi)有丟失的。
于是,我新建了mysql2 容器,命令如下docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql2 -v /mnt/md0/User/wzp/home/www/mysql/:/var/lib/mysql -v /mnt/md0/User/wzp/home/www/mysql-files:/var/lib/mysql-files/ mysql
然后,進(jìn)入mysql2,發(fā)現(xiàn)沒(méi)法連接數(shù)據(jù)庫(kù)docker exec -it mysql2 /bin/bash
查看mysql 狀態(tài)
root@0e83698acbfb:/# mysqld status mysqld: [Warning] World-writable config file '/etc/mysql/conf.d/docker.cnf' is ignored. mysqld: [Warning] World-writable config file '/etc/mysql/conf.d/mysql.cnf' is ignored. 2020-12-27T02:39:41.865252Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. 2020-12-27T02:39:41.865455Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 105 2020-12-27T02:39:41.871715Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root! 2020-12-27T02:39:41.872541Z 0 [ERROR] [MY-010119] [Server] Aborting 2020-12-27T02:39:41.872776Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20) MySQL Community Server - GPL. root@0e83698acbfb:/# Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!^C
用以下方法以root方式啟動(dòng)mysqld
root@0e83698acbfb:/# mysqld --user=root mysqld: [Warning] World-writable config file '/etc/mysql/conf.d/docker.cnf' is ignored. mysqld: [Warning] World-writable config file '/etc/mysql/conf.d/mysql.cnf' is ignored. 2020-12-27T02:40:57.169719Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. 2020-12-27T02:40:57.169896Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 116 2020-12-27T02:40:57.184807Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2020-12-27T02:40:57.241048Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11 2020-12-27T02:40:58.241783Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11 2020-12-27T02:40:59.242983Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11 2020-12-27T02:41:00.244290Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11 2020-12-27T02:41:01.245762Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11 2020-12-27T02:41:02.247539Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11
屏幕一直打印Unable to lock ./ibdata1 error: 11,只能CTRL-C強(qiáng)制中斷。百度了下,有兩個(gè)方式來(lái)解決該問(wèn)題
1 參考mysql之 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
該文章分析,導(dǎo)致該error主要是以下兩個(gè)原因,很可惜,文章中的方法并不能解決我的問(wèn)題。
磁盤(pán)空間目錄不足
ibdata1 文件被其他的進(jìn)程占用
2 參考mysqld報(bào)InnoDB: Unable to lock ./ibdata1 error: 11這篇文章完美解決了我的問(wèn)題。主要進(jìn)行了以下操作。
2.1 首先,進(jìn)入我的mysql數(shù)據(jù)庫(kù)所在目錄cd /mnt/md0/User/wzp/home/www/mysql
2.2 然后將ibdata1等文件重命名后,再cp回來(lái)。具體為什么要這么做,我也不太明白。
[root@TNAS-012664 www]# cd /mnt/md0/User/wzp/home/www/mysql/ [root@TNAS-012664 mysql]# ls auto.cnf binlog.index client-key.pem dci '#ib_16384_0.dblwr' ib_logfile0 mautic nianbao performance_schema robot shangbiao undo_001 zeng baike ca-key.pem company_works dianzicaipiao '#ib_16384_1.dblwr' ib_logfile1 mysql niuwan private_key.pem sara_wiki sjzt_ry6 undo_002 bigdatapaltfrom ca.pem copyrightdata gs_data ib_buffer_pool '#innodb_temp' mysql.ibd pachong public_key.pem server-cert.pem sys wenshu binlog.000001 client-cert.pem db_huayun hy_dci_admin ibdata1 integrate mysql_upgrade_info pachong2 qianliu_wiki server-key.pem ucenter_huayunyy yuanqixiaoshuo [root@TNAS-012664 mysql]# mv ibdata1 ibdata1.bak [root@TNAS-012664 mysql]# mv ib_logfile0 ib_logfile0.bak [root@TNAS-012664 mysql]# mv ib_logfile1 ib_logfile1.bak [root@TNAS-012664 mysql]# cp -a ibdata1.bak ibdata1 [root@TNAS-012664 mysql]# cp -a ib_logfile0.bak ib_logfile0 [root@TNAS-012664 mysql]# cp -a ib_logfile1.bak ib_logfile1
2.3 然后我刪除之前的mysql2 container,用下面的命令再次run一個(gè)mysql2容器,發(fā)現(xiàn)就可以連接mysql數(shù)據(jù)庫(kù)了。
[root@TNAS-012664 ~]# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql2 -v /mnt/md0/User/wzp/home/www/mysql/:/var/lib/mysql -v /mnt/md0/User/wzp/home/www/mysql-files:/var/lib/mysql-files/ mysql 1e031247ea46e82f6205db68e7fb1b55389c87e5e2cb13517f9e1ac17d514509 [root@TNAS-012664 ~]# docker exec -it mysql2 /bin/bash root@1e031247ea46:/# mysql -uroot -p mysql: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored. Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.20 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 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 input statement. mysql> show databases;
以為mysql容器好了就萬(wàn)事大吉了? No,too naive! 還有一個(gè)小插曲等著我呢。這邊剛把mysql容器解決好,突然又發(fā)現(xiàn)我的wiki容器莫名其妙沒(méi)了。不過(guò)好在,數(shù)據(jù)庫(kù)文件在,一切還能恢復(fù)如初。
1 用以下的命令新建兩個(gè)wiki
docker run --name sarawiki --link mysql2:mysql -p 8086:80 -d sarawang85/mediawiki:1.0.0 docker run --name qianliuwiki --link mysql2:mysql -p 8083:80 -d sarawang85/mediawiki:1.0.0
2 然后把備份好的LocalSettings.php 文件和Logo圖片copy 進(jìn)容器,搞定。
PS,如果在docker gui界面編輯stop狀態(tài)的容器,比如設(shè)置內(nèi)存限制,實(shí)際是會(huì)新建一個(gè)同名的容器。因?yàn)槲野l(fā)現(xiàn)我這樣做了后,訪問(wèn)我的wiki,又提示我重新安裝。
再次PS,mysql 備份得立即提上日程。mysql 內(nèi)存限制不能單單通過(guò)容器來(lái)限制,my.cnf也得做響應(yīng)更改。
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Mysql容器啟動(dòng)失敗恢復(fù)的示例分析”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!