nodejs安装部署

1.Linux
cd /usr/local/

#下载
wget https://nodejs.org/dist/v20.17.0/node-v20.17.0-linux-x64.tar.xz --no-check-certificate

#解压
tar -xvf node-v20.17.0-linux-x64.tar.xz

#修改文件名
mv node-v20.17.0-linux-x64 nodejs

#编辑配置文件
vim /etc/profile

#修改环境变量
export NODE_HOME=/usr/local/nodejs
export PATH=$PATH:${NODE_HOME}/bin

#刷新
source /etc/profile

#验证
node -v

在安装的过程中可能会遇到GLIBC的问题,解决办法如下:

1.更换yum源
#备份原CentOS-Base.repo配置
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
2.修改/etc/yum.repos.d/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/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#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/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#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/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=http://vault.centos.org/centos/7/sclo/$basearch/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
 
[centos-sclo-sclo]
name=CentOS-6.10 - SCLo sclo
baseurl=http://vault.centos.org/centos/7/sclo/$basearch/sclo/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
3.执行命令
yum update

#升级libstdc++.so.6
cd /usr/local/
wget http://www.vuln.cn/wp-content/uploads/2019/08/libstdc.so_.6.0.26.zip
unzip libstdc.so_.6.0.26.zip
cp libstdc++.so.6.0.26 /usr/lib64
rm -f libstdc.so_.6.0.26.zip
rm -f libstdc++.so.6.0.26
cd  /usr/lib64
ln -s libstdc++.so.6.0.26 libstdc++.so.6

#更新gcc
cd /usr/local/
yum install -y centos-release-scl
yum install -y devtoolset-8-gcc*
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++
echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile
source /etc/profile


#更新make
cd /usr/local/
wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar -xzvf make-4.3.tar.gz 
yes|rm make-4.3.tar.gz
cd make-4.3/
mkdir /usr/local/make
./configure --prefix=/usr/local/make
make && make install
cd /usr/bin/
ln -sv /usr/local/make/bin/make /usr/bin/make


#更新glibc-2.28
cd /usr/local/
yum install bison -y
wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar xf glibc-2.28.tar.gz 
rm -rf 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
make -j 10
make localedata/install-locales -j 10
make install -j 10

### 部署 Node.js 后端应用的最佳实践 部署 Node.js 后端应用程序涉及多个方面,包括环境准备、代码优化以及生产环境下的性能调优。以下是详细的说明: #### 1. 准备工作 在正式部署之前,需要确保本地开发环境中构建的应用程序能够正常运行于目标服务器上。通常情况下,在开发阶段,服务器会运行在 `localhost` 上[^3]。为了使应用能够在公网访问,需将其迁移到实际的远程主机。 #### 2. 使用包管理工具配置国内镜像源 如果项目依赖较多或者网络条件不佳,可以考虑切换至国内 NPM 镜像源以加速安装过程。执行命令如下所示: ```bash npm config set registry https://registry.npm.taobao.org ``` 此操作可显著提升下载速度并减少超时错误的发生概率[^4]。 #### 3. 选择合适的云服务商 对于希望将服务公开给更多用户的开发者来说,选用专业的云计算平台是非常重要的一步。常见的选项包括但不限于AWS、阿里云、腾讯云等。这些平台提供了丰富的功能和服务支持,帮助简化Node.js应用上线流程的同时也保障了系统的稳定性和安全性。 #### 4. 设置持续集成/持续交付(CI/CD)管道 通过自动化的方式处理版本控制、测试和发布环节不仅提高了效率还能降低人为失误的风险。GitHub Actions, Jenkins 或者 GitLab CI 是几个值得推荐的选择方案之一。 #### 5. 运行进程守护程序保持服务在线 即使是最可靠的软件也可能因为各种原因崩溃退出。因此建议采用 PM2 等专门设计用于监控nodejs项目的工具来自动重启失败的任务实例,并记录日志以便后续分析排查问题所在。 #### 6. 安全加固措施 - **HTTPS 加密传输**: 利用 Let's Encrypt 提供免费SSL证书实现数据加密保护。 - **API 密钥验证机制**: 对外部请求增加身份校验步骤防止未授权访问。 - **输入参数过滤**: 防范SQL注入攻击等问题发生。 --- ### 示例代码片段展示如何初始化express server 并监听指定端口 ```javascript const express = require('express'); const app = express(); app.get('/', (req, res) => { res.send('Hello World!'); }); // Set port number explicitly or rely on environment variable PORT. const PORT = process.env.PORT || 3000; app.listen(PORT, () => console.log(`Server running at http://localhost:${PORT}/`)); ``` 上述例子展示了创建一个基础webserver的过程,其中设置了默认端口号为3000除非另有定义来自操作系统级别的变量覆盖它[^1]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值