Ambari 编译打包需要的 GCC 环境
# Ambari 编译打包需要的 GCC 环境 🚀
在 Ambari 的编译过程中,GCC 是必不可少的工具。若系统中缺少合适版本的 GCC,编译过程将会遇到许多问题。本篇文章将介绍如何安装高版本的 GCC,并解决在 Ambari 项目编译时可能遇到的相关问题。
# 一、如何安装高版本的 GCC 🚀
# 1.1 方法一:通过常规方式安装高版本的 gcc
🛠️
# 1.1.1 启用 CentOS SCLo 仓库 🔧
首先,我们需要启用 Software Collections (SCL) 仓库来安装较新版本的 GCC:
sudo yum install centos-release-scl
# 1.1.2 安装 devtoolset-7
⚙️
启用仓库后,安装高版本的 GCC 和 gcc-c++
:
sudo yum install devtoolset-7-gcc devtoolset-7-gcc-c++
# 1.1.3 启用 devtoolset-7
环境 🎯
安装完成后,通过以下命令启用 devtoolset
环境:
scl enable devtoolset-7 bash
你可以通过以下命令检查 GCC 版本是否更新:
gcc --version
# 1.1.4 永久启用 devtoolset-7
📝
若希望每次启动时自动启用 devtoolset-7
,将命令添加到 .bashrc
文件中:
echo "source scl_source enable devtoolset-7" >> ~/.bashrc
# 1.2 方法二:通过 Nexus 私服安装高版本的 gcc
🔐
# 1.2.1 在 Nexus 上配置阿里云 YUM 仓库 💻
首先配置阿里云的 YUM 仓库,以便从国内镜像源安装:
# 配置以下地址
https://mirrors.aliyun.com/centos/
2
# Step1:新增 Proxy 源
# Step2:将 Proxy 源添加到 Group 中
# Step3:配置完成后的效果
# 1.2.2 编辑 YUM Repo 配置文件
编辑自定义 YUM 源文件 /etc/yum.repos.d/yum-public.repo
:
# 编辑一个自定义源头
vim /etc/yum.repos.d/yum-public.repo
2
填入以下内容:
[yum-public-base]
name=YUM Public Repository
baseurl=http://172.20.0.2:8081/repository/yum-public/$releasever/os/$basearch/
enabled=1
gpgcheck=0
[yum-public-update]
name=YUM Public Repository
baseurl=http://172.20.0.2:8081/repository/yum-public/$releasever/updates/$basearch/
enabled=1
gpgcheck=0
[yum-public-extras]
name=YUM Public Repository
baseurl=http://172.20.0.2:8081/repository/yum-public/$releasever/extras/$basearch/
enabled=1
gpgcheck=0
[yum-public-centosplus]
name=YUM Public Repository
baseurl=http://172.20.0.2:8081/repository/yum-public/$releasever/centosplus/$basearch/
enabled=1
gpgcheck=0
[yum-public-scl]
name=YUM Public Repository
baseurl=http://172.20.0.2:8081/repository/yum-public/7.9.2009/sclo/$basearch/sclo/
enabled=1
gpgcheck=0
[yum-public-scl-rh]
name=YUM Public Repository
baseurl=http://172.20.0.2:8081/repository/yum-public/7.9.2009/sclo/$basearch/rh/
enabled=1
gpgcheck=0
[yum-public-epel]
name=YUM Public Repository
baseurl=http://172.20.0.2:8081/repository/yum-public/$releasever/$basearch/
enabled=1
gpgcheck=0
[yum-public-mariadb]
name=YUM Public Repository
baseurl=http://172.20.0.2:8081/repository/yum-public/yum/10.11.8/centos7-amd64/
enabled=1
gpgcheck=0
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 1.2.3 安装高版本的 gcc
🔄
清理 YUM 缓存并安装 GCC:
sudo yum clean all
sudo yum makecache
sudo yum install devtoolset-7-gcc devtoolset-7-gcc-c++
2
3
# 1.2.4 启用 devtoolset-7
环境 🎯
安装完成后,通过以下命令启用 devtoolset-7
环境:
scl enable devtoolset-7 bash
# 二、在 Ambari 项目中编译 ambari-web 报错
# 2.1 报错日志
在编译 ambari-web
时,可能会遇到以下报错:
[DEBUG] Loading mojo com.github.eirslett:frontend-maven-plugin:1.4:yarn from plugin realm ClassRealm[plugin>com.github.eirslett:frontend-maven-plugin:1.4, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[DEBUG] Configuring mojo execution 'com.github.eirslett:frontend-maven-plugin:1.4:yarn:yarn install' with basic configurator -->
[DEBUG] (f) arguments = install --ignore-engines --pure-lockfile --verbose
[DEBUG] (f) environmentVariables = {npm_config_tmp=/tmp/npm_config_tmp}
[DEBUG] (f) npmRegistryURL = https://registry.npmmirror.com
[DEBUG] (f) project = MavenProject: org.apache.ambari:ambari-web:2.8.0.0.0 @ /opt/modules/ambari/ambari-web/pom.xml
[DEBUG] (f) repositorySystemSession = org.eclipse.aether.DefaultRepositorySystemSession@3c35c345
[DEBUG] (f) session = org.apache.maven.execution.MavenSession@41aaedaa
[DEBUG] (f) skip = false
[DEBUG] (f) skipTests = false
[DEBUG] (f) testFailureIgnore = false
[DEBUG] (f) workingDirectory = /opt/modules/ambari/ambari-web
[DEBUG] (f) yarnInheritsProxyConfigFromMaven = false
[DEBUG] (f) execution = com.github.eirslett:frontend-maven-plugin:1.4:yarn {execution: yarn install}
[DEBUG] -- end configuration --
[INFO] yarn not inheriting proxy config from Maven
[INFO] Running 'yarn install --ignore-engines --pure-lockfile --verbose --registry=https://registry.npmmirror.com/' in /opt/modules/ambari/ambari-web
[DEBUG] Executing command line [/opt/modules/ambari/ambari-web/node/yarn/dist/bin/yarn, install, --ignore-engines, --pure-lockfile, --verbose, --registry=https://registry.npmmirror.com]
[ERROR] node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
[ERROR] node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node)
[ERROR] node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
[ERROR] node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
[ERROR] node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
[ERROR] node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.140 s
[INFO] Finished at: 2024-08-20T09:15:00+08:00
[INFO] ------------------------------------------------------------------------
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 2.2 解决办法
# 2.2.1 多版本共存方案
为了解决编译问题,你可以通过启用 SCL 源并安装 devtoolset-7-gcc
和 devtoolset-7-gcc-c++
,从而使用高版本的 GCC 编译器。只需确保启用相关环境即可解决问题。
# 2.2.2 配置示例
通过配置 YUM 仓库并启用对应版本的
gcc
,解决低版本 GCC 的问题,确保安装最新版编译工具链。在项目中配置好相应的编译环境后,执行以下命令:
scl enable devtoolset-7 bash
1
# 2.3 使用 ambari-env 一键解决环境准备问题
# 2.3.1 自动配置 YUM 源
使用 ambari-env
项目可以自动加入并配置统一的 YUM 源。
# 2.3.2 自动初始化 yum-public.repo
文件
通过执行 ambari-env
脚本,自动初始化并配置 yum-public.repo
文件,确保所有源都指向正确的 YUM 仓库。
# 2.3.3 编译前自动准备环境
在 Ambari 项目中,使用 ambari-env
进行自动环境准备,确保项目编译不再因环境问题报错。