在一台Linux服務器上使用postfix發送郵件時遇到上面錯誤:
sendmail.postfix: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
Error sending message, child exited 127 (Exec error.).
檢查和啟動postfix服務時,報下面錯誤:
# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2022-03-13 08:30:32 CST; 6s ago
Process: 235712 ExecStart=/usr/sbin/postfix start (code=exited, status=127)
Process: 235709 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
Process: 235705 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=127)
Mar 13 08:30:32 xxx-xxx-DB01 systemd[1]: Starting Postfix Mail Transport Agent...
Mar 13 08:30:32 xxx-xxx-DB01 aliasesdb[235705]: /usr/sbin/postconf: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
Mar 13 08:30:32 xxx-xxx-DB01 aliasesdb[235705]: /usr/bin/newaliases: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
Mar 13 08:30:32 xxx-xxx-DB01 postfix[235712]: /usr/sbin/postfix: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
Mar 13 08:30:32 xxx-xxx-DB01 systemd[1]: postfix.service: control process exited, code=exited status=127
Mar 13 08:30:32 xxx-xxx-DB01 systemd[1]: Failed to start Postfix Mail Transport Agent.
Mar 13 08:30:32 xxx-xxx-DB01 systemd[1]: Unit postfix.service entered failed state.
Mar 13 08:30:32 xxx-xxx-DB01 systemd[1]: postfix.service failed.
出現個錯誤的原因是找不到libmysqlclient.so.18這個文件,根本原因:要在這台機器上測試MySQL升級,我卸載MySQL時,將/usr/lib64/mysql/這個目錄給清理了,也導致/usr/lib64/mysql/libmysqlclient.so.18文件被刪除了,從而引起了這個問題。
解決方案:
1、因為這台Linux服務器是從生產環境克隆的,所以,我們可以將生產服務器上的libmysqlclient.so.18拷貝克隆過來。放到MySQL 5.7.36的安裝目錄下去。當前MySQL 5.7.36的lib目錄,你可以看到沒有libmysqlclient.so.18,只有libmysqlclient.so.20等文件,如下所示:
$ ls -lrt
total 1016992
-rw-r--r-- 1 mysql mysql 404983716 Sep 7 2021 libmysqld-debug.a
-rw-r--r-- 1 mysql mysql 43494 Sep 7 2021 libmysqlservices.a
-rwxr-xr-x 1 mysql mysql 9518856 Sep 7 2021 libmysqlclient.so.20.3.23
-rw-r--r-- 1 mysql mysql 21915440 Sep 7 2021 libmysqlclient.a
-rw-r--r-- 1 mysql mysql 595352594 Sep 7 2021 libmysqld.a
lrwxrwxrwx 1 mysql mysql 25 Sep 7 2021 libmysqlclient.so.20 -> libmysqlclient.so.20.3.23
lrwxrwxrwx 1 mysql mysql 20 Sep 7 2021 libmysqlclient.so -> libmysqlclient.so.20
drwxr-xr-x 2 mysql mysql 28 Mar 8 13:11 pkgconfig
drwxr-xr-x 4 mysql mysql 28 Mar 8 13:11 mecab
drwxr-xr-x 3 mysql mysql 4096 Mar 8 13:11 plugin
2、然后編輯/etc/ld.so.conf文件,在文件后面增加一條記錄:/data/mysql/mysql5.7/lib (libmysqlclient.so.18 和libmysqlclient.so.18.0.0所在目錄),運行ldconfig 命令,讓其生效。
下面是具體的操作步驟。
# mv libmysqlclient.so.18 /data/mysql/mysql5.7/lib/
# echo "/data/mysql/mysql5.7/lib" >> /etc/ld.so.conf
# ldconfig
# systemctl start postfix
ld.so.conf文件
/etc/ld.so.conf 此文件記錄了編譯時使用的動態庫的路徑,也就是加載so庫的路徑。
ldconfig命令:
它的作用是將文件/etc/ld.so.conf列出的路徑下的庫文件緩存到/etc/ld.so.cache以供使用,因此當安裝完一些庫文件,或者修改/etc/ld.so.conf增加了庫的新的搜索路徑,需要運行一下ldconfig,使所有的庫文件都被緩存到文件/etc/ld.so.cache中,如果沒做,可能會找不到剛安裝的庫