yum更换国内源、yum下载rpm包、源码包安装

7.6yum更换国内源
当自带的yum仓库慢,把之前的仓库改名字,安装新的
安装扩展源epel
yum install -y epel-release 直接安装上就可以
yum list | grep epel
 

7.7yum下载rpm包
--downloadonly 只下载不安装
--downloadfdir= 放在哪个目录下
yum reinstall 重新安装,不会出现因为卸载导致启动的服务停止
 

7.8/7.9源码包安装
源码包统一放在 /usr/local/src/
wget 后面跟源码包地址直接下载
echo $? 可以测试上一条命令是否正常 0为正常
安装第一步 ./configure --prefix=/usr/local/apache2 指定安装路径
安装第二步 make 出现安装问题,想办法解决
安装第三步 make install
源码包尽量在官网下载
 

扩展:yum更新源优先级设置
1.安装 yum-priorities
yum install yum-priorities
 
2.priorities的配置文件是/etc/yum/pluginconf.d/priorities.conf,确认其是否存在。
其内容为:
[main]
enabled=1 # 0禁用 1启用
 
3.编辑 /etc/yum.repos.d/目录下的*.repo 文件来设置优先级。
参数为:
priority=N # N的值为1-99
推荐的设置为:
[base], [addons], [updates], [extras] … priority=1
[centosplus],[contrib] … priority=2
Third Party Repos such as rpmforge … priority=N (where N is > 10 and based on your preference)
数字越大,优先级越低
 

扩展:简单制作rpm二进制包
有好多朋友问到怎么制作rpm包,可不可把其它服务器上编译好的软件目录复杂到其它服务器上直接应用等等。。。这里做个简单的介绍,高级复杂的不会。
此方法是通过编写spec文件,使用rpmbuild来完成一个rpm的打包。
以nginx为例进行介绍
制作平台:CentOS 5.x X86_64
四步走:
第一步:建立目录结构
mkdir /usr/src/RedHat/{SOURCES,SPECS,BUILD,RPMS,SRPMS} -p
相关目录介绍:
  1. /usr/src/redhat/SOURCES #存放源代码、补丁等文件
  2. /usr/src/redhat/SPECS #存放用于管理rpm制作进程的spec文件
  3. /usr/src/redhat/BUILD #解压后的文件存放目录
  4. /usr/src/redhat/RPMS #存放由rpmbuild制作好的二进制包
  5. /usr/src/redhat/SRPMS #存放由rpmbuild制作好的源码包
第二步:把源码包放在SOURCES目录下
cd /usr/src/redhat/SOURCES
wget http://nginx.org/download/nginx-1.2.0.tar.gz
 
第三步:生成nginx.spec文件
 
  1. cd /usr/src/redhat/SPECS
  2. cat nginx.spec
  3. #
  4. # spec file for nginx
  5. # Build 2012-07-17
  6. # By opsren
  7. #
  8. Summary: High performance web server
  9. Name: Nginx
  10. Version: 1.2
  11. Release: 0.el5.ngx
  12. License: 2-clause BSD-like license
  13. Group: Applications/Server
  14. Source: http://nginx.org/download/nginx-1.2.0.tar.gz
  15. URL: http://nginx.org
  16. Distribution: Centos/Redhat
  17. Packager: qiuzhijun <250621008@qq.com>
  18. %description
  19. Nginx ("engine x") is a high performance HTTP and reverse proxy server, as well as a mail(IMAP/POP3/SMTP) proxy server.
  20. %prep
  21. tar zxf $RPM_SOURCE_DIR/nginx-1.2.0.tar.gz
  22. %build
  23. cd nginx-1.2.0
  24. ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid
  25. make
  26. %install
  27. cd nginx-1.2.0
  28. make install
  29. %preun
  30. if [ -z "`ps aux | grep nginx | grep -v grep`" ];then
  31. pkill nginx >/dev/null
  32. exit 0
  33. fi
  34. %files
  35. /usr/local/webserver/nginx
 
第四步:RPM包制作
首先系统要安装好必备的制作工具:gcc、rpmbuild等
  1. yum -y install gcc rpm-build pcre-devel
  2. cd /usr/src/redhat/SPECS/
  3. rpmbuild -bb nginx.spec
通过上面这条命令,会在/usr/src/redhat/RPMS/x86_64/下面生成nginx-1.2.0-1.el5.ngx.x86_64.rpm这个文件
 
-bb 这个选项就是制作二进制包(build binary package only from <specfile>)
 
对spec文件内容进行简单说明:
spec文件是制作rpm包的核心!
  1. 以#开头的是注释信息;
  2. Summary:对相关软件进行简单描述说明
  3. Name:定义rpm包的名称
  4. Version:定义软件的版本号
  5. Release:发行版本
  6. License:定义许可证
  7. Group:说明软件属于哪种应用类型
  8. Source:软件源码下载地址
  9. URL:软件相关官方站点
  10. Distribution: 发行版系列
  11. Packager: 制作人的简单信息
  12. %description:软件详细描述信息
  13. %prep:软件编译之前的处理
  14. %build:编译软件
  15. %install:安装软件
  16. %preun:定义卸载之前的动作
  17. %files:指定要打包的软件包,这里是/usr/local/webserver/nginx
 
对于更详细的说明请参考官方资料:http://www.rpm.org/max-rpm/ch-rpm-inside.html
 
下面是apache的spec文件实例:
  1. #
  2. # spec file for apache
  3. # Build 2012-07-17
  4. # By opsren
  5. #
  6. Summary: High stability web server
  7. Name: Apache
  8. Version: 2.2
  9. Release: 22.el5
  10. License: 2-clause BSD-like license
  11. Group: Applications/Server
  12. Source: http://apache.etoak.com/httpd/httpd-2.2.22.tar.gz
  13. URL: http://apache.org
  14. Distribution: Centos/Redhat
  15. Packager: qiuzhijun <250621008@qq.com>
  16. %description
  17. Apache is a first web server
  18. %prep
  19. tar zxf $RPM_SOURCE_DIR/httpd-2.2.22.tar.gz
  20. %build
  21. cd httpd-2.2.22
  22. ./configure --prefix=/usr/local/webserver/apache --enable-so --enable-deflate --enable-headers --enable-mods-shared=all --enable-rewrite
  23. make
  24. %install
  25. cd httpd-2.2.22
  26. make install
  27. %preun
  28. if [ -z "`ps aux | grep httpd | grep -v grep`" ];then
  29. pkill httpd >/dev/null
  30. exit 0
  31. fi
  32. %files
  33. /usr/local/webserver/apache
以后对于相同或类似平台可以到其它服务器上进行rpm安装部署。
 
另外还有一种rpm打包的方法:rpm_create
这是一种新的打rpm的工具,不用spec语言,只需要会简单的shell命令,即可完成打包操作,非常方便,结合了spec语言和checkinstall,相比spec方法要简单很多!
 
官方站点:http://code.google.com/p/rpmcreate/
下载站点:wget http://rpmcreate.googlecode.com/files/rpm_create-1.7.5-9.x86_64.rpm
大家可以去官方站点参考!
原文地址:https://www.cnblogs.com/0329linux/p/7083397.html