centos7在2024年6月30日,生命周期结束,官方不再进行支持维护,官方的YUM源也下线了,下线的方式是使yum的域名不解析。所以现在需要配置国内的YUM源
今天新建了个centos7的虚拟机发现yum无法正常使用
已加载插件: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:
Contact the upstream for the repository and get them to fix the problem.
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).
Run the command with the repository temporarily disabled
yum --disablerepo= …
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
or
subscription-manager repos --disable=
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=.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64
解决:sudo vi /etc/yum.repos.d/CentOS-Base.repo
将CentOS-Base.repo里的内容全部替换为:
# CentOS-Base.repo
#
# 这里配置了CentOS的yum源,使用了阿里云和清华大学的镜像点。
#
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# 使用failovermethod指定优先级,这里设置为随机(roundrobin),也可以改为priority并指定每个URL的优先级
failovermethod=roundrobin
- 清理YUM缓存并更新
sudo yum clean all
sudo yum makecache
sudo yum update
Centos7 停止维护之后 升级gcc||找不到devtoolset-8-gcc* 问题解决方案
为了去小米澎湃互联组,感觉必须得拿下linux网络编程,今天第一步这个centos就给我拉了坨大的
问题实质
SCL源没换,相信你也在别的教程上看到要安装centos-release-scl吧?有坑!
安装完成后在 /etc/yum.repos.d 目录下会出现 CentOS-SCLo-scl.repo 和 CentOS-SCLo-scl-rh.repo 两个文件,安装后源默认启用,问题就在这两个文件上。
解决方案
修改CentOS-SCLo-scl.repo
vi /etc/yum.repos.d/CentOS-SCLo-scl.repo |
修改此部分的baseurl
[centos-sclo-sclo] | |
name=CentOS-7 - SCLo sclo | |
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/ | |
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo | |
gpgcheck=0 | |
enabled=1 | |
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo |
修改CentOS-SCLo-scl-rh.repo
vi /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo |
修改此部分的baseurl
[centos-sclo-rh] | |
name=CentOS-7 - SCLo rh | |
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/ | |
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh | |
gpgcheck=0 | |
enabled=1 | |
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo |
刷新缓存
yum repolist | |
yum clean all | |
yum makecache |
FAQ
-
报错Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64
检查那两个文件里的url是不是正确,运行yum repolist
检查是不是有centos-sclo-rh
和centos-sclo-sclo
如果没有上面这两个,运行一下yum install centos-release-scl*
,会生成默认的两个文件,在/etc/yum.repos.d/文件夹下可以找到这两个文件 -
仍然报错No package devtoolset-8-gcc* available
运行yum clean all
,然后运行yum makecache
在 centos 上安装配置 C++11 教程_centos 安装c++-优快云博客
在 centos 上安装配置 C++11 教程
默认安装旧版本 C++
更新最新版本的 C++
VSCODE 注意事项
安装环境为:win11 系统 -> virtualbox 虚拟机 -> centos7.9 系统 -> C++11
测试时间为:2023 年 04 月
默认安装旧版本 C++
在 CentOS7 上,可以使用 yum 包管理器来安装 C++11 的开发工具和库。具体步骤如下:
更新系统软件包到最新版本:
sudo yum update
1
安装 C++11 开发工具和库:
sudo yum install gcc-c++ -y
sudo yum install libstdc++-devel -y
1
2
以上命令会安装GNU C++编译器和标准C++库的开发文件,包括头文件和库文件。其中,gcc-c++是C++编译器,libstdc+±devel是标准C++库的开发文件。
检查安装是否成功:
可以通过以下命令检查安装是否成功:
g++ --version
1
该命令会显示C++编译器的版本信息,则说明安装成功。
写个 hello world 看可不可以跑:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
1
2
3
4
5
6
7
8
文件命名为 hello.cpp,在命令行中执行:
g++ -o demo hello.cpp
./demo
1
2
输出结果为 hello world! 即安装成功。
更新最新版本的 C++
CentOS7 默认安装的是 GCC 4.8.5,这个版本的GCC不支持完整的 C++11 标准。
如果您需要使用 C++11 标准的特性,则需要安装新版本的 GCC。
安装 centos-release-scl:
sudo yum install centos-release-scl
1
安装 devtoolset,11 为版本号:
sudo yum install devtoolset-11-gcc*
1
临时激活对应的 devtoolset,11为版本号:
scl enable devtoolset-11 bash
1
永久激活软链接:
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-11/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-11/root/bin/g++ /usr/bin/g++
1
2
3
4
测试版本是否正确:
gcc --version
g++ --version
1
2
可以看到,输出结果为:
gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
1
2
成功更新!!!
VSCODE 注意事项
在 VSCODE 环境中使用时,编译器有时不能找到 G++ 所处的位置,需要我们手动导入。
报错情况一般为 #include <stdlib.h> 等头文件下方出现波浪线。
解决方法:
点击 ctrl+shift+p -> C/C++ configurations (UI) -> compiler path 处填入:
/usr/bin/g++
1
即可解决该问题。
Centos7安装、配置SSH服务远程登录_centos7 ssh-优快云博客
VSCode最近自动升级到了1.86后,由于vs1.86版本依赖的glibc版本必须要高于2.28,导致不能打开wsl上安装的centos7,显示如下信息:
类似的,升级后的vs也不能通过ssh连接到glibc版本低于2.28的远程linux服务器。解决方案有以下几种:
1. 【不建议】升级服务器的glibc,升至2.28以上。因glibc为linux系统内核依赖的环境,升级可能导致服务器各种异常,故不建议此种解决方案。
2. 【官方建议】官方建议的解决方案有两个,一个是降级vscode至1.85,并永久禁用vscode的更新,但这样的问题也比较明显,就是以后vscode新的特性都用不了了,哪怕你打开本地的代码也用不了最新特性。
这里说一下首选的解决方案,也是官方推荐的解决方案的第二种:
下载 1.85版本的vscode绿色版(解压即用),然后把当前的vscode(高版本)的配置拷贝到绿色版vscode的下载包中。
下面说一下具体的执行步骤:
-
下载1.85的vscode,这里建议下载1.85.2 (直接官网下载即可,这里不让带url
-
然后解压到一个目录,这里举例为 D:\VSCode1.85
-
进入D:\VSCode1.85,新建data文件夹
-
把%APPDATA%\Code目录拷贝到D:\VSCode1.85\data\下,并重命名为user-data
-
把%USERPROFILE%\.vscode\extensions下面的目录拷贝到D:\VSCode1.85\data\下
-
新建D:\VSCode1.85\data\tmp目录
-
将VScode的remote-ssh扩展版本重新安装v0.107.1
-
将VScode的WSL扩展重新安装v0.78.9
wsl的版本
另外,如果你使用的是web版本的vscode连接服务器,需要在url后面拼接上?vscode-version=0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
表示继续使用VS code1.85
vscode(windows) 如何连接虚拟机中的linux(centos 7)_vscode远程连接虚拟机centos-优快云博客