systemd 沒有正確關閉 MariaDB?

systemd 沒有正確關閉 MariaDB?

我們在 CentOS 7 上執行 LAMP 堆疊。我們無法讓 MariaDB 在測試機器上成功切換,因此我們從未嘗試在生產中進行切換。

最近我們遇到了更嚴重的資料庫崩潰。崩潰和損壞是一個長期存在的問題,但這次導致我們的維基離線。我們修復了 wiki 表和 MariaDB 資料庫,並認為我們解決了問題(直到下一次)。但是,重新啟動後我在日誌檔案中註意到以下內容:

InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
InnoDB: Database was not shut down normally! 

The log sequence number in ibdata files does not match是一個很常見的問題並且已經被討論過令人作嘔。但我們不應該在乾淨的關閉/重新啟動時遇到它。 (請更正)。

作為一個實驗,我執行了sudo su -隨後的shutdown -r now.然後日誌顯示:

# tail /var/log/mariadb/mariadb.log
180901 23:01:26 Percona XtraDB (http://www.percona.com) 5.5.59-MariaDB-38.11 started; log sequence number 1478830786
180901 23:01:26 [Note] Plugin 'FEEDBACK' is disabled.
180901 23:01:26 [Note] Server socket created on IP: '0.0.0.0'.
180901 23:01:26 [Note] Event Scheduler: Loaded 0 events
180901 23:01:26 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.60-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
180901 23:01:30 [ERROR] mysqld: Table './my_wiki/wikicryptopp_objectcache' is marked as crashed and should be repaired
180901 23:01:30 [Warning] Checking table:   './my_wiki/wikicryptopp_objectcache'
180901 23:05:01 [ERROR] mysqld: Table './my_wiki/wikicryptopp_module_deps' is marked as crashed and should be repaired
180901 23:05:01 [Warning] Checking table:   './my_wiki/wikicryptopp_module_deps'

systemd 似乎沒有正確關閉資料庫。 (請更正)。

我搜尋了 CentOS 和 Systemd 錯誤追蹤器,但沒有找到相關問題。我希望其他人也遇到這些問題,並且可以提供解決問題的步驟。

如何解決 MariaDB 關閉問題?


這是我在弄清楚關閉期間發生的情況時所了解到的。我不知道這是否正確(也許不正確),因為我不是 systemd 人員。

[root@ftpit ~]# find /etc -name mariadb.service
/etc/systemd/system/multi-user.target.wants/mariadb.service
[root@ftpit ~]# find /etc -name mysql.service
[root@ftpit ~]# find /opt/rh -name mariadb.service
[root@ftpit ~]# find /opt/rh -name mysql.service

進而:

# cat /etc/systemd/system/multi-user.target.wants/mariadb.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to create a file "/etc/systemd/system/mariadb.service",
# containing
#       .include /lib/systemd/system/mariadb.service
#       ...make your changes here...
# or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
# which doesn't need to include ".include" call and which will be parsed
# after the file mariadb.service itself is parsed.
#
# For more info about custom unit files, see systemd.unit(5) or
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# For example, if you want to increase mariadb's open-files-limit to 10000,
# you need to increase systemd's LimitNOFILE setting, so create a file named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
#       [Service]
#       LimitNOFILE=10000

# Note: /usr/lib/... is recommended in the .include line though /lib/...
# still works.
# Don't forget to reload systemd daemon after you change unit configuration:
# root> systemctl --system daemon-reload

[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql

ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

# Place temp files in a secure directory, not /tmp
PrivateTmp=true

[Install]
WantedBy=multi-user.target

答案1

「ibdata 檔案中的日誌序號不符」不應經常發生。這不太可能是系統問題。我會採取一個完整的 mysqldump 並將其還原到一個乾淨的實例中,並讓它消除 innodb 差異。

注意:systemctl show mariadb.service是顯示 systemd 配置的更好方法。

相關內容