CentOS/Red Hat 系 Linux 使用

目录

  • 1. CentOS/Red Hat 系 Linux 使用
    • 1.1. 包地址
    • 1.2. 网络
      • 1.2.1. 修改 DNS
    • 1.3. 时间
      • 1.3.1. 配置时区
      • 1.3.2. Sync with NTP Time Servers
      • 1.3.3. List of Top Public Time Servers
      • 1.3.4. timedatectl 命令的使用
      • 1.3.5. 关于 timedatectl 输出中的 DST active
    • 1.4. 安装内核开发包
    • 1.5. 问题解决
      • 1.5.1. warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
    • 1.6. EPEL
      • 1.6.1. 什么是 EPEL, 为何经常要安装 epel-release 软件包
      • 1.6.2. EPEL 清华镜像配置
    • 1.7. Centos7 升级内核 kernel-ml-4.18.9 版本
    • 1.8. 安装官方 buildlogs 的包
    • 1.9. devtoolset
  • 2. CentOS 因为停服引起的问题解决
    • 2.1. repomd.xml: [Errno 14] curl#60 - "The certificate issuer's certificate has expired. Check your system date and time."
    • 2.2. 关于 CentOS Stream
      • 2.2.1. CentOS 的 Linux 和 Stream 版的区别
      • 2.2.2. 为什么会有 CentOS Stream
  • 3. 如何使用 llvm 从头到尾构建一个 Linux 发行版
  • 4. 包
    • 4.1. 安装包
      • 4.1.1. No package g++ available

1. CentOS/Red Hat 系 Linux 使用

这里记录与其它 Linux 系不同的地方。

1.1. 包地址

https://centos.pkgs.org/

1.2. 网络

1.2.1. 修改 DNS

  1. 通过 ip addr 命令找到网卡名称(这里假设我们获取到的网卡名为 eth0);
  2. 编辑其配置: vim /etc/sysconfig/network-scripts/ifcfg-eth0, 添加如下:
DNS1=1.1.1.1
DNS2=1.0.0.1
  1. 使配置生效: systemctl restart network。生效后 /etc/resolv.conf 将会被修改;

上述配置生效会修改文件 /etc/resolv.conf(重启网络或者重启电脑都会), 如果不想其被修改可以在 /etc/sysconfig/network-scripts/ifcfg-eth0 里面再添加一行 PEERDNS=no, 这个时候任意修改 /etc/resolv.conf 都可以, 重启后配置不会被覆盖。

1.3. 时间

1.3.1. 配置时区

Checking the Current Timezone:

timedatectl
ls -l /etc/localtime

Changing Timezone in CentOS:

timedatectl list-timezones
sudo timedatectl set-timezone your_time_zone (example: sudo timedatectl set-timezone America/Toronto)
timedatectl

Changing the Timezone by Creating a Symlink:

sudo rm -rf /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date

1.3.2. Sync with NTP Time Servers

We need to install the ntpd and ntpdate clients on our Linux host.

yum install ntp ntpdate
# ntpd service
systemctl start ntpd
systemctl enable ntpd
systemctl status ntpd

# configure the NTP servers
ntpdate -u -s 0.centos.pool.ntp.org 1.centos.pool.ntp.org 2.centos.pool.ntp.org

# restart
systemctl restart ntpd

# set the hardware clock to the current system time using the -w switch
hwclock -w

# check
timedatectl

1.3.3. List of Top Public Time Servers

From: List of Top Public Time Servers

  • Google Public NTP [AS15169]:
time.google.com
time1.google.com
time2.google.com
time3.google.com
time4.google.com
  • Cloudflare NTP [AS13335]:
time.cloudflare.com
  • Facebook NTP [AS32934]:
time.facebook.com
time1.facebook.com
time2.facebook.com
time3.facebook.com
time4.facebook.com
time5.facebook.com
  • Microsoft NTP server [AS8075]:
time.windows.com
  • Apple NTP server [AS714, AS6185]:
time.apple.com
time1.apple.com
time2.apple.com
time3.apple.com
time4.apple.com
time5.apple.com
time6.apple.com
time7.apple.com

time.euro.apple.com
  • DEC/Compaq/HP:
clepsydra.dec.com/clepsydra.labs.hp.com/clepsydra.hpl.hp.com
  • NIST Internet Time Service (ITS) [AS49, AS104]:
time-a-g.nist.gov
time-b-g.nist.gov
time-c-g.nist.gov
time-d-g.nist.gov
time-a-wwv.nist.gov
time-b-wwv.nist.gov
time-c-wwv.nist.gov
time-d-wwv.nist.gov
time-a-b.nist.gov
time-b-b.nist.gov
time-c-b.nist.gov
time-d-b.nist.gov
time.nist.gov
utcnist.colorado.edu
utcnist2.colorado.edu

1.3.4. timedatectl 命令的使用

查看

  • 显示系统的当前时间和日期: timedatectl status
  • 查看当前时区: timedatectl | grep Time
  • 查看所有可用时区: timedatectl list-timezones

要根据地理位置找到本地的时区, 运行以下命令

timedatectl list-timezones |  egrep  -o "Asia/B.*"
timedatectl list-timezones |  egrep  -o "Europe/L.*"
timedatectl list-timezones |  egrep  -o "America/N.*"

设置硬件时钟

  • 查看你的硬件时钟是否设置为本地时区: timedatectl | grep local
  • 将硬件时钟设置为本地时区: timedatectl set-local-rtc 1
  • 将硬件时钟设置为协调世界时 (UTC): timedatectl set-local-rtc 0

设置时区

  • 在 Linux 中设置本地时区, 使用 set-timezone 开关: timedatectl set-timezone "Asia/Shanghai"
  • 设置 local_timeUTC: timedatectl set-timezone UTC

设置时间和日期

  • 设置时间: timedatectl set-time 15:58:30
  • 设置日期: timedatectl set-time 20151120
  • 设置日期和时间: timedatectl set-time '16:10:40 2015-11-20'

同步系统及硬件时间

  • 查看系统时间: date
  • 查看硬件时间: hwclock --show

当系统时钟与硬件时钟不一致时, 可进行同步到同一时间

hwclock --systohc    #以系统时钟为准, 同步硬件时钟  
hwclock --hctosys    #以硬件时钟为准, 同步系统时钟 

这样写一下也许看的更明白些

[root@mycomputer ~]# timedatectl status
      Local time: Fri 2020-09-18 14:57:06 CST
  Universal time: Fri 2020-09-18 06:57:06 UTC
        RTC time: Fri 2020-09-18 06:57:06
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
Local time           本地时间 通常为 RTC + 时区
Universal time       系统时间一直是 UTC
RTC time             硬件时钟的时间, 一般也 BIOS 时间
Time zone            时区, set-timezone 就是设置的这个
NTP enabled          是否开启 ntp 时间同步
NTP synchronized     NTP 同步是否完成
RTC in local TZ      是否设置 RTC 时间, set-local-rtc 选项就是控制该处
DST active           夏令时
  • 设置硬件时钟为本地时间, 终端输入: timedatectl set-local-rtc yes, yes 可写为 no
  • 发现时区不对, 导致协调世界时间与本地时间一致, 所以修改时区, 终端输入: sudo timedatectl set-timezone 'Asia/Shanghai'
  • 硬件时间处没写值, 终端输入 hwclock -r 查看硬件时间; 将硬件时间同步本地时间, 硬件终端输入 hwclock -w
  • 查询硬件时间, 发现没有改成功, 查询资料发现是 NTP 时间同步跟 timedatectl 修改时间不能共用, 所以关闭 NTP 时间同步(终端输入: timedatectl set-ntp no)

1.3.5. 关于 timedatectl 输出中的 DST active

DST 即 Daylight Saving Time。

daylight saving time = summer time 夏令时
每年的四月左右, 人们的时钟要向前调一个小时, 到了十月左右再调回来。全世界有近 110 个国家采用夏令时制。中国曾在 1986-1991 采用过夏令时制。

daylight saving time 字面意思是"日光节省时制"
举个例子, 夏令时到来, 人们将时间调快一个小时, 闹钟还是 7 点响。但最终会在原本冬令时的 6 点就起床了。这样所有人就都早一个小时进入了生产生活状态, 下班后早一个小时进入休息状态。整个社会就增加了对日光的利用效率, 节省了照明等能源。

夏令时制与固定时制的时间转换

美股开盘时间

- 夏令时 冬令时
美东时间 9:30 9:30
北京时间 21:30 22:30

争议

每六个月就要调表到来时, 总会引起采用夏令时的争论。夏令时制反对者认为: 人为的调整时钟, 会扰乱人体生物钟。会对人体和精神健康产生负面影响。研究表明, 固定时制可以减少犯罪、能源消耗、车祸。

最新进展

美国参议院通过了《阳光保护法案》S.623 - 117th Congress (2021-2022): Sunshine Protection Act of 2021 | Congress.gov | Library of Congress, 规定在 2023 年 11 月 5 号夏令时制永久实行。但是历史上美国曾经在 1974 年尝试过永久化夏令时制, 仅仅 4 个月后就在公众的反对声中取消了。

1.4. 安装内核开发包

没有则下载对应的内核开发包: yum install kernel-devel-$(uname -r)

再看 /usr/src/kernels/, 发现内核开发包存在了

1.5. 问题解决

1.5.1. warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

On a freshly installed CentOS 7 machine, I got the following notice when I SSH’d into the server.

warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

The fix is pretty straight-forward. On the server (not your client), edit the file /etc/environment and add the following lines.

(You’ll need root privileges to do this)

$ cat /etc/environment
LANG=en_US.utf-8
LC_ALL=en_US.utf-8

Log out & back in and you should notice the warning message is gone. Don’t need reboot.

1.6. EPEL

1.6.1. 什么是 EPEL, 为何经常要安装 epel-release 软件包

EPEL (Extra Packages for Enterprise Linux) 是基于 Fedora 的一个项目, 为 “红帽系” 的操作系统提供额外的软件包, 适用于 RHEL、CentOS 和 Scientific Linux, 是为企业级 Linux 提供的一组高质量的额外软件包。

我们在 CentOS 下使用 yum 安装时往往找不到 rpm 的情况, 官方的 rpm repository 提供的 rpm 包也不够丰富, 很多时候需要自己编译很痛苦, 而 EPEL 恰恰可以解决这两方面的问题。EPEL 的全称叫 Extra Packages for Enterprise Linux。EPEL 是由 Fedora 社区打造, 为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL 之后, 就相当于添加了一个第三方源。

yum -y install epel-release
 
yum repolist

yum clean all
 
yum makecache
$ cat /etc/yum.repos.d/epel.repo
 
[epel]
name=epel
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-releasever&arch=releasever&arch=basearch
enabled=1
gpgcheck=0

1.6.2. EPEL 清华镜像配置

From Here

EPEL(Extra Packages for Enterprise Linux) 是由 Fedora Special Interest Group 维护的 Enterprise Linux(RHEL、CentOS) 中经 常用到的包。

下面以 CentOS 7 为例讲解如何使用本镜像站的 epel 镜像。CentOS 8 同样可用该方法。

首先从 CentOS Extras 这个源(本镜像站也有镜像)里安装 epel-release:

yum install epel-release

修改 /etc/yum.repos.d/epel.repo, 将 mirrorlistmetalink 开头的行注释掉。

接下来, 取消注释这个文件里 baseurl 开头的行, 并将其中的 http://download.fedoraproject.org/pub 替换成 https://mirrors.tuna.tsinghua.edu.cn

可以用如下命令自动替换: (来自 https://github.com/tuna/issues/issues/687)

sed -e 's!^metalink=!#metalink=!g' \
    -e 's!^#baseurl=!baseurl=!g' \
    -e 's!//download\.fedoraproject\.org/pub!//mirrors.tuna.tsinghua.edu.cn!g' \
    -e 's!//download\.example/pub!//mirrors.tuna.tsinghua.edu.cn!g' \
    -e 's!http://mirrors!https://mirrors!g' \
    -i /etc/yum.repos.d/epel*.repo

修改结果如下: (仅供参考, 不同版本可能不同)

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=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=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=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=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=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 update 测试一下吧。

1.7. Centos7 升级内核 kernel-ml-4.18.9 版本

默认内核版本为 3.10.0, 现升级到 4.18.9 版本

# 查看当前内核版本
uname -r

自行查找需要的 内核版本(比较全的 lt 和 ml 版本)。

或者下载网上找来的 4.18.9 版本内核文件: kernel-ml-4.18.9.tar.gz

tar xf kernel-ml-4.18.9.tar.gz

cd kernel-ml-4.18.9

yum localinstall kernel-ml*

设置默认启动新内核 并重新生成 grub2

# 查看当前内核
$ cat /boot/grub2/grub.cfg |grep ^menuentry
menuentry 'CentOS Linux (4.18.9-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1127.el7.x86_64-advanced-abb47b92-d268-4d8c-a9df-43bf44522cab' {
menuentry 'CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1127.el7.x86_64-advanced-abb47b92-d268-4d8c-a9df-43bf44522cab' {
menuentry 'CentOS Linux (0-rescue-63f20fbd07a048dc88574233e1ad966b) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-63f20fbd07a048dc88574233e1ad966b-advanced-abb47b92-d268-4d8c-a9df-43bf44522cab' {

# 设置启动内核
grub2-set-default 0
# 或者
grub2-set-default 'CentOS Linux (4.18.9-1.el7.elrepo.x86_64) 7 (Core)'

grub2-mkconfig -o /boot/grub2/grub.cfg

# 重启系统
reboot

# 确认使用的内核版本
uname -r
4.18.9-1.el7.elrepo.x86_64

1.8. 安装官方 buildlogs 的包

这里以安装 LLVM 9.0 为例。

需要先安装:

# 1. Install CentOS SCLo RH repository:
yum install centos-release-scl-rh

# 2. Install devtoolset-8-libstdc++-devel rpm package:
yum install devtoolset-8-libstdc++-devel

然后修改文件 /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo, 复制增加一个节点 centos-sclo-rh-testing1, 如下:

cat /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

[centos-sclo-rh-testing1]
name=CentOS-7 - SCLo rh Testing1
baseurl=https://buildlogs.centos.org/c7-llvm-toolset-9.0.x86_64/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

添加环境变量:

export LLVM_HOME=/opt/rh/llvm-toolset-9.0/root

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LLVM_HOME/usr/lib64

export PATH=$PATH:$LLVM_HOME/bin

一般按上述就可以了, 有的特殊情况需要进行静态链接: ln -s /usr/bin/llvm-strip-9.0 /usr/bin/llvm-strip

TIP: 编辑配置 /etc/yum.repos.d 下的 .repo 配置文件, 其中 baseurl 必须保证其有 repodata/repomd.xml 这样的目录结构, 如 https://buildlogs.centos.org/c7-llvm-toolset-9.0.x86_64/ 这样的。

1.9. devtoolset

Centos 7 has the devtoolsets with more recent versions of everything you should really consider installing them. E.g. you can directly install GCC 11 and likely a clang 12 or something like this which will come with clangd directly

yum install centos-release-scl
yum install devtoolset-11
scl enable devtoolset-11 bash

2. CentOS 因为停服引起的问题解决

2.1. repomd.xml: [Errno 14] curl#60 - “The certificate issuer’s certificate has expired. Check your system date and time.”

原由: yum 调用 curl 命令下载软件包, 而 curl 命令在从 https 路径下载软件包时, 会通过本地 ca-certicifates 包中的文件校验证书合法性, 如果 ca-certificates 包过期, 则会出现证书过期的问题

解决: 手动更新 ca-certificates 软件包及其依赖

yum update -y http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/ca-certificates-2020.2.41-70.0.el7_8.noarch.rpm http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/p11-kit-0.23.5-3.el7.x86_64.rpm http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/p11-kit-trust-0.23.5-3.el7.x86_64.rpm
yum makecache

搞定!

(可选)更新完成后再执行 yum makecahce fast 命令即恢复正常

如果是 HTTPS 证书的话在 /etc/yum.conf 里面增加 sslverify=0

2.2. 关于 CentOS Stream

Linux distributions based on Red Hat Enterprise Linux (RHEL) include:

  • CentOS
  • Rocky Linux
  • Oracle Linux
  • AlmaLinux
  • Fedora
  • ClearOS
  • Future OS

红帽公司今天宣布, CentOS Stream 现在将成为公开的 RHEL 相关源代码发布的唯一仓库。在一个可能会疏远一些 Linux 社区用户和开发者的举动中, 红帽决定 CentOS Stream 将成为公开的红帽企业 Linux 相关源码的唯一存储库。不过, 付费的红帽客户仍然可以通过红帽客户门户访问适当的 RHEL 源代码。

通过将 RHEL 公共源代码限制在 CentOS Stream 中, 这意味着现有的社区/分支企业 Linux 发行版, 如 Alma Linux、Rocky Linux、Oracle Linux 等, 将更难提供 1:1 的二进制兼容构建来对抗给定的 RHEL 版本。

同时, 红帽的工程师们也在致力于 CentOS Stream 10 的开发, 作为未来红帽企业 Linux 10 的基础。

红帽赞助 CentOS Linux 和 CentOS Stream 的时间表:

  • 不会有 CentOS Linux 9。
  • CentOS Linux 8 发行版的更新将持续到 2021 年 12 月 31 日。
  • CentOS Linux 7 发行版的更新与之前一样, 一直持续到 2024 年 6 月 30 日。
  • CentOS Linux 6 发行版的已于 2020 年 11 月 30 日结束。
  • 作为 RHEL 9 开发过程的一部分, CentOS Stream 9 将于 2021 年第二季度发布。
  • CentOS Stream 8 发行版的更新将贯穿整个 RHEL 支持阶段。

2.2.1. CentOS 的 Linux 和 Stream 版的区别

  1. CentOS Linux 版为传统 CentOS 系统, 系统的基本源代码由 RHEL 对应版本的开源代码提供, 是 RHEL 的下游。
    当 RHEL 更新后 CentOS Linux 根据 RHEL 更新的内容进行更新并修复其中可能的漏洞等。版本略落后于 RHEL, 更新新特性速度较 RHEL 慢。(见 CentOS 官方 WIKI/FAQ 第二条"How long after Red Hat publishes a fix does it take for CentOS to publish a fix?") 提供与 CentOS Linux 版以前一样的安全服务支持和稳定的服务器操作系统, 但 CentOS Linux 8 服务支持时间被大幅减少, CentOS Linux7 的维护时间暂时没有改变, 且官方维护团队的重心已经转移到 Stream 版本。

CentOS Linux 在红帽系的系统中的生态位置 Fedora Linux ➡️ RHEL ➡️CentOS Linux(或者同级)

  1. CentOS Stream 版则为滚动更新版 , 系统的基本源代码也由 RHEL 对应版本的开源代码提供。但代码更加激进, 是合并进 RHEL 前的一个试验场, 比 RHEL 更新新特性更快。等到相关新代码成熟后由 RHEL 合并, 是 RHEL 的上游 (见参考资料 CentOS Wiki 第 11 条"CentOS Stream")。

CentOS Stream 在红帽系的系统中的生态位置 Fedora Linux ➡️ CentOS Stream ➡️ RHEL

2.2.2. 为什么会有 CentOS Stream

在红帽提出做企业级 Linux 之前, 很少有人将 Linux 直接用于企业生产, 企业对于安全、稳定等还是有担忧的。红帽提出将 Linux 送进企业生产环境, 主要做法就是反向移植, 基于社区某一版本拉出一个分支, 在该分支上不断优化和工程化改进, 如果有一些创新的想法也加进来, 类似 SUSE 等做企业级 Linux 的基本都是这样的思路。这让我们的开发模式在很长一段时间内类似瀑布式开发, 我们在这个过程中不断地将整个版本做稳定, 这是一种传统的开发方式。

2017 年左右, 我们认为这个传统的开发方式有点不合时宜, 因为这种方式的迭代周期比较慢, 现在都讲究 DevOps、微服务, 开发周期越来越短, 我们也在思考操作系统内核包含其上软件的开发速度有没有可能提升, 我们在开发流程中加入了 CI/CD, 且每天晚上都对当天的提交用例做自动化测试 (Nightly Builds), 第二天就发布一个新的版本, 我们将这个过程叫做 Stream。

2018 年左右, CentOS Stream 的雏形就已经有了, 但并没有在 CentOS 社区里面公布这种流式的开发模式。随着这几年的孵化并综合考虑了各方面因素, 我们认为 CentOS Stream 可以更快捷稳定的发布 Linux 版本, 所以相对于我们把 CentOS 升级到 CentOS Stream。

在我们看来, CentOS Stream 的稳定性不输于 CentOS, 很多人对此有疑问, 认为这是给小白鼠用的, 其实不然, Fedora 才是 RHEL 的实验场。从正常的逻辑来说, 我们也不需要两个实验场。

至于 CentOS Stream 在 Linux 生态中的位置, 一般来说, Fedora 是中上游, RHEL 是下游, CentOS Stream 是中游。事实上, Fedora 完全从社区里来, 红帽做的更多是打包和简单测试, 对其稳定性及可靠性方面的工作做得是比较少, 遵循滚动更新的方式, 每半年发布一个新版本, 新版本与旧版本之间保有基本的兼容性, 也可能会丢弃一些老版本中不好的地方, 这恰恰是企业级开发不能接受的。

RHEL 则是基于 Fedora 某个特定版本拉取分支, 逐渐在这个版本上做增强, 保证新旧版本之间的兼容性, 并保证最终版本的稳定性。CentOS Stream 则与 RHEL 的版本相对应, 其 Git 提交记录完全一致, 二者通过同样的构建流程、同样的测试用例。简单来说, 只有通过全部的测试用例, CentOS Stream 新版本才会发布, 这些测试用例与 RHEL 可能重合, 也可能不重合, 但我们认为只有全部通过才是稳定的, 才可以进入下一步, RHEL 也是如此, 二者在稳定性上保持一致。

那么, 既然二者一致, 为什么还区分中游和下游呢? 所有在 RHEL 做的改动都会先进到 CentOS Stream 里面, 方便社区生态伙伴一起共建, 并让所有开发者第一时间享受到最新版本。

CentOS Stream 8 和 RHEL 8 是对应的, 不过 RHEL 可能还有 8.1、8.2、8.3… 这其中的区别是 CentOS Stream 永远只对应 RHEL 最新的稳定版。一般来说, 我们的更新节奏是每六个月会更新一个小版本, 假设当前 RHEL 的最新稳定版是 8.3, 那么 CentOS Stream 一定是和该版本对应的。

原 CentOS 用户如何切换至 CentOS Stream:

dnf swap centos-linux-repos centos-stream-repos
dnf distro-sync

CentOS Stream 为什么不直接从红帽的企业版编译?

无论是红帽的企业版还是 CentOS Stream, 代码和走过的测试用例都是一样的, 无非最终一个包打了红帽企业级产品的签名, 我们更想表达的意思是 RHEL 里面所有的内容都可以在 CentOS Stream 里面看到, 如果反过来, 用户难免觉得红帽是不是自己留了一部分。

对开发者而言, 如何选择在红帽的哪个平台开发? 哪个平台部署?

开发层面, 很多发烧友可能习惯采用 Linux Destop; 桌面开发可以选择 Fedora, 里面的所有包都是最新的; 大部分情况下, 服务器端开发, CentOS Stream 是很好的选择, 因为它不像 Fedora 那么激进, 包也很全, 又具备 RHEL 的稳定性, 更新又足够快, 特别是 8 之后的版本, 不同语言的库包括容器化应用开发所需的镜像都是存在的, 是很省心的选择。当然, 这些都是免费的。如果需要红帽提供一些服务, 也可以选择我们的企业级版本。

3. 如何使用 llvm 从头到尾构建一个 Linux 发行版

编译 sysroot: LLVM cross-compiled Linux From Scratch: C & C++ libraries

编译内核和 busybox, 打包 initramfs: LLVM cross-compiled Linux From Scratch: Bootable kernel and initramfs

还有一个示例, 编译 zfs 及其依赖库: LLVM cross-compiled Linux From Scratch: ZFS on root (Optional)

这套流程支撑了我的 Linux rootfs on zfs 的 initramfs, 并且在 x86_64 和 arm(apple m1) 上都验证过。

因为 clang 目前不能编译 glibc, 所以只能用 musl. 我从 2018 年开始用 musl libc 作为桌面系统的库, 目前大部分程序都可以支持 musl.

另外 clang 也不能自举 gcc 的 libstdc++, 因此使用的是 LLVM libc++. 因为 Android、macOS 等系统都是使用的 LLVM libc++, 其兼容性要比 musl 好很多。只是有一些程序会少 include, 需要打补丁。

clang 支持命令行传递配置: https://clang.llvm.org/docs/UsersManual.html#configuration-files 一定程度上 linux 的 clang 安装搭配一个配置文件就能作为交叉编译器, 因此比 LFS 多次自举 gcc 要方便很多。

如果真的想用 glibc, 可以参考 chromiumOS, 这个系统的 glibc 可以用 clang 编译, 但是打了 163 个补丁: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/refs/heads/main/sys-libs/glibc/files/local/glibc-2.35/llvm/

如果想要自动化编译, 可以用 gentoo 现成的 musl/llvm/openrc stage3, 也可以使用 gentoo 的 bootstrap 脚本编译这个 profile 的 stage1

如果有编译不过的包可以参考我的 gentoo overlay, 有一些包的补丁, 比如 systemd, chromium, electron, vscode, qtwebengine, openjdk, rustc: https://github.com/12101111/overlay

还有一些零散的补丁: https://github.com/12101111/etc

4. 包

4.1. 安装包

4.1.1. No package g++ available

yum install gcc-c++

你可能感兴趣的:(#,linux,centos,epel,yum,kernel,pkg)