更换国内的yum源

备份原yum文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载新的CentOS-Base.repo 到/etc/yum.repos.d/

CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

之后运行yum makecache生成缓存

yum下载安装包 安装扩展yum源

yum install -y epel-release yum list |grep epel

查看下epel的yum配置文件

[root@localhost yum.repos.d]# cat epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

yum下载安装的rpm包

使用yum install 包名 --downloadonly --downloaddir=/usr/local/src/tmp/ --downloaddir 是指定下载到的目录,如果不加此参数,下载的rpm包会保存在/var/cache/yum/x86_64/7/updates/packages/目录下

[root@localhost tmp]# yum install zsh --downloadonly --downloaddir=/usr/local/src/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.aliyun.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-28.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================
 Package 架构 版本 源 大小
=======================================================================================
正在安装:
 zsh x86_64 5.0.2-28.el7 base 2.4 M

事务概要
=======================================================================================
安装 1 软件包

总下载量:2.4 M
安装大小:5.6 M
Background downloading packages, then exiting:
zsh-5.0.2-28.el7.x86_64.rpm | 2.4 MB 00:00:01     
exiting because "Download Only" specified
[root@localhost tmp]# ls
 zsh-5.0.2-28.el7.x86_64.rpm

这个方法只能下载未安装的yum包,如需下载已安装包,使用yumreinstall下载yum源的安装包,如

[root@localhost tmp]# yum reinstall -y vim --downloadonly --downloaddir=/usr/local/src/tmp
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.aliyun.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 vim-enhanced.x86_64.2.7.4.160-4.el7 将被 已重新安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================
 Package 架构 版本 源 大小
=======================================================================================
重新安装:
 vim-enhanced x86_64 2:7.4.160-4.el7 base 1.0 M

事务概要
=======================================================================================
重新安装 1 软件包

总下载量:1.0 M
安装大小:2.2 M
Background downloading packages, then exiting:
vim-enhanced-7.4.160-4.el7.x86_64.rpm | 1.0 MB 00:00:00     
exiting because "Download Only" specified
[root@localhost tmp]# ls
vim-enhanced-7.4.160-4.el7.x86_64.rpm

可以配置yum保留已经下载的rpm包,供以后升级或重新安装时使用,修改/etc/yum.conf

[main]
cachedir=/home/xiang/yumcache
keepcache=1
debuglevel=2

chchedir是保存下载包的路径。可以修改为自己定义的路径 keepcache为1时表示保存已经下载的rpm包

源码包编译安装

这里以apache的web服务器软件作为示范,首先下载apache:

[root@localhost src]# wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.33.tar.gz
--2018-06-27 11:31:02-- http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.33.tar.gz
正在解析主机 mirrors.hust.edu.cn (mirrors.hust.edu.cn)... 202.114.18.160
正在连接 mirrors.hust.edu.cn (mirrors.hust.edu.cn)|202.114.18.160|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9076901 (8.7M) [application/octet-stream]
正在保存至: “httpd-2.4.33.tar.gz”
100%[================================================================================>] 9,076,901 86.0KB/s 用时 1m 43s 
2018-06-27 11:32:46 (86.0 KB/s) - 已保存 “httpd-2.4.33.tar.gz” [9076901/9076901])

解压打包压缩的文件,使用./configure 编译安装 --prefix=则是指定安装的一个路径

[root@localhost src]# tar zxf httpd-2.4.33.tar.gz -C .
[root@localhost src]# cd httpd-2.4.33/
[root@localhost httpd-2.4.33]# ./configure --prefix=/usr/local/httpd
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to " -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
.........................
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:

    Server Version: 2.4.33
    Install prefix: /usr/local/httpd
    C compiler: gcc -std=gnu99
    CFLAGS: -pthread  
    CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@localhost httpd-2.4.33]# echo $?
0                      echo $? 查看上次执行结果,为0表示正确,为1表示错误

编译中会有报错,比如

checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

上面的信息中提示了pcre-config for libpcre这个包的信息,一般判断安装pcre和pcre-devel这些名称的安装包就可以继续编译了,并且编译安装成功

apr报错,yum安装了apr还不行,版本过低的问题。。。这属于版本依赖问题 只能在官网下载apr和apr-util的源码包,先./configure 安装apr,安装到/usr/local/apr目录下

./configure --prefix=/usr/local/apr/;make;make install

其后安装apr-util时还需要指定apr的安装路径

./configure --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr;make;make install

随后编译安装apache时指定apr和apr-util的安装路径,./configure时需要添加编译参数

./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr  --with-apr-util=/usr/local/apr-util;make;make install

源码包卸载直接可以删除指定安装的目录即可,因为我们安装的时候所指定的路径就是软件安装时所有文件存在的地方,删除即代表卸载掉