如何使用Jenkins在多个服务器上同时部署Node.js Web应用程序? [英] How to simultaneously deploy Node.js web app on multiple servers with Jenkins?

查看:114
本文介绍了如何使用Jenkins在多个服务器上同时部署Node.js Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在两个远程服务器上部署Node.js移动Web应用程序.(Linux OS) 我正在使用SVN服务器来管理我的项目源代码.

I'm gonna deploy a Node.js mobile web application on two remote servers.(Linux OS) I'm using SVN server to manage my project source code.

为了简单,清晰地管理应用程序,我决定使用Jenkins. 我是Jenkins的新手,因此安装和配置Jenkins相当困难.

To simply and clearly manage the app, I decided to use Jenkins. I'm new to Jenkins so it was a quite difficult task installing and configuring Jenkins.

但是我找不到如何设置Jenkins来同时构建远程服务器.

But I couldn't find how to set up Jenkins to build remote servers simultaneously.

你能帮我吗?

推荐答案

您应该查看主管.它与语言和应用程序类型无关,只需要(重新)启动应用程序即可.

You should look into supervisor. It's language and application type agnostic, it just takes care of (re-) starting application.

因此,在您的詹金斯构建中:

So in your jenkins build:

  • 您从SVN更新代码
  • 您运行单元测试(绝对是个好主意)
  • 您可以在每个主机上启动svn更新或将当前内容复制到它们(我建议这样做,因为有很多方法可以使SVN失败,并且可以在某些.JS文件中包含SVN_REVISION)
  • 您在每台主机上执行:fuser -k -n tcp $DAEMON_PORT,这将终止端口$ DAEMON_PORT(您在node.js应用程序中使用的端口)的当前正在运行的应用程序
  • You update your code from SVN
  • You run your unit tests (definitely a good idea)
  • You either launch an svn update on each host or copy the current content to them (I'd recommend this because there are many ways to make SVN fail and this allows to include SVN_REVISION in the some .JS file for instance)
  • You execute on each host: fuser -k -n tcp $DAEMON_PORT, this will kill the currently running application with the port $DAEMON_PORT (the one you use in your node.js's app)

最好的办法显然是它将在系统启动时自动启动node.js(如果正确安装了Supervisor(在Debian上为apt-get install supervisor)),并在出现故障时重新启动它.

And the best is obviously that it will automatically start your node.js at system's startup (provided supervisor is correctly installed (apt-get install supervisor on Debian)) and restart it in case of failure.

node.js主管的子配置如下:

A node.js supervisord's subconfig looks like this:

# /etc/supervisor/conf.d/my-node-app.conf
[program:my-node-app]
user = running-user
environment = NODE_ENV=production
directory = /usr/local/share/dir_app
command = node app.js
stderr_logfile = /var/log/supervisor/my-node-app-stderr.log
stdout_logfile = /var/log/supervisor/my-node-app-stdout.log

有许多配置参数.

注意:这里有一个node.js的主管,不是我在说的,我还没有测试它.

Note: There is a node.js's supervisor, it's not the one I'm talking about and I haven't tested it.

这篇关于如何使用Jenkins在多个服务器上同时部署Node.js Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆