一、RPM包的管理 www.2cto.com
rpm软件包的一个例子:
sudo-1.7.4p5-11.el6.i686.rpm
其中包括软件名(sudo),版本号(1.7.4p5),发行号(11.el6)和硬件平台(i686)
1、卸载
[root@localhost ~]# rpm -e sudo
如果其它软件包有依赖关系,卸载时会产生提示信息,可以使用--nodeps强行卸载
[root@localhost ~]# rpm -e --nodeps samba
2、安装
光盘里面带有的软件包,可以直接从光盘安装
1)挂载光盘
[root@localhost ~]# mkdir /mnt/cdrom [root@localhost ~]# mount /dev/cdrom /mnt/cdrom mount: block device /dev/sr0 is write-protected, mounting read-only [root@localhost ~]#
2)rpm的安装包都放在Packages目录中
[
root@localhost ~]# cd /mnt/cdrom [root@localhost cdrom]# ls CentOS_BuildTag Packages RPM-GPG-KEY-CentOS-Security-6 EULA RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Testing-6 GPL repodata TRANS.TBL images RPM-GPG-KEY-CentOS-6 isolinux RPM-GPG-KEY-CentOS-Debug-6 [root@localhost cdrom]#
3)找到sudo的安装包
[root@localhost cdrom]# cd Packages [root@localhost Packages]# ls | grep sudo sudo-1.7.4p5-11.el6.i686.rpm [root@localhost Packages]#
4)执行安装
[root@localhost Packages]# rpm -ivh sudo-1.7.4p5-11.el6.i686.rpm warning: sudo-1.7.4p5-11.el6.i686.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:sudo ########################################### [100%] [root@localhost Packages]#
5)查询软件包是否已安装
[root@localhost Packages]# rpm -q sudo sudo-1.7.4p5-11.el6.i686 [root@localhost Packages]#
没有安装的会给出提示
[root@localhost ~]# rpm -q samba package samba is not installed [root@localhost ~]#
6)--excludedocs 不安装软件包中的文档文件
[root@localhost Packages]# rpm -ivh --excludedocs sudo-1.7.4p5-11.el6.i686.rpm
7)--prefix PATH 将软件包安装到由PATH指定的路径下
[root@localhost Packages]# rpm -ivh --prefix=/usr/local/sudo sudo-1.7.4p5-11.el6.i686.rpm
不过指定rpm包的安装路径意义不大,rpm一般都不允许改变安装目录,rpm包在设计的时候就已经指定好相应的安装目录了 www.2cto.com
8)--test 只对安装进行测试,并不实际安装
[root@localhost Packages]# rpm -ivh --test sudo-1.7.4p5-11.el6.i686.rpm
9)软件包已被安装
[root@localhost Packages]# rpm -ivh sudo-1.7.4p5-11.el6.i686.rpm warning: sudo-1.7.4p5-11.el6.i686.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] package sudo-1.7.4p5-11.el6.i686 is already installed [root@localhost Packages]#
如果要覆盖安装该软件包,可以使用--replacepkgs选项
[root@localhost Packages]# rpm -ivh --replacepkgs sudo-1.7.4p5-11.el6.i686.rpm warning: sudo-1.7.4p5-11.el6.i686.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Preparing... ########################################### [100%] 1:sudo ########################################### [100%] [root@localhost Packages]#
10)文件冲突
如果要安装的软件包中有一个文件已在安装其它软件包是安装了,就会出现文件冲突,可以使用--replacefiles选项
[root@localhost Packages]# rpm -ivh --replacefiles sudo-1.7.4p5-11.el6.i686.rpm
11)未解决依赖关系
RPM软件包可能依赖于其它软件包,在安装了依赖的软件包之后才能安装该软件包。强制安装使用--nodeps选项,如果依赖包没安装,强制安装的软件一般用不了。
3、升级
比如升级到 sudo-1.8.0p5-11.el6.i686.rpm
[root@localhost Packages]# rpm -Uvh sudo-1.8.0p5-11.el6.i686.rpm
二、YUM包管理
应用yum包的好处:
自动解决软件包依赖关系
方便的软件包升级
1、安装 yum install (需要网络访问)
[
root@bogon ~]# yum install sudoLoaded plugins: fastestmirror, securityDetermining fastest mirrors* base: mirror.neu.edu.cn* extras: mirror.neu.edu.cn* updates: mirror.neu.edu.cnbase | 3.7 kB 00:00base/primary_db | 3.5 MB 00:07extras | 3.5 kB 00:00extras/primary_db | 24 kB 00:00updates | 3.5 kB 00:00updates/primary_db | 3.8 MB 00:08Setting up Install ProcessResolving Dependencies--> Running transaction check---> Package sudo.i686 0:1.7.4p5-13.el6_3 will be installed--> Finished Dependency Resolution Dependencies Resolved ================================================================================Package Arch Version Repository Size================================================================================Installing:sudo i686 1.7.4p5-13.el6_3 updates 419 k Transaction Summary================================================================================Install 1 Package(s) Total download size: 419 kInstalled size: 1.0 MIs this ok [y/N]: yDownloading Packages:sudo-1.7.4p5-13.el6_3.i686.rpm | 419 kB 00:01warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEYRetrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6Importing GPG key 0xC105B9DE:Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>Package: centos-release-6-3.el6.centos.9.i686 (@anaconda-CentOS-201207051201.i386/6.3)From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6Is this ok [y/N]: yRunning rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionWarning: RPMDB altered outside of yum. Installing : sudo-1.7.4p5-13.el6_3.i686 1/1 Verifying : sudo-1.7.4p5-13.el6_3.i686 1/1 Installed: sudo.i686 0:1.7.4p5-13.el6_3 Complete![root@bogon ~]#
2、检测升级 yum check-update
[
root@bogon ~]# yum check-update sudo Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile * base: mirror.neu.edu.cn * extras: mirror.neu.edu.cn * updates: mirror.neu.edu.cn [root@bogon ~]#
3、升级 yum update
[root@bogon ~]# yum update sudo Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile * base: mirror.neu.edu.cn * extras: mirror.neu.edu.cn * updates: mirror.neu.edu.cn Setting up Update Process No Packages marked for Update [root@bogon ~]#
4、软件包查询yum list
[root@bogon ~]# yum list | grep sudo sudo.i686 1.7.4p5-13.el6_3 @updates [root@bogon ~]#
5、软件包信息yum info
[root@bogon ~]# yum info sudo Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile * base: mirror.neu.edu.cn * extras: mirror.neu.edu.cn * updates: mirror.neu.edu.cn Installed Packages Name : sudo Arch : i686 Version : 1.7.4p5 Release : 13.el6_3 Size : 1.0 M Repo : installed From repo : updates
Summary : Allows restricted root access for specified users URL : http://www.courtesan.com/sudo/ License : ISC Description : Sudo (superuser do) allows a system administrator to give certain : users (or groups of users) the ability to run some (or all) : commands as root while logging all commands and arguments. Sudo : operates on a per-command basis. It is not a replacement for the : shell. Features include: the ability to restrict what commands a : user may run on a per-host basis, copious logging of each command : (providing a clear audit trail of who did what), a configurable : timeout of the sudo command, and the ability to use the same : configuration file (sudoers) on many different machines.
6、卸载 yum remove
[root@bogon ~]# yum remove sudoLoaded plugins: fastestmirror, securitySetting up Remove ProcessResolving Dependencies--> Running transaction check---> Package sudo.i686 0:1.7.4p5-13.el6_3 will be erased--> Finished Dependency Resolution Dependencies Resolved ================================================================================Package Arch Version Repository Size================================================================================Removing:sudo i686 1.7.4p5-13.el6_3 @updates 1.0 M Transaction Summary================================================================================Remove 1 Package(s) Installed size: 1.0 MIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Erasing : sudo-1.7.4p5-13.el6_3.i686 1/1 Verifying : sudo-1.7.4p5-13.el6_3.i686 1/1 Removed: sudo.i686 0:1.7.4p5-13.el6_3 Complete!
[root@bogon ~]#
7、帮助yum -help、man yum
三、RPM查询应用案例
1、查询文件隶属的软件包 rpm -qf
[root@bogon ~]# rpm -qf /etc/services setup-2.8.14-16.el6.noarch [root@bogon ~]# rpm -qf /bin/ls coreutils-8.4-19.el6.i686 [root@bogon ~]#
2、查询软件包信息 rpm -qi、rpm -qip(查询还未安装的软件包)
[root@bogon ~]# rpm -qi sudo Name : sudo Relocations: (not relocatable) Version : 1.7.4p5 Vendor: CentOS Release : 13.el6_3 Build Date: 2012年08月06日 星期一 22时43分51秒 Install Date: 2012年12月15日 星期六 15时24分40秒 Build Host: c6b7.bsys.dev.centos.org Group : Applications/System Source RPM: sudo-1.7.4p5-13.el6_3.src.rpm Size : 1078427 License: ISC Signature : RSA/SHA1, 2012年08月06日 星期一 23时31分02秒, Key ID 0946fca2c105b9de Packager : CentOS BuildSystem <http://bugs.centos.org> URL : http://www.courtesan.com/sudo/ Summary : Allows restricted root access for specified users Description : Sudo (superuser do) allows a system administrator to give certain users (or groups of users) the ability to run some (or all) commands as root while logging all commands and arguments. Sudo operates on a per-command basis. It is not a replacement for the shell. Features include: the ability to restrict what commands a user may run on a per-host basis, copious logging of each command (providing a clear audit trail of who did what), a configurable timeout of the sudo command, and the ability to use the same configuration file (sudoers) on many different machines.
3、查询软件包安装文件rpm -ql、rpm -qlp(查询还未安装的软件包)
[root@bogon ~]# rpm -ql sudo /etc/pam.d/sudo /etc/pam.d/sudo-i /etc/sudo-ldap.conf /etc/sudoers /etc/sudoers.d /usr/bin/sudo /usr/bin/sudoedit /usr/bin/sudoreplay /usr/libexec/sesh /usr/libexec/sudo_noexec.so /usr/sbin/visudo /usr/share/doc/sudo-1.7.4p5 /usr/share/doc/sudo-1.7.4p5/ChangeLog /usr/share/doc/sudo-1.7.4p5/HISTORY /usr/share/doc/sudo-1.7.4p5/LICENSE /usr/share/doc/sudo-1.7.4p5/NEWS /usr/share/doc/sudo-1.7.4p5/README /usr/share/doc/sudo-1.7.4p5/README.LDAP /usr/share/doc/sudo-1.7.4p5/TROUBLESHOOTING /usr/share/doc/sudo-1.7.4p5/UPGRADE /usr/share/doc/sudo-1.7.4p5/sample.pam /usr/share/doc/sudo-1.7.4p5/sample.sudoers /usr/share/doc/sudo-1.7.4p5/sample.syslog.conf /usr/share/doc/sudo-1.7.4p5/schema.ActiveDirectory /usr/share/doc/sudo-1.7.4p5/schema.OpenLDAP /usr/share/doc/sudo-1.7.4p5/schema.iPlanet /usr/share/doc/sudo-1.7.4p5/sudoers2ldif /usr/share/man/man5/sudoers.5.gz /usr/share/man/man5/sudoers.ldap.5.gz /usr/share/man/man8/sudo.8.gz /usr/share/man/man8/sudoedit.8.gz /usr/share/man/man8/sudoreplay.8.gz /usr/share/man/man8/visudo.8.gz /var/db/sudo
4、查询软件包帮助文档rpm -qd
[root@bogon ~]# rpm -qd sudo /usr/share/doc/sudo-1.7.4p5/ChangeLog /usr/share/doc/sudo-1.7.4p5/HISTORY /usr/share/doc/sudo-1.7.4p5/LICENSE /usr/share/doc/sudo-1.7.4p5/NEWS /usr/share/doc/sudo-1.7.4p5/README /usr/share/doc/sudo-1.7.4p5/README.LDAP /usr/share/doc/sudo-1.7.4p5/TROUBLESHOOTING /usr/share/doc/sudo-1.7.4p5/UPGRADE /usr/share/doc/sudo-1.7.4p5/sample.pam /usr/share/doc/sudo-1.7.4p5/sample.sudoers /usr/share/doc/sudo-1.7.4p5/sample.syslog.conf /usr/share/doc/sudo-1.7.4p5/schema.ActiveDirectory /usr/share/doc/sudo-1.7.4p5/schema.OpenLDAP /usr/share/doc/sudo-1.7.4p5/schema.iPlanet /usr/share/doc/sudo-1.7.4p5/sudoers2ldif /usr/share/man/man5/sudoers.5.gz /usr/share/man/man5/sudoers.ldap.5.gz /usr/share/man/man8/sudo.8.gz /usr/share/man/man8/sudoedit.8.gz /usr/share/man/man8/sudoreplay.8.gz /usr/share/man/man8/visudo.8.gz
5、查询软件包配置文件
[root@bogon ~]# rpm -qc sudo /etc/pam.d/sudo /etc/pam.d/sudo-i /etc/sudo-ldap.conf /etc/sudoers [root@bogon ~]#
6、校验
[root@bogon tutor]# rpm -V sudo [root@bogon tutor]#
如果没有任何内容显示,说明sudo这个软件没有被改变过
7、软件包文件提取
比如不小心把/etc/inittab文件删除了,需要从软件包中重新提取恢复
1)先查找/etc/inittab这个文件属于哪个软件包
[root@bogon backup]# rpm -qf /etc/inittab initscripts-9.03.31-2.el6.centos.i686 [root@bogon backup]#
2)从软件包中解压/etc/inittab文件到当前目录
root@bogon backup]# rpm2cpio /mnt/cdrom/Packages/initscripts-9.03.31-2.el6.centos.i686.rpm | cpio -idv ./etc/inittab ./etc/inittab 11182 块 [root@bogon backup]# ls etc [root@bogon backup]# ls etc inittab [root@bogon backup]#
3)然后从当前目录复制到/etc/inittab
[root@bogon backup]# cp etc/inittab /etc/inittab
四、源代码包安装
以安装proftpd为例子:
1)解压解包
[root@bogon softs]# ls
proftpd-1.3.4b.tar.gz
[root@bogon softs]# tar -xzvf proftpd-1.3.4b.tar.gz
2)进入解压后的目录
[root@bogon softs]# cd proftpd-1.3.4b
[root@bogon proftpd-1.3.4b]#
3)先看看这个源码包中的文件
[root@bogon proftpd-1.3.4b]# ls
acconfig.h include README README.PAM
aclocal.m4 INSTALL README.AIX README.ports
ChangeLog install-sh README.capabilities README.Solaris2.5x
config.guess lib README.classes README.Unixware
config.h.in locale README.controls RELEASE_NOTES
config.sub ltmain.sh README.cygwin sample-configurations
configure m4 README.DSO src
configure.in Makefile.in README.facl stamp-h.in
contrib Make.rules.in README.FreeBSD tests
COPYING modules README.IPv6 utils
CREDITS NEWS README.LDAP
doc proftpd.spec README.modules
[root@bogon proftpd-1.3.4b]#
可以看到里面有一个源码包典型的可以执行文件 configure
4)配置
[root@bogon proftpd-1.3.4b]# ./configure --prefix=/usr/local/proftpd
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: no acceptable C compiler found in $PATH
See `config.log‘ for more details.
[root@bogon proftpd-1.3.4b]#
./configure 在当前目录下执行
--prefix 指定安装目录
执行上述的配置命令后,出现错误,没有找到c编译器
使用yum安装gcc编译器,可以方便的解决gcc依赖的问题
[root@bogon proftpd-1.3.4b]#yum install gcc
安装好gcc编译器之后,重新执行配置
[root@bogon proftpd-1.3.4b]# ./configure --prefix=/usr/local/proftpd
5)编译
[root@bogon proftpd-1.3.4b]# make
把源代码编译成可执行文件
6)安装
[root@bogon proftpd-1.3.4b]# make install
五、脚本安装
以安装webmin为例子:
1)解压解包
[root@bogon softs]# tar -xzvf webmin-1.610.tar.gz
2)进入解压目录
[root@bogon softs]# cd webmin-1.610
3)可以查看一下README文件,路面有安装方式的说明
[root@bogon webmin-1.610]# more README
4)执行脚本安装
[root@bogon webmin-1.610]# ./setup.sh
安装过程会有一些交互,安装目录、日志文件存放目录、设置用户名密码之类的
[root@bogon webmin-1.610]# ./setup.sh
***********************************************************************
* Welcome to the Webmin setup script, version 1.610 *
***********************************************************************
Webmin is a web-based interface that allows Unix-like operating
systems and common Unix services to be easily administered.
Installing Webmin in /softs/webmin-1.610 ...
***********************************************************************
Webmin uses separate directories for configuration files and log files.
Unless you want to run multiple versions of Webmin at the same time
you can just accept the defaults.
Config file directory [/etc/webmin]:
Log file directory [/var/webmin]:
***********************************************************************
Webmin is written entirely in Perl. Please enter the full path to the
Perl 5 interpreter on your system.
Full path to perl (default /usr/bin/perl):
Testing Perl ...
Perl seems to be installed ok
***********************************************************************
Operating system name: CentOS Linux
Operating system version: 6.3
***********************************************************************
Webmin uses its own password protected web server to provide access
to the administration programs. The setup script needs to know :
- What port to run the web server on. There must not be another
web server already using this port.
- The login name required to access the web server.
- The password required to access the web server.
- If the webserver should use SSL (if your system supports it).
- Whether to start webmin at boot time.
Web server port (default 10000):
Login name (default admin):
Login password:
Password again:
The Perl SSLeay library is not installed. SSL not available.
Start Webmin at boot time (y/n): n
***********************************************************************
Creating web server config files..
..done
安装完成我们就看见在远程用浏览器登录来管理服务器了
webmin是一个非常强大基于Web的Unix/Linux系统管理工具
原文地址:http://10793128.blog.51cto.com/10783128/1839696