经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Windows » 查看文章
自建windows服务器如何部署egg应用
来源:cnblogs  作者:xulonglong  时间:2019/10/18 8:45:08  对本文有异议

1. 使用IE浏览器登陆VPN


2. 远程登陆

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

4. 下载源码

  1. > git clone ****.git

5. npm安装依赖

  1. > cd you-project
  2. > 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. });

测试启动

  1. > node run.js

7. pm2启动

  • 安装pm2
  1. > npm i pm2 -g
  • 新建pm2启动文件
  1. module.exports = {
  2. apps : [{
  3. name: '****',
  4. script: 'run.js',
  5. // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
  6. args: 'one two',
  7. instances: 4,
  8. autorestart: true,
  9. watch: false,
  10. max_memory_restart: '4G',
  11. env: {
  12. NODE_ENV: 'development',
  13. },
  14. env_production: {
  15. NODE_ENV: 'production',
  16. APP_URL: '*****',
  17. DB_HOST: 'localhost',
  18. DB_PORT: '3306',
  19. DB_USERNAME: '*****',
  20. DB_PASSWORD: '*****',
  21. DB_DATABASE: '*****',
  22. EGG_SERVER_ENV: '****',
  23. },
  24. }],
  25. };
  • 生产环境启动
  1. $ pm2 start ecosystem.config.js --env production
  • 测试环境启动
  1. $ pm2 start ecosystem.config.js

8. 开放3000端口

参考 https://blog.csdn.net/zzq900503/article/details/11936379

9. 安装mysql,

参考: https://blog.csdn.net/u013235478/article/details/50623693, 设置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 路径
  • 重启查看

参考:https://blog.cloudboost.io/nodejs-pm2-startup-on-windows-db0906328d75

原文链接:http://www.cnblogs.com/xulonglong/p/zi-jianwindows-fu-wu-qi-ru-he-bu-shuegg-ying-yong.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号