Deploy those pits that node.js v6.4.0 stepped on on centos6.5

Background note:

There is a project that uses Node.js, so the running environment of node V6.4.0 needs to be deployed under centos.

 

Introduction:

The Node.js platform runs JavaScript code on the backend, so the Node environment must be installed on the machine first .

npm is a package management tool for Node.js ( node package manager ) , which is used to manage the download of modules referenced by Node.js code, which is convenient for solving the dependencies of each module.

 

Summary of the problem:

In fact, the main reason is that the environment is not satisfied. After upgrading one, and relying on the other, I am really tired. The worst thing is that after upgrading libc.so.6 to version 2.14 ( centos6.5 comes with 2.12 ), it affects the locale of the machine. When svn is updated, Chinese cannot be updated. So I wanted to delete the high-version libc.so.6 dynamic library and restore the old one. As a result, once I deleted the system, I couldn't run any commands. I immediately restored it through the solution found on the Internet, LD_PRELOAD=/lib64/libc-2.12. so ln -s /usr/local/glibc-2.14/lib/libc-2.14.so libc.so.6, the system came to life again; but the second time I didn't give up, I wondered if it was caused by the application occupancy, I deleted it again, but it still didn't work. After a few seconds of restoring it, the system crashed. Fortunately, it is a test system. After cleaning up my emotions, I  booted from the centos CD to enter rescue mode and restored it by backing up the original libc.so.6.

 

Let’s restore it from memory, how I fell into the pit step by step, so that I can reminisce later, or the classmates who see it can bypass some pits:

Because of the dependencies when  npm installs modules, python2.7 and gcc-c++ 4.8.0 are required:

 

First, upgrade python from 2.6 to 2.7 :

Implementation steps:

1. Download the release file of nux  :

wget http://li.nux.ro/download/nux/dextop/el6/i386/nux-dextop-release-0-2.el6.nux.noarch.rpm

rpm -ivh nux-dextop-release-0-2.el6.nux.noarch.rpm

yum -y install python27

yum -y install python27-devel

2. Upgrade python

Centos still uses python2.6.* by default , you need to overwrite the python file with the python2.7 file.

cd /usr/bin/

rm -rf python

cp python2.7 python

3. Test

Enter python --version on the command line , if the output shows this is correct:

[root@linuxidc script]# python --version

Python 2.7.3

4、由于yum没有兼容python2.7,需要vi /usr/bin/yum将 #!/usr/bin/python 修改为 #!/usr/bin/python2.6

 

 

 然后,npm install时需要gcc-c++-4.8.0以上,在centos6.5默认是gcc-c++-4.4.7。没办法,只能编译升级:

 

1.下载gcc最新的源码包 wget http://gcc.skazkaforyou.com/releases/gcc-4.9.1/gcc-4.9.1.tar.gz

2.解压缩 tar -xf gcc-4.9.1.tar.gz

3. cd gcc-4.9.1

4.运行download_prerequisites脚本, ./contrib/download_prerequisites ,这个脚本会自动下载所需要的依赖文件和库

5.建立输出目录,将所有的中间文件都放到该目录,

mkdir gcc_temp

cd gcc_temp

6. 运行 ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

7. make & make install

 

然而,gcc升级后,并没有结束,npm install发现引起的依赖关系是libstdc++版本不够高,

 /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15'

libstdc++ 检查发现,GLIBCXX 最高只有 3.4.13

strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

于是下载了一个 6.0.20 的,替换掉当前使用的 libstdc++

cp /usr/local/lib64/libstdc++.so.6.0.20 /usr/lib64/

ln -s -f /usr/lib64/libstdc++.so.6.0.20 /usr/lib64/libstdc++.so.6

检查一下新的 libstdc++GLIBCXX 最高到 3.4.20 

 

libstdc++.so.6的坑填完之后,就是最挫的地方了,linux的语言环境设置异常,报错:

# locale -a|more

locale: Cannot set LC_CTYPE to default locale: No such file or directory

locale: Cannot set LC_MESSAGES to default locale: No such file or directory

locale: Cannot set LC_COLLATE to default locale: No such file or director

试遍网上的改编码的方式,都不行,其实我也知道,肯定还是glibc版与glibc-common版本不一致造成,找遍度娘谷哥都没找到类似的解决方法,有一个网友跟我的出错一毛一样,但是他也没解决,他说更新了glibc-common仍然无效,此时我有点想回滚了;最悲剧的场面也是因此产生,删除了动态库libc.so.6,服务器直接就挂了,当时就傻了,应该另外找台机器来搞的,没想到依赖关系这么多,捅一堆篓子。

 

这里其实就是,libstdc++依赖/lib64/libc.so.6: version `GLIBC_2.14'的问题,报错如下:

node: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib64/libstdc++.so.6)

centos6.5libc.so.6默认版本是2.12,所以,又得升级。。。

于是安装glibc2.14,将glibc更新到glibc2.14

1)下载

glibc2.14下载地址:

http://ftp.gnu.org/gnu/glibc/

wget http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz

2)编译

tar -zxvf glibc-2.14.tar.gz

cd glibc-2.14

mkdir build

cd build

../configure --prefix=/usr/local/glibc-2.14

make -j4

make install

 

方法一:直接生效(建议)

编译.bash_profile下设置:

export LD_PRELOAD=/lib64/libc

export LD_PRELOAD=/usr/local/glibc-2.14/lib/libc-2.14.so

source .bash_profile

在网上查找时,博主是建议用这个,但是糟糕在我选了删除动态库重建链接

 

方法二:(效果不好,不建议用)

可以先删除软链接:删除/lib64/libc.so.6

cd /lib64

rm libc.so.6

此时libc.so.6被删除,无法执行其他命令,需要用一下命令进行恢复,并重新建立软链接:

export LD_PRELOAD=/lib64/libc

export LD_PRELOAD=/lib64/libc-2.12.so

恢复完成之后执行:

cp /usr/local/glibc-2.14/lib/libc-2.14.so /lib64/libc-2.14.so

ln -s libc-2.14.so libc.so.6

此时,libc.so.6就升级完成。

 

其实我也就是想回滚libc.so.6包到2.12版本出的问题,过程如下:

cd /lib64

rm libc.so.6

结果系统命令就无法执行,就想先恢复系统,还是用2.14

LD_PRELOAD=/lib64/libc-2.12.so ln -s /usr/local/glibc-2.14/lib/libc-2.14.so libc.so.6

 

结果,恢复后几秒,系统就挂了,无法开机了。

 

 

下面是拯救过程:思路就是用系统安装镜像(因为我是虚拟机)把libc.so.6

还原成2.12

进入救援模式后,chroot /mnt/sysimage,结果报错libc.so.6 too short,总之是异常。

然后,我想直接mv 或者删除再拷贝旧版本的libc.so.6都操作失败。

最后想,要不看下当前的挂载情况,看到/mnt/sysimage挂载路径,于是进入

/mnt/sysimage/user/lib64/

删除libc.so.6,再ln -s /libc-2.12.so libc.so.6

 

之后,重启,至此,系统终于恢复。。。

 

 

总结:Centos6.5自带的gccpython版本都太低,编译升级后各种依赖关系真是让人头疼,而已容易把环境搞得很乱,给维护也带来很大难度,所以程序要求环境的版本比较高,该升centos 7就升吧。我最后也是这么干的,升到centos7后,安装一路顺利,高歌挺进,下一篇写一下整个安装过程。

 

因水平有限,如有疏漏,还请留言反馈,谢谢~

 

参考文档:

python2.6升级到2.7

http://www.linuxidc.com/Linux/2014-07/104555.htm

 

GCC4.7升级到4.9.1

https://www.cppfans.org/1719.html

 

libstdc++ 的问题

http://blog.41ms.com/post/54.html

 

libstdc++依赖/lib64/libc.so.6: version `GLIBC_2.14'的问题:

http://rocketeer.leanote.com/post/Glibc%E9%94%99%E8%AF%AF

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327077430&siteId=291194637