問題描述:
今天在做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