代码改变世界

Postfix发送邮件时报错“libmysqlclient.so.18: cannot open shared object file: No such file or directory”

2022-03-14 23:13  潇湘隐者  阅读(1442)  评论(0编辑  收藏  举报

在一台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中,如果没做,可能会找不到刚安装的库