linux centos7 换源和安装docker

  • 问题一

在刚下载安装完的centos7(minimal)后,想更换yum源,但是报错:-bash: wget: 未找到命令,
然后执行:sudo yum install wget,但是报错:
已加载插件:fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

解决方法-直接改 yum 源为固定地址

// linux 更换yum源
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' \
         -i.bak /etc/yum.repos.d/CentOS-Base.repo

更换完成后执行sudo yum install wget
然后执行
1、cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
2、wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/artifactory/os-conf/centos/centos-7.repo(这是把yum源更换为华为源)
3、执行yum clean all清除原有 yum 缓存
4、执行yum makecache(刷新缓存)或者yum repolist all(查看所有配置可以使用的文件,会自动刷新缓存)。
参考地址:[华为开源镜像站_软件开发服务_华为云](https://mirrors.huaweicloud.com/mirrorDetail/5ea14ecab05943f36fb75ee5?mirrorName=centos&catalog=os)

安装doker

参考文档:[Centos7上安装docker「建议收藏」-腾讯云开发者社区-腾讯云](https://cloud.tencent.com/developer/article/2053492)
1、使用 root 权限登录 Centos。确保 yum 包更新到最新。
   sudo yum update
2、卸载旧版本(如果安装过旧版本的话)
   sudo yum remove docker  docker-common docker-selinux docker-engine
3、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
   sudo yum install -y yum-utils device-mapper-persistent-data lvm2
4、设置yum源
   sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
5、安装docker
  执行一下命令,安装最新版本的 Docker Engine-Community 和 containerd。
  sudo yum install -y docker-ce docker-ce-cli containerd.io
  如果不需要docker-ce-cli或containerd.io可直接执行如下命令
  yum install -y docker-ce
6、启动并加入开机启动
   sudo systemctl start docker
   sudo systemctl enable docker
7、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
  docker version
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。