【NodeJS】GLIBC_2.28 not found CentOS7不兼容Node高版本

 后端   大苹果   2023-12-02 15:08   2440

提前部署

  1. 安装编译环境devtoolset-8

  2. 编译安装glibc-2.28

  3. 编译安装gcc高版本并配置LD_LIBRARY_PATH

参考链接:

https://github.com/nodejs/build/issues/2815 https://cloud.tencent.com/developer/article/2021784

操作步骤

1、安装编译环境devtoolset-8

sudo yum install centos-release-scl

sudo yum install devtoolset-8

scl enable devtoolset-8 bash

gcc --version

2、编译安装glibc-2.28

wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz --no-check-certificate

tar -xzvf glibc-2.28.tar.gz

cd glibc-2.28

mkdir build && cd build

../configure--prefix=/usr--disable-profile--enable-add-ons--with-headers=/usr/include --with-binutils=/usr/bin --enable-obsolete-nsl

configure 增加 --enable-obsolete-nsl ,解决编译错误 undefined reference to '_nsl_default_nss@GLIBC_PRIVATE'

修改 scripts/test-installation.pl 128行,增加 && $name ne "nss_test2" ,解决编译错误 nss_test2报错。

sed -i '128i\ && $ name ne "nss_test2"' ../scripts/test-installation.pl

126 if ($name ne "nss_ldap" && $name ne "db1"

127 && $name ne "thread_db"

128 && $name ne "nss_test2"

129 && $name ne "nss_test1" && $name ne "libgcc_s") {

130 $link_libs .= " -l$name";

131 $versions{$name} = $version;

132 }

执行编译安装:

make -j4

make install

查看glibc支持的版本:

strings /lib64/libc.so.6 | grep GLIBC

3、编译安装gcc高版本并配置LD_LIBRARY_PATH

sudo yum install gmp-devel mpfr-devel libmpc-devel
wget https://ftp.gnu.org/gnu/gcc/gcc-8.5.0/gcc-8.5.0.tar.gz --no-check-certificate
tar -xvf gcc-8.5.0.tar.gz
cd gcc-8.5.0
mkdir build
cd build
../configure--disable-multilib--enable-languages=c,c++--prefix=$HOME/local
make -j8
make install

~/.bashrc 中增加语句:
export LD_LIBRARY_PATH=$HOME/local/lib64