章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • linux

    • rsync

      • rsync用法及参数详解
      • rsync服务实现推送,拉取
    • dns

    • sed、awk、grep、find四剑客

    • LVM管理
    • sudo权限规划
    • linux修改网卡为eth0的两种方法
    • Logrotate入门了解及生产实践
    • linux中用dd命令来测试硬盘读写速度
    • linux 阿里云盘挂载错误
    • CentOS7安装Android SDK
    • centos7安装更新git
    • linux启动顺序
    • centos7升级openssl
    • expect工具的安装和使用方法
    • linux下使用v2ray
    • centos7安装java环境的两种方式
    • linux-centos7系统设置时区及同步时间
    • rsyslog日志系统:rsyslog配置文件
    • rsyslog的安装、使用、详解
    • safe-rm防止删除重要的文件
    • linux如何获取打开文件和文件描述符数量
    • LVS集群-DR模式
    • linux服务器安装ffmpeg
    • linux服务器安装samba
    • 使用openssl创建自签发证书
    • linux服务器部署next.js服务
    • linux服务器ionice命令使用方式
    • linux服务器curl命令常用操作
  • windows

  • 中间件

  • 网络

  • 安全

  • 存储

  • 防火墙

  • 数据库

  • 系统

  • docker

  • other

  • 监控

  • 运维
  • linux
章工运维
2024-12-21

linux服务器部署next.js服务

# node服务部署

  • 下载地址:Index of /download/release/v23.5.0/ (opens new window)

  • 在服务器执行

wget https://nodejs.org/download/release/v23.5.0/node-v23.5.0-linux-x64.tar.gz
tar -xf node-v23.5.0-linux-x64.tar.gz
mv node-v23.5.0-linux-x64 node
1
2
3
  • 添加全局环境变量

    vim /etc/profile
     export NODE_HOME=/usr/local/node
     export PATH=$PATH:$NODE_HOME/bin
     source /etc/profile
    
    1
    2
    3
    4
  • 设置国内源加速代理

    一、修改成腾讯云镜像源
     1、命令
    
    npm config set registry http://mirrors.cloud.tencent.com/npm/
    
    2. 验证命令
    
      npm config get registry
    
      如果返回http://mirrors.cloud.tencent.com/npm/,说明镜像配置成功。
    
      二、修改成淘宝镜像源
    
    3. 命令
    
      npm config set registry https://registry.npmmirror.com
    
    4. 验证命令
    
      npm config get registry
    
      如果返回https://registry.npmmirror.com,说明镜像配置成功。
    
      三、修改成华为云镜像源
    
    5. 命令
    
      npm config set registry https://mirrors.huaweicloud.com/repository/npm/
    
    6. 验证命令
    
      npm config get registry
    
      如果返回https://mirrors.huaweicloud.com/repository/npm/,说明镜像配置成功。
    
      四、通过使用淘宝定制的cnpm安装
    
    7. 安装cnpm
    
      npm install -g cnpm --registry=https://registry.npmmirror.com
    
    8. 使用cnpm
    
      cnpm install xxx
    
    1
    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
    42
    43
    44
  • 安装yarn、pm2工具

    npm install -g yarn
    npm install -g pm2
    
    1
    2

# 使用pm2启动服务

#清理缓存
yarn cache clean
yarn install
yarn build
pm2 start yarn --name "nextjs-app" -- start
#查看应用状态
pm2 status
#查看日志
pm2 logs nextjs-app
#停止应用
pm2 stop nextjs-app
#重启应用
pm2 restart nextjs-app
#删除指定id
pm2 delete <id>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 使用docker部署

dockerfile文件如下

# 构建阶段
FROM node:18-alpine AS builder
WORKDIR /app
#COPY package.json yarn.lock ./
#RUN yarn config set registry https://mirrors.huaweicloud.com/repository/npm/ && \
#    yarn install --network-timeout 600000
#RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build

# 生产阶段
FROM node:18-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

# 创建非 root 用户
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

CMD ["node", "server.js"]
1
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

打包镜像

docker build -t resume .
1

启动服务

docker run -d -p 3000:3000 --name resume_Container resume
1

nextjs中文官网 (opens new window)

微信 支付宝
上次更新: 2024/12/21, 22:22:09

← 使用openssl创建自签发证书 linux服务器ionice命令使用方式→

最近更新
01
shell脚本模块集合
05-13
02
生活小技巧(认知版)
04-29
03
生活小技巧(防骗版)
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式