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

本文详细介绍了如何在CentOS系统中更换国内的yum源以提高下载速度,并通过实例演示了使用yum工具下载软件包的具体步骤。此外,还深入探讨了源码包安装的过程,包括安装Apache HTTP Server所需的准备步骤、配置、编译和安装等全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

yum更换国内源

进入目录 yum配置目录

[root@yolks1 ~]# cd /etc/yum.repos.d/
[root@yolks1 yum.repos.d]# ls
dvd.repo

删除原dvd源

[root@yolks1 yum.repos.d]# rm -f dvd.repo

拷贝回之前备份的.bak

root@yolks1 yum.repos.d]# ls /etc/yum.repos.d.bak/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@yolks1 yum.repos.d]# cp /etc/yum.repos.d.bak/* .
[root@yolks1 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo

删除核心的yum仓库文件CentOS-Base.repo

[root@yolks1 yum.repos.d]# rm -f CentOS-Base.repo
[root@yolks1 yum.repos.d]# ls
CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo
CentOS-Debuginfo.repo  CentOS-Media.repo      CentOS-Vault.repo

获取163yum源:wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 或者 curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo

[root@yolks1 yum.repos.d]# wget  http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2018-06-28 00:36:13--  http://mirrors.163.com/.help/CentOS7-Base-163.repo
正在解析主机 mirrors.163.com (mirrors.163.com)... 59.111.0.251
正在连接 mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1572 (1.5K) [application/octet-stream]
正在保存至: “CentOS7-Base-163.repo.1”

100%[===================================================>] 1,572       --.-K/s 用时 0s      

2018-06-28 00:36:13 (241 MB/s) - 已保存 “CentOS7-Base-163.repo.1” [1572/1572])

自带的 yum 源是国外的网站, 从国内下载国外的资源时会很慢, 所以弄一个国内的 yum 源很有必要

列出选项 yum list

......
zenity.x86_64                                   3.22.0-1.el7                        base     
zlib.i686                                       1.2.7-17.el7                        base     
zlib-devel.i686                                 1.2.7-17.el7                        base     
zlib-devel.x86_64                               1.2.7-17.el7                        base     
zlib-static.i686                                1.2.7-17.el7                        base     
zlib-static.x86_64                              1.2.7-17.el7                        base     
zsh.x86_64                                      5.0.2-28.el7                        base     
zsh-html.x86_64                                 5.0.2-28.el7                        base     
zziplib.i686                                    0.13.62-5.el7                       base     
zziplib.x86_64                                  0.13.62-5.el7                       base     
zziplib-devel.i686                              0.13.62-5.el7                       base     
zziplib-devel.x86_64                            0.13.62-5.el7                       base     
zziplib-utils.x86_64                            0.13.62-5.el7                       base

yum下载npm包

安装扩展源, 有时候文件在一个 yum 源找不到, 需要去扩展源里去找, epel, 实际上就是安装了一个文件 / etc/yum.repos.d/epel.repo

安装扩展源

[root@yolks1 yum.repos.d]# yum install -y epel-release

查看epel扩展源

yum list |grep epel

ls /var/cache/yum/x86_64/7/

仅仅下载包:yum install -y 包名 --downloadonly --downloaddir=路径

[root@yolks1 yum.repos.d]# yum install -y zsh --downloadonly
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.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:00     
exiting because "Download Only" specified

指定路径安装 : yum install package --downloadonly --downloaddir 指定路径安装

[root@yolks1 yum.repos.d]# yum install vim-enhanced --downloadonly --downloaddir =/tmp/
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
软件包 2:vim-enhanced-7.4.160-4.el7.x86_64 已安装并且是最新版本
无须任何处理

重新安装 : 因为这个包已经安装了, 所以在 /tmp/ 下没有显示, 碰到这种情况, 可以先卸载再去安装, 但是服务在用这个包时就不合适了, 可以采用 reinstall

[root@yolks1 yum.repos.d]# yum reinstall vim-enhanced --downloadonly --downloaddir =/tmp/
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: mirrors.tongji.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

查看/tmp/目录:可以看到有vim-enhanced的包

总用量 1152
lrwxrwxrwx 1 root root       3 6月   6 23:12 by123 -> 234
drwxr-xr-x 3 root root     143 6月  25 23:21 chapter6
-rw-r--r-- 1 root root    1218 6月  21 23:01 passwd.sh
drwxr-xr-x 3 root root      30 6月  25 22:50 study_zip
-rw-r--r-- 1 root root     984 6月  25 22:44 study_zip.zip
drwx------ 3 root root      17 6月  21 22:24 systemd-private-05dede71d73947899f17c7b16701d7bb-chronyd.service-sSEbWo
drwx------ 3 root root      17 6月  21 22:24 systemd-private-05dede71d73947899f17c7b16701d7bb-vgauthd.service-BP6aYc
drwx------ 3 root root      17 6月  21 22:24 systemd-private-05dede71d73947899f17c7b16701d7bb-vmtoolsd.service-SqsZUA
drwx------ 3 root root      17 6月  19 23:22 systemd-private-1a76b4473d434038aa8ff17c97e68f1d-chronyd.service-cRyE1F
drwx------ 3 root root      17 6月  19 23:22 systemd-private-1a76b4473d434038aa8ff17c97e68f1d-vgauthd.service-XfBLwr
drwx------ 3 root root      17 6月  19 23:22 systemd-private-1a76b4473d434038aa8ff17c97e68f1d-vmtoolsd.service-8oFrxU
drwx------ 3 root root      17 6月  18 23:20 systemd-private-1d1953de3de6479cb06ae04c3475f929-chronyd.service-yJ6IJZ
drwx------ 3 root root      17 6月  18 23:20 systemd-private-1d1953de3de6479cb06ae04c3475f929-systemd-hostnamed.service-nFtnEE
drwx------ 3 root root      17 6月  18 23:20 systemd-private-1d1953de3de6479cb06ae04c3475f929-vgauthd.service-8HpIIx
drwx------ 3 root root      17 6月  18 23:20 systemd-private-1d1953de3de6479cb06ae04c3475f929-vmtoolsd.service-FBbeI5
drwx------ 3 root root      17 6月  25 22:27 systemd-private-2482eb13f2c04de69cd259034431e02e-chronyd.service-aaUNpp
drwx------ 3 root root      17 6月  25 22:27 systemd-private-2482eb13f2c04de69cd259034431e02e-vgauthd.service-B4hbt2
drwx------ 3 root root      17 6月  25 22:27 systemd-private-2482eb13f2c04de69cd259034431e02e-vmtoolsd.service-IeDmWd
drwx------ 3 root root      17 6月  26 21:41 systemd-private-c3321e5433514784b5a99a7fd6a85c05-chronyd.service-AG23G9
drwx------ 3 root root      17 6月  26 21:41 systemd-private-c3321e5433514784b5a99a7fd6a85c05-vgauthd.service-AEDsRl
drwx------ 3 root root      17 6月  26 21:41 systemd-private-c3321e5433514784b5a99a7fd6a85c05-vmtoolsd.service-Wejn2x
drwx------ 3 root root      17 6月  27 23:33 systemd-private-e8a72b196ad54272ae2bd358049ae6af-chronyd.service-xWGEn3
drwx------ 3 root root      17 6月  27 23:33 systemd-private-e8a72b196ad54272ae2bd358049ae6af-vgauthd.service-Lh8ScG
drwx------ 3 root root      17 6月  27 23:33 systemd-private-e8a72b196ad54272ae2bd358049ae6af-vmtoolsd.service-0JcU7j
drwx------ 3 root root      17 6月  20 20:34 systemd-private-f74df1594788493287333d76d3f3b780-chronyd.service-5qF0BD
drwx------ 3 root root      17 6月  20 20:34 systemd-private-f74df1594788493287333d76d3f3b780-vgauthd.service-PPaqRA
drwx------ 3 root root      17 6月  20 20:34 systemd-private-f74df1594788493287333d76d3f3b780-vmtoolsd.service-o1qi7x
-rw-r--r-- 1 root root   26818 6月  21 23:33 test_new_file.txt
-rw-r--r-- 1 root root    9909 6月  25 22:38 test_new_file.txt.zip
-rw-r--r-- 1 root root   26832 6月  20 21:20 test_study_vim.conf
drwxr-xr-x 2 root root      31 6月  25 22:54 unzip
-rw-r--r-- 1 root root 1087452 4月  25 19:50 vim-enhanced-7.4.160-4.el7.x86_64.rpm
drwxr-xr-x 3 root root      15 6月   3 19:36 yolks
-rw------- 1 root root     235 6月  28 00:57 yum_save_tx.2018-06-28.00-57.thh7qo.yumtx
-rw------- 1 root root     244 6月  28 01:02 yum_save_tx.2018-06-28.01-02.loypJe.yumtx
-rw------- 1 root root     244 6月  28 01:06 yum_save_tx.2018-06-28.01-06.5k0nUl.yumtx

源码包

安装软件默认路径:/usr/local/src/

cd /usr/local/src/
 wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.32.tar.gz
 tar zxvf httpd-2.2.32.tar.gz
 cd httpd-2.2.32
 ./configure --prefix=/usr/local/apache2
 make
 make install
 卸载就是删除安装的文件 

像 LAMP 和 LNMP 采用的编译安装, 就是源码包安装, 以后源码包就放在 /usr/local/src/ 路径下

curl -O http://mirrors.sohu.com/apache/httpd-2.4.29.tar.gz;

解压后查看说明文档 README 或者 INSTALL

tar xzf httpd-2.4.29.tar.gz;  ls . ;  cd httpd-2.4.29/ ;   ls . 
httpd-2.4.29  httpd-2.4.29.tar.gz
ABOUT_APACHE     INSTALL         NWGNUmakefile     ap.d             docs         libhttpd.dep  support
Apache-apr2.dsw  InstallBin.dsp  README            apache_probes.d  emacs-style  libhttpd.dsp  test
Apache.dsw       LAYOUT          README.cmake      build            httpd.dep    libhttpd.mak
BuildAll.dsp     LICENSE         README.platforms  buildconf        httpd.dsp    modules
BuildBin.dsp     Makefile.in     ROADMAP           config.layout    httpd.mak    os
CHANGES          Makefile.win    VERSIONING        configure        httpd.spec   server
CMakeLists.txt   NOTICE          acinclude.m4      configure.in     include      srclib

more ReadMe : 查看ReadMe

                        Apache HTTP Server

  What is it?
  -----------

  The Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant
  web server.  Originally designed as a replacement for the NCSA HTTP
  Server, it has grown to be the most popular web server on the
  Internet.  As a project of the Apache Software Foundation, the
  developers aim to collaboratively develop and maintain a robust,
  commercial-grade, standards-based server with freely available
  source code.

  The Latest Version
  ------------------

  Details of the latest version can be found on the Apache HTTP
  server project page under http://httpd.apache.org/.

  Documentation
  -------------

  The documentation available as of the date of this release is

more INSTALL

APACHE INSTALLATION OVERVIEW

  Quick Start - Unix
  ------------------

  For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.4/install.html

     $ ./configure --prefix=PREFIX
     $ make
     $ make install
     $ PREFIX/bin/apachectl start

源码包安装时可以通过 ./configure --help 查看安装时的参数

./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/apache2]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/apache2/bin', `/usr/local/apache2/lib' etc.  You can specify
an installation prefix other than `/usr/local/apache2' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
.......

初始化, 发觉不行, 可以在执行后的下一步(不要选在下下步) echo $? 来查看初始化以及 make & make install 是否 ok , echo $? 返回的是 0 就表示 OK, 如果 非 0 就表示 失败

./configure --prefix=/usr/local/apache2
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... no
configure: error: APR not found.  Please read the documentation.

echo $? 1 如下显示的是上一步操作 OK , 不是上上步

安装需要的包, apr 是 Configuring Apache Portable Runtime library 需要的, 而 gcc 是编译安装必须的一个工具

yum install -y apr; yum install -y gcc

再次初始化也不行

./configure --prefix=/usr/local/apache2
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... no
configure: error: APR not found.  Please read the documentation.

但是不行, 需要这样操作, 参考网址: https://blog.youkuaiyun.com/superbirds/article/details/52373102

下载两个包 ( apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植)

wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz;wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
mv apr-1.6.3.tar.gz ../ ; mv apr-util-1.6.1.tar.gz ../ ; ls ../
apr-1.6.3.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.29  httpd-2.4.29.tar.gz 

解压并安装他们

cd ../ ; tar zxf apr-1.6.3.tar.gz ; tar zxf apr-util-1.6.1.tar.gz ; ls 
apr-1.6.3  apr-1.6.3.tar.gz  apr-util-1.6.1  apr-util-1.6.1.tar.gz  httpd-2.4.29  httpd-2.4.29.tar.gz

初始化 apr-1.6.3

cd apr-1.6.3; ./configure --prefix=/usr/local/apr

出现了如下的错误, 网上的解决方案: https://blog.youkuaiyun.com/u013281361/article/details/51896740

"解决如上错误的方案"

30375 RM='$RM'

查找包, 这个包没有安装成功, 不过这个包不装也没有关系

yum provides "/*/libtool"
libtool-2.4.2-22.el7_3.x86_64 : The GNU Portable Library Tool
Repo        : base
Matched from:
Filename    : /usr/bin/libtool
Filename    : /usr/share/libtool 

重新初始化 apr

./configure --prefix=/usr/local/apr

编译, 安装 apr

make && make install

初始化 apr-util

cd ../apr-util-1.6.1/ ; ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

出现如下错误, expat.h: No such file or directory

xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
 #include <expat.h>
                   ^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/src/apr-util-1.6.1'
make: *** [all-recursive] Error 1
yum provides "/*/expat.h" 
......
expat-devel-2.1.0-10.el7_3.x86_64 : Libraries and header files to develop applications using expat
Repo        : base
Matched from:
Filename    : /usr/include/expat.h
......

安装包 expat-devel

yum install -y expat-devel

继续编译安装 apr-util

make && make install

安装 httpd

cd httpd-2.4.29/ ; ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --w
ith-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most 

.......

如下的错误要去安装包

checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

查找 文件 pcre-config 的包

pcre-devel-8.32-17.el7.x86_64 : Development files for pcre
Repo        : base
Matched from:
Filename    : /usr/bin/pcre-config
yum install -y pcre-devel

继续初始化 httpd

cd httpd-2.4.29/ ; ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most 

编辑安装 httpd

make && make install 

在编译时出现问题要解决这些问题, 查看日志文件, 写的参数, 在网上查找等等 查看生成的文件

ls /usr/local/apache2/
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules 

卸载就是在没有做其他操作前删除安装的目录就可以了,

且安装时要从可靠的站点去下载

转载于:https://my.oschina.net/yolks/blog/1836750

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值