linux环境,通过rpm删除mysql包,报错:error reading information on service mysqld: Invalid argument...

问题描述:

  今天在做saltstack的练习,想要通过sls的方式,在远程进行mysql数据库的安装,发现无法通过service的方式启动数据库,然后就想给删除了重新进行安装,在通过rpm -e进行删除rpm包时,报下面的错误:

[root@testvm03 ~]# rpm -e mysql-server-5.1.73-8.el6_8.x86_64
error reading information on service mysqld: Invalid argument
error: %preun(mysql-server-5.1.73-8.el6_8.x86_64) scriptlet failed, exit status 1

 

问题分析

  开始对于这个报错,以为是rpm本身在删除软件的时候的报错,所以呢,就把错误贴到各种地方去搜索,搜索了很久也没有得到答案。后来想想,不对,我得仔细看看报错信息想要说明什么内容,然后看到第1行,明显是在读mysqld这个服务的信息报错,在思考,rpm -e的过程,首先应该是读取这个服务的状态,如果在运行,先将服务停掉,然后再进行删除各种相关文件的操作。

 

问题解决

1.看看mysqld这个脚本是否存在,或者有问题

[root@testvm03 init.d]# ls -ltr
total 224
-rwxr-xr-x. 1 root root  2898 Mar 20  2010 rhnsd
-rwxr-xr-x  1 root root  2073 Oct 23  2012 rpcbind
-rwxr-xr-x. 1 root root  2011 Aug 15  2013 rsyslog
-rwxr-xr-x. 1 root root  2826 Sep 12  2013 crond
-rwxr-xr-x. 1 root root  1513 Sep 17  2013 rdisc
-rwxr-xr-x. 1 root root  3912 Feb 14  2014 postfix
-rwxr-xr-x. 1 root root  2056 Jun 23  2014 saslauthd
-rwxr-xr-x. 1 root root   647 Jul 22  2014 single
-rwxr-xr-x. 1 root root  6334 Jul 22  2014 network
-rwxr-xr-x. 1 root root  6064 Jul 22  2014 netfs
-rwxr-xr-x. 1 root root  2989 Jul 22  2014 netconsole
-rwxr-xr-x. 1 root root   652 Jul 22  2014 killall
-rwxr-xr-x. 1 root root  5866 Jul 22  2014 halt
-rw-r--r--. 1 root root 19295 Jul 22  2014 functions
-rwxr-xr-x. 1 root root  2294 Jul 24  2014 udev-post
-rwxr-xr-x. 1 root root  1698 Aug  9  2014 sandbox
-rwxr-xr-x. 1 root root  1822 Aug  9  2014 restorecond
-rwxr-xr-x. 1 root root  3580 Aug 10  2014 auditd
-rwxr-xr-x. 1 root root 19476 Aug 27  2014 kdump
-rwxr-xr-x. 1 root root  4621 Aug 27  2014 sshd
-rwxr-xr-x. 1 root root 10688 Aug 28  2014 iptables
-rwxr-xr-x. 1 root root 10804 Aug 28  2014 ip6tables
-rwxr-xr-x. 1 root root  1738 Aug 29  2014 snmptrapd
-rwxr-xr-x. 1 root root  2162 Aug 29  2014 snmpd
-r-xr-xr-x. 1 root root  1340 Sep  1  2014 blk-availability
-r-xr-xr-x. 1 root root  2757 Sep  1  2014 lvm2-monitor
-r-xr-xr-x. 1 root root  2134 Sep  1  2014 lvm2-lvmetad
-rwxr-xr-x  1 root root  2464 Sep  5  2014 rpcsvcgssd
-rwxr-xr-x  1 root root  2305 Sep  5  2014 rpcidmapd
-rwxr-xr-x  1 root root  2518 Sep  5  2014 rpcgssd
-rwxr-xr-x  1 root root  3526 Sep  5  2014 nfslock
-rwxr-xr-x  1 root root  6878 Sep  5  2014 nfs
-rwxr-xr-x. 1 root root  2571 Sep  5  2014 mdmonitor
-rwxr-xr-x. 1 root root  1215 Sep 16  2014 rhsmcertd
-rwxr-xr-x  1 root root     0 Jan 27  2017 mysqld      #经过检查,发现mysqld中的脚本是空字节的,就是没有任何的内容,如果要查mysqld的状态,传参自然是不可用的
-rwxr-xr-x  1 root root  3488 Jun 19  2018 httpd
-rwxr-xr-x  1 root root  2001 Jun 19  2018 htcacheclean
-rwxr-xr-x. 1 root root  1193 Jul 31  2018 nrpe
-rwxr-xr-x  1 root root  7752 Feb 21 06:06 salt-minion

备注:这个也就能够解释执行service mysqld start为啥没有任何反应,脚本中啥都没有,mysqld根本不知道做什么。

2.考虑将其他机器上的mysqld脚本拷贝到/etc/init.d/目录下

[root@testvm03 init.d]# rm mysqld          #删除空字节的mysqld脚本文件
rm: remove regular empty file `mysqld'? y   
[root@testvm03 init.d]# rz                 #通过rz命令,将其他主机上可用的脚本上传到此

[root@testvm03 init.d]# 
[root@testvm03 init.d]# ls -ltr
total 232
-rwxr-xr-x. 1 root root  2898 Mar 20  2010 rhnsd
-rwxr-xr-x  1 root root  2073 Oct 23  2012 rpcbind
-rwxr-xr-x. 1 root root  2011 Aug 15  2013 rsyslog
-rwxr-xr-x. 1 root root  2826 Sep 12  2013 crond
-rwxr-xr-x. 1 root root  1513 Sep 17  2013 rdisc
-rwxr-xr-x. 1 root root  3912 Feb 14  2014 postfix
-rwxr-xr-x. 1 root root  2056 Jun 23  2014 saslauthd
-rwxr-xr-x. 1 root root   647 Jul 22  2014 single
-rwxr-xr-x. 1 root root  6334 Jul 22  2014 network
-rwxr-xr-x. 1 root root  6064 Jul 22  2014 netfs
-rwxr-xr-x. 1 root root  2989 Jul 22  2014 netconsole
-rwxr-xr-x. 1 root root   652 Jul 22  2014 killall
-rwxr-xr-x. 1 root root  5866 Jul 22  2014 halt
-rw-r--r--. 1 root root 19295 Jul 22  2014 functions
-rwxr-xr-x. 1 root root  2294 Jul 24  2014 udev-post
-rwxr-xr-x. 1 root root  1698 Aug  9  2014 sandbox
-rwxr-xr-x. 1 root root  1822 Aug  9  2014 restorecond
-rwxr-xr-x. 1 root root  3580 Aug 10  2014 auditd
-rwxr-xr-x. 1 root root 19476 Aug 27  2014 kdump
-rwxr-xr-x. 1 root root  4621 Aug 27  2014 sshd
-rwxr-xr-x. 1 root root 10688 Aug 28  2014 iptables
-rwxr-xr-x. 1 root root 10804 Aug 28  2014 ip6tables
-rwxr-xr-x. 1 root root  1738 Aug 29  2014 snmptrapd
-rwxr-xr-x. 1 root root  2162 Aug 29  2014 snmpd
-r-xr-xr-x. 1 root root  1340 Sep  1  2014 blk-availability
-r-xr-xr-x. 1 root root  2757 Sep  1  2014 lvm2-monitor
-r-xr-xr-x. 1 root root  2134 Sep  1  2014 lvm2-lvmetad
-rwxr-xr-x  1 root root  2464 Sep  5  2014 rpcsvcgssd
-rwxr-xr-x  1 root root  2305 Sep  5  2014 rpcidmapd
-rwxr-xr-x  1 root root  2518 Sep  5  2014 rpcgssd
-rwxr-xr-x  1 root root  3526 Sep  5  2014 nfslock
-rwxr-xr-x  1 root root  6878 Sep  5  2014 nfs
-rwxr-xr-x. 1 root root  2571 Sep  5  2014 mdmonitor
-rwxr-xr-x. 1 root root  1215 Sep 16  2014 rhsmcertd
-rw-r--r--  1 root root  7026 Jan 27  2017 mysqld           #有内容,没有执行权限
-rwxr-xr-x  1 root root  3488 Jun 19  2018 httpd
-rwxr-xr-x  1 root root  2001 Jun 19  2018 htcacheclean
-rwxr-xr-x. 1 root root  1193 Jul 31  2018 nrpe
-rwxr-xr-x  1 root root  7752 Feb 21 06:06 salt-minion
[root@testvm03 init.d]# chmod +x mysqld    #增加该脚本的可执行权限
[root@testvm03 init.d]# ls -ltr
total 232
-rwxr-xr-x. 1 root root  2898 Mar 20  2010 rhnsd
-rwxr-xr-x  1 root root  2073 Oct 23  2012 rpcbind
-rwxr-xr-x. 1 root root  2011 Aug 15  2013 rsyslog
-rwxr-xr-x. 1 root root  2826 Sep 12  2013 crond
-rwxr-xr-x. 1 root root  1513 Sep 17  2013 rdisc
-rwxr-xr-x. 1 root root  3912 Feb 14  2014 postfix
-rwxr-xr-x. 1 root root  2056 Jun 23  2014 saslauthd
-rwxr-xr-x. 1 root root   647 Jul 22  2014 single
-rwxr-xr-x. 1 root root  6334 Jul 22  2014 network
-rwxr-xr-x. 1 root root  6064 Jul 22  2014 netfs
-rwxr-xr-x. 1 root root  2989 Jul 22  2014 netconsole
-rwxr-xr-x. 1 root root   652 Jul 22  2014 killall
-rwxr-xr-x. 1 root root  5866 Jul 22  2014 halt
-rw-r--r--. 1 root root 19295 Jul 22  2014 functions
-rwxr-xr-x. 1 root root  2294 Jul 24  2014 udev-post
-rwxr-xr-x. 1 root root  1698 Aug  9  2014 sandbox
-rwxr-xr-x. 1 root root  1822 Aug  9  2014 restorecond
-rwxr-xr-x. 1 root root  3580 Aug 10  2014 auditd
-rwxr-xr-x. 1 root root 19476 Aug 27  2014 kdump
-rwxr-xr-x. 1 root root  4621 Aug 27  2014 sshd
-rwxr-xr-x. 1 root root 10688 Aug 28  2014 iptables
-rwxr-xr-x. 1 root root 10804 Aug 28  2014 ip6tables
-rwxr-xr-x. 1 root root  1738 Aug 29  2014 snmptrapd
-rwxr-xr-x. 1 root root  2162 Aug 29  2014 snmpd
-r-xr-xr-x. 1 root root  1340 Sep  1  2014 blk-availability
-r-xr-xr-x. 1 root root  2757 Sep  1  2014 lvm2-monitor
-r-xr-xr-x. 1 root root  2134 Sep  1  2014 lvm2-lvmetad
-rwxr-xr-x  1 root root  2464 Sep  5  2014 rpcsvcgssd
-rwxr-xr-x  1 root root  2305 Sep  5  2014 rpcidmapd
-rwxr-xr-x  1 root root  2518 Sep  5  2014 rpcgssd
-rwxr-xr-x  1 root root  3526 Sep  5  2014 nfslock
-rwxr-xr-x  1 root root  6878 Sep  5  2014 nfs
-rwxr-xr-x. 1 root root  2571 Sep  5  2014 mdmonitor
-rwxr-xr-x. 1 root root  1215 Sep 16  2014 rhsmcertd
-rwxr-xr-x  1 root root  7026 Jan 27  2017 mysqld
-rwxr-xr-x  1 root root  3488 Jun 19  2018 httpd
-rwxr-xr-x  1 root root  2001 Jun 19  2018 htcacheclean
-rwxr-xr-x. 1 root root  1193 Jul 31  2018 nrpe
-rwxr-xr-x  1 root root  7752 Feb 21 06:06 salt-minion

 3.尝试启动服务,或者删除软件包

[root@testvm03 init.d]# service mysqld start   #尝试启动mysql,发现有内容,虽然报错了。
Initializing MySQL database:                               [  OK  ]
MySQL Daemon failed to start.
Starting mysqld:                                           [FAILED]
[root@testvm03 init.d]# ps -ef | grep mysql   #没有启动成功,但是不是关注的焦点,焦点在于删除这个组件包
root      1441  1291  0 10:45 pts/0    00:00:00 grep mysql
[root@testvm03 init.d]# tail -f /var/log/mysqld.log 
^C
[root@testvm03 init.d]# rpm -qa | grep mysql
mysql-server-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
[root@testvm03 init.d]# rpm -e mysql-server-5.1.73-8.el6_8.x86_64   #再次执行删除包操作,发现是能够删除掉的。
warning: /etc/logrotate.d/mysqld saved as /etc/logrotate.d/mysqld.rpmsave
[root@testvm03 init.d]# rpm -qa | grep mysql
mysql-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
[root@testvm03 init.d]# 

备注:该问题得到解决,mysql-server的软件包,已经成功删除。

 

小结:在这个问题解决之后,我思考了这么一个问题,当执行rpm -e来卸载一个软件包的时候,都做了些什么事情,找了好久,找到了如下的一些信息。

链接地址:http://ftp.rpm.org/max-rpm/ch-rpm-erase.html#S1-RPM-ERASE-WHAT-DOES-IT-DO

rpm -e — What Does it Do?

The rpm -e command (--erase is equivalent) removes, or erases, one or more packages from the system. RPM performs a series of steps whenever it erases a package:

    It checks the RPM database to make sure that no other packages depend on the package being erased.

    It executes a pre-uninstall script (if one exists).  #执行一个预先卸载脚本,比如,检查软件是否在运行,运行就将其停掉等等。%preun 就是预卸载脚本的意思。

    It checks to see if any of the package's config files have been modified. If so, it saves copies of them.

    It reviews the RPM database to find every file listed as being part of the package, and if they do not belong to another package, deletes them.

    It executes a post-uninstall script (if one exists).

    It removes all traces of the package (and the files belonging to it) from the RPM database. 

 另外,我也对自己解决问题的思路进行了一个调整,当你在解决一个问题的时候,如果想要更好的解决问题,那么最好的方式,就是对于你要操作的东西,有个基本工作原理的理解。看似很慢的理解工作原理,花费时间来思考,实则在解决问题时,却变得更加的容易,而不仅仅是搜索,搜索,搜索。

 

文档创建时间:2019年3月8日14:39:04

转载于:https://www.cnblogs.com/chuanzhang053/p/10495738.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值