服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - 服务器知识 - 自建windows服务器如何部署egg应用(图文详解)

自建windows服务器如何部署egg应用(图文详解)

2023-02-16 15:46xulonglong 服务器知识

这篇文章主要介绍了自建windows服务器如何部署egg应用的教程,本文图文并茂给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

1. 使用IE浏览器登陆VPN

自建windows服务器如何部署egg应用(图文详解)
自建windows服务器如何部署egg应用(图文详解)

2. 远程登陆

自建windows服务器如何部署egg应用(图文详解)

3. 在服务器安装最新的node.js,git等

4. 下载源码> git clone ****.git

5. npm安装依赖> cd you-project> npm i

6. 使用egg单进程启动

  1. // 安装最新的egg包
  2. // 在项目根目录下新建run.js
  3. const egg = require('egg');
  4. function normalizePort(val) {
  5. const listenPort = parseInt(val, 10);
  6. if (isNaN(listenPort)) {
  7. return val;
  8. }
  9. if (listenPort >= 0) {
  10. return listenPort;
  11. }
  12. return false;
  13. }
  14. const port = normalizePort(process.env.PORT) || 3000;
  15. egg.start({ ignoreWarning: true })
  16. .then(app => {
  17. app.listen(port);
  18. app.logger.info(`server running on ${port} ...`);
  19. });

测试启动

> node run.js

7. pm2启动安装pm2

> npm i pm2 -g

新建pm2启动文件

  1. module.exports = {
  2. apps : [{
  3. name: '****',
  4. script: 'run.js',
  5.  
  6. // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
  7. args: 'one two',
  8. instances: 4,
  9. autorestart: true,
  10. watch: false,
  11. max_memory_restart: '4G',
  12. env: {
  13. NODE_ENV: 'development',
  14. },
  15. env_production: {
  16. NODE_ENV: 'production',
  17. APP_URL: '*****',
  18. DB_HOST: 'localhost',
  19. DB_PORT: '3306',
  20. DB_USERNAME: '*****',
  21. DB_PASSWORD: '*****',
  22. DB_DATABASE: '*****',
  23. EGG_SERVER_ENV: '****',
  24. },
  25. }],
  26. };

生产环境启动

  1. $ pm2 start ecosystem.config.js --env production

测试环境启动

  1. $ pm2 start ecosystem.config.js

8. 开放3000端口

参考 http://www.tuohang.net/article/172191.htm

9. 安装mysql,

参考:http://www.tuohang.net/article/170594.htm

设置mysql开机启动

10. 设置pm2开机启动,使用nssm

查看PM2_HOME, pm2 save

设置系统环境变量 PM2_HOME = C:\Users\GYSD\.pm2

验证 echo %PM2_HOME%

创建启动脚本 pm2_startup.bat

  1. @echo off
  2. set HOMEDRIVE=C:
  3. set PM2_HOME=C:\Users\***\.pm2
  4. @REM Ensure that pm2 command is part of your PATH variable
  5. @REM if you're not sure, add it here, as follow:
  6. set path=C:\Users\****\AppData\Roaming\npm;%path%
  7. @REM Optionally, you can add 'pm2 kill' just before
  8. @REM resurrect (adding a sleep between 2 commands):
  9. @REM pm2 kill
  10. @REM timeout /t 5 /nobreak > NUL
  11. @REM pm2 resurrect
  12. @REM otherwise, you can simple call resurrect as follow:
  13. pm2 resurrect
  14. echo "Done"

nssm.exe install MyPM2Service

选择自己的 pm2_startup.bat 路径

自建windows服务器如何部署egg应用(图文详解)

重启查看

自建windows服务器如何部署egg应用(图文详解)

总结

以上所述是小编给大家介绍的自建windows服务器如何部署egg应用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

原文链接:https://www.cnblogs.com/xulonglong/archive/2019/10/17/zi-jianwindows-fu-wu-qi-ru-he-bu-shuegg-ying-yong.html

延伸 · 阅读

精彩推荐