目录
一、测试网络是否能上网
二、下载阿里云镜像
三、解决执行yum命令出现报错(没有就跳过)
四、下载NVM安装包
五、解压NVM安装包
六、安装Node
七、连接新的动态库
八、升级GLIBC版本
九、安装GCC
十、查看当前服务器CentOS版本
一、测试网络是否能上网
1.网络是否能正常访问:
2.查看文件:cat /etc/sysconfig/network-scripts/ifcfg-ens33
文件的ONBOOT是否等于"yes",并不是的话,将其改为yes
编辑文件:vim /etc/sysconfig/network-scripts/ifcfg-ens33
按I键,修改完成后,按Esc键,输入::wq!
二、下载阿里云镜像
1.备份原镜像文件:
1)新建文件夹:mkdir backup
2)将/etc/yum.repos.d的文件全部移进backup文件夹:mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
3)复制一份CentOS-Base.repo:
cp /etc/yum.repos.d/backup/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
2.修改成阿里云镜像:(不要用http://mirrors.cloud.aliyuncs.com,用http://mirrors.aliyuncs.com,因为ping http://mirrors.cloud.aliyuncs.com,ping不通,访问不到)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.查看镜像文件内容:cat /etc/yum.repos.d/CentOS-Base.repo
完整的CentOS-Base.repo 文件内容:
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/PowerTools/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
4.依次执行命令: yum clean all 和 yum makecache
如果还是出现报错:"Failed connect to mirrors.cloud.aliyuncs.com:80; Connection refused"
三、解决执行yum命令出现报错(没有就跳过)
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; 未知的错误"
解决方法:配置dns服务器
1)查看当前网络连接:nmcli connection show
2)修改当前网络连接对应的dns服务器,网络连接可以使用NAME(ens33)或者UUID(6f403f04-ea93-4abe-9ce3-5236172de5d9),执行命令:
nmcli con mod ens33 ipv4.dns "114.114.114.114 8.8.8.8"
3)启用dns配置:nmcli con up ens33
现在再执行yum命令就不会报错了,试试吧
四、下载NVM安装包
1.下载nvm包:https://github.com/nvm-sh/nvm/archive/refs/tags/v0.39.5.tar.gz
打开虚拟机浏览器,输入下载链接,出现弹窗,选择保存文件,等待下载,在右上角,下载图标,点击文件夹图标,查看nvm安装包的文件所在文件夹
文件下载默认存放在下载文件夹中
五、解压NVM安装包
1.在/root目录创建.nvm文件夹:mkdir /root/.nvm
2.将nvm解压到.nvm文件夹中:
tar -zxvf 下载/nvm-0.39.5.tar.gz -C /root/.nvm/ (-C 解压到指定目录)
或 (两则对比在于前者多了nvm-0.39.5文件夹,后者直接去掉nvm-0.39.5文件夹,直接存放nvm-0.39.5里面的内容)
tar -zxvf 下载/nvm-0.39.5.tar.g --strip-components 1 -C /root/.nvm/
3.编辑~/.bashrc文件:vim ~/.bashrc,文件末尾添加以下内容(按I键,进入编辑模式,按Esc键,退出编辑模式,保存并强制退出,输入::wq!)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
4.重新编译.bashrc文件:source ~/.bashrc,检查nvm是否安装成功,输入:nvm -v
六、安装Node
安装node:nvm install node版本(此处安装20.15.0版本)
查看nvm支持安装什么版本的node:nvm ls-remote
查看已安装的node版本列表:nvm ls
一开始不知道是网络不好还是怎么样,中断了一下,多执行几次
到这,node就安装成功了,不出意外,输入node -v可以看到node的版本号的,那么,不出意外,意外就要来了
七、连接新的动态库
1.解决问题:
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
2.复制链接,执行:wget https://cdn.frostbelt.cn/software/libstdc%2B%2B.so.6.0.26
按住ctrl键,到linux的浏览器下载该文件
3.将下载好的文件,复制一份到/usr/lib64,执行命令:cp 下载/libstdc++.so.6.0.26 /usr/lib64/
4.进入/usr/lib64文件夹,执行命令:ln -snf ./libstdc++.so.6.0.26 libstdc++.so.6
八、升级GLIBC版本
1.解决问题:node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
2.分析原因:没有找到GLIBC_2.27这个版本,node v18开始,都需要GLIBC_2.27支持,而本机的GLIBC版本是比较低的,最高才2.17,不符合要求(centos7服务器使用nvm安装的node之后,只要使用npm或者node,均会出现以下问题)
3.查看GLIBC版本:strings /lib64/libc.so.6 | grep GLIBC
4.安装包glibc-2.2
wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.xz
5.进入glibc-2.28文件夹,创建并进入build文件夹,依次执行:mkdir build 和 cd build
6.编译GLIBC:
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
问题:
configure: error: in `/tmp/glibc-2.28/build':
configure: error: no acceptable C compiler found in $PATH
原因:没有找到C编译器的环境路径,简而言之,就是要安装gcc
查看本机gcc版本(没有这东西)
九、安装GCC
1.执行:yum -y install gcc
资源找不到
执行命令:curl http://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/repodata/repomd.xml -v
再次执行gcc安装命令:yum -y install gcc
查看gcc版本:gcc -v
十、查看当前服务器CentOS版本
1.查看本机服务器版本:rpm -qi centos-release