SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Deploying Node.js
With Forever and Nginx
“a no-downtime tale”
Node.js

•  Runs as a standalone server, listen its own
• 
• 

port
Just need to proxy the request to Node.js
and relay the result back
Installing is easy (let's try in MacOS/Ubuntu)
o 

sudo apt-get update
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Sample server with Compound.js

•  sudo npm install compound -g
•  compound init todo-list-app
•  cd todo-list-app && npm install
How to start the project:
node .

• 
Making Node.js run "forever"

•  Using Forever.js
•  Forever.js is a "daemonized version" of your
• 

Node app.
Will check if the app is killed and re-spawn it
Forever.js setup and commands

•  It's an npm package.
o 

sudo npm install forever -g

o 
o 
o 
o 

start
- Start SCRIPT as a daemon
stop
- Stop the daemon SCRIPT
stopall - Stop all running forever scripts
restart - Restart the daemon SCRIPT

•  Main commands

o  restartall - Restart all running forever scripts
o  list
- List all running forever script
Let's try it!

•  Identify the script to run
o 
o 

Inspecting package.json is often a good idea
Example with compound.js
§  , "main": "server.js"

o 

Command: "node ." loads package.json, finds "main"
script and executes it.

•  Run on Forever:
o 

forever start /full-path-to-script/server.js
Ok, a bit more of Forever.js
(featuring up and inspecting)

•  How to keep the log
o 
o 

-l LOGFILE - Logs the forever output to LOGFILE
-o OUTFILE - Logs stdout from child script to OUTFILE

o 

-e ERRFILE - Logs stderr from child script to ERRFILE

o 

-p PATH

•  Some other useful commands
§ 
o 

- Base path for all forever related files (pid files, etc.)

To make your line shorter

-c COMMAND - COMMAND to execute (defaults to node)
§ 

For when you have "more" than just "node" to run (server init params for example)

•  List running processes
o 

forever list (easy, right?)
Now, the cherry, "no downtime"

•  forever restart /full-path-to-script/script
•  If you're not sure about the script path, just
do "forever list" and take it up from there
Now we're all set, let's get serious

•  Nginx
o 

Awesome
Event-driven
Asynchronous
10k-friendly

o 

sudo apt-get install nginx

o 
o 
o 

•  Not quite hard to setup (ubuntu)
Configure Nginx

•  Sites management
o 
o 
o 
o 
o 

Config files are best kept per-site
1 file per site in
§  /etc/nginx/sites-available/ (standard)
To activate a site, make a symbolic link to
§  /etc/nginx/sites-enabled/
Restart gracefully
§  sudo service nginx reload
Done.
Let's configure our proxy

•  cd /etc/nginx/sites-available/
•  sudo view compoundapp.com
o 

(name it based on your FQDN as a best practice)

•  Create a proxy block

upstream node_boxes {
server 127.0.0.1:3000;
}
Proxy Will be used as the relay
o 

• 
Architecture
• 
• 
• 

Traffic

Traffic goes through
the load balancer
nginx redirects to
the "upstream"
node_box
Want to scale? Just
add more boxes
and update nginx
config.

nginx load balancer

Node.js box

Node.js box

Node.js box

Node.js box
Configs: Load balancer
server {
# server_name yourdomain.com yourdomain; # set the domain name to bind to
access_log /var/log/nginx/compountapp.com_access.log; error_log /var/log/nginx/
compountapp.com_error.log;
# reroute all and pass the correct headers
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
# then proxy the request
proxy_pass http://node_boxes/;
proxy_redirect off;
}
}
Load balancing?
o 

o 

upstream node_boxes {
server 50.20.14.8:3000;
server 50.20.14.9:3001;
server 50.20.14.10:3002;
server 50.20.14.11:3000;
}
sudo service nginx reload
What's next?

•  WebSockets
•  Load balancing
•  What about the Databases/services?
•  Centralize your logs
•  Performance analysis
•  Cloud
Resources
• 

http://stackoverflow.com/a/5015178/519649
o 

• 
• 

Config node.js as a proxy

https://github.com/nodejitsu/forever
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
o 

Install Node.js via package manager
About us
Author: Nicolas Embleton
Find me at: nicolas.embleton@gmail.com
Presentation made for “Javascript Ho Chi Minh City” meetup group
You can find us at:
•  http://meetup.com/JavaScript-Ho-Chi-Minh-City/
•  https://www.facebook.com/JavaScriptHCMC
•  https://plus.google.com/communities/116105314977285194967

Weitere ähnliche Inhalte

Was ist angesagt?

Warsztaty ansible
Warsztaty ansibleWarsztaty ansible
Warsztaty ansiblegnosek
 
Build and deployment
Build and deploymentBuild and deployment
Build and deploymentWO Community
 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsWO Community
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginxroskakori
 
docker build with Ansible
docker build with Ansibledocker build with Ansible
docker build with AnsibleBas Meijer
 
Ansible
AnsibleAnsible
Ansiblegnosek
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to AnsibleDan Vaida
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = CodeGeorg Sorst
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practicesBas Meijer
 
Learn basic ansible using docker
Learn basic ansible using dockerLearn basic ansible using docker
Learn basic ansible using dockerLarry Cai
 
Depende, ¿de qué depende? - Plain Concepts Dev Day
Depende, ¿de qué depende? - Plain Concepts Dev Day Depende, ¿de qué depende? - Plain Concepts Dev Day
Depende, ¿de qué depende? - Plain Concepts Dev Day Plain Concepts
 
Glauber Costa on OSv as NoSQL platform
Glauber Costa on OSv as NoSQL platformGlauber Costa on OSv as NoSQL platform
Glauber Costa on OSv as NoSQL platformDon Marti
 
The Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session IThe Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session IOded Sagir
 
OSv at Cassandra Summit
OSv at Cassandra SummitOSv at Cassandra Summit
OSv at Cassandra SummitDon Marti
 
Install openstack
Install openstackInstall openstack
Install openstack어형 이
 
Salt Stack - Subhankar Sengupta
Salt Stack - Subhankar SenguptaSalt Stack - Subhankar Sengupta
Salt Stack - Subhankar SenguptaDevOpsBangalore
 
Odoo Performance Limits
Odoo Performance LimitsOdoo Performance Limits
Odoo Performance LimitsOdoo
 
OpenNebula, the foreman and CentOS play nice, too
OpenNebula, the foreman and CentOS play nice, tooOpenNebula, the foreman and CentOS play nice, too
OpenNebula, the foreman and CentOS play nice, tooinovex GmbH
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
 

Was ist angesagt? (20)

Warsztaty ansible
Warsztaty ansibleWarsztaty ansible
Warsztaty ansible
 
Build and deployment
Build and deploymentBuild and deployment
Build and deployment
 
Using Nagios to monitor your WO systems
Using Nagios to monitor your WO systemsUsing Nagios to monitor your WO systems
Using Nagios to monitor your WO systems
 
Multiple django applications on a single server with nginx
Multiple django applications on a single server with nginxMultiple django applications on a single server with nginx
Multiple django applications on a single server with nginx
 
docker build with Ansible
docker build with Ansibledocker build with Ansible
docker build with Ansible
 
Ansible
AnsibleAnsible
Ansible
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to Ansible
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practices
 
Learn basic ansible using docker
Learn basic ansible using dockerLearn basic ansible using docker
Learn basic ansible using docker
 
Depende, ¿de qué depende? - Plain Concepts Dev Day
Depende, ¿de qué depende? - Plain Concepts Dev Day Depende, ¿de qué depende? - Plain Concepts Dev Day
Depende, ¿de qué depende? - Plain Concepts Dev Day
 
Glauber Costa on OSv as NoSQL platform
Glauber Costa on OSv as NoSQL platformGlauber Costa on OSv as NoSQL platform
Glauber Costa on OSv as NoSQL platform
 
The Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session IThe Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session I
 
OSv at Cassandra Summit
OSv at Cassandra SummitOSv at Cassandra Summit
OSv at Cassandra Summit
 
Install openstack
Install openstackInstall openstack
Install openstack
 
Salt Stack - Subhankar Sengupta
Salt Stack - Subhankar SenguptaSalt Stack - Subhankar Sengupta
Salt Stack - Subhankar Sengupta
 
Odoo Performance Limits
Odoo Performance LimitsOdoo Performance Limits
Odoo Performance Limits
 
OpenNebula, the foreman and CentOS play nice, too
OpenNebula, the foreman and CentOS play nice, tooOpenNebula, the foreman and CentOS play nice, too
OpenNebula, the foreman and CentOS play nice, too
 
Vagrant
VagrantVagrant
Vagrant
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 

Ähnlich wie Deploy Node.js with Forever and Nginx for No Downtime

OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopleffen
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Alex S
 
FullStack London - Cloud Native Node.js
FullStack London - Cloud Native Node.jsFullStack London - Cloud Native Node.js
FullStack London - Cloud Native Node.jsBethany Nicolle Griggs
 
Ansible is the simplest way to automate. SymfonyCafe, 2015
Ansible is the simplest way to automate. SymfonyCafe, 2015Ansible is the simplest way to automate. SymfonyCafe, 2015
Ansible is the simplest way to automate. SymfonyCafe, 2015Alex S
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction Robert Reiz
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with AnsibleAhmed AbouZaid
 
Nginx as a Revers Proxy for Apache on Ubuntu
Nginx as a Revers Proxy for Apache on UbuntuNginx as a Revers Proxy for Apache on Ubuntu
Nginx as a Revers Proxy for Apache on Ubuntuabdullah roomi
 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)Ashish Gupta
 
Modern Development Tools
Modern Development ToolsModern Development Tools
Modern Development ToolsYe Maw
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to productionSean Hess
 
Deploying your rails application to a clean ubuntu 10
Deploying your rails application to a clean ubuntu 10Deploying your rails application to a clean ubuntu 10
Deploying your rails application to a clean ubuntu 10Maurício Linhares
 
PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoHannes Hapke
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdfNigussMehari4
 
Quest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDQuest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDAndi Smith
 
Go Faster with Ansible (AWS meetup)
Go Faster with Ansible (AWS meetup)Go Faster with Ansible (AWS meetup)
Go Faster with Ansible (AWS meetup)Richard Donkin
 

Ähnlich wie Deploy Node.js with Forever and Nginx for No Downtime (20)

OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
 
FullStack London - Cloud Native Node.js
FullStack London - Cloud Native Node.jsFullStack London - Cloud Native Node.js
FullStack London - Cloud Native Node.js
 
Ansible is the simplest way to automate. SymfonyCafe, 2015
Ansible is the simplest way to automate. SymfonyCafe, 2015Ansible is the simplest way to automate. SymfonyCafe, 2015
Ansible is the simplest way to automate. SymfonyCafe, 2015
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Install dev stack
Install dev stackInstall dev stack
Install dev stack
 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
 
Nginx as a Revers Proxy for Apache on Ubuntu
Nginx as a Revers Proxy for Apache on UbuntuNginx as a Revers Proxy for Apache on Ubuntu
Nginx as a Revers Proxy for Apache on Ubuntu
 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)
 
Elastic search
Elastic searchElastic search
Elastic search
 
Modern Development Tools
Modern Development ToolsModern Development Tools
Modern Development Tools
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
 
Deploying your rails application to a clean ubuntu 10
Deploying your rails application to a clean ubuntu 10Deploying your rails application to a clean ubuntu 10
Deploying your rails application to a clean ubuntu 10
 
PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
 
Ansible - Hands on Training
Ansible - Hands on TrainingAnsible - Hands on Training
Ansible - Hands on Training
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdf
 
Quest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDQuest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFRED
 
Go Faster with Ansible (AWS meetup)
Go Faster with Ansible (AWS meetup)Go Faster with Ansible (AWS meetup)
Go Faster with Ansible (AWS meetup)
 
Node js
Node jsNode js
Node js
 

Mehr von JavaScript Meetup HCMC

Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]JavaScript Meetup HCMC
 
Building workflow in Javascript: Build the awesome with Gulp.
Building workflow in Javascript: Build the awesome with Gulp.   Building workflow in Javascript: Build the awesome with Gulp.
Building workflow in Javascript: Build the awesome with Gulp. JavaScript Meetup HCMC
 
[Js hcm] Java script- Testing the awesome
[Js hcm] Java script- Testing the awesome[Js hcm] Java script- Testing the awesome
[Js hcm] Java script- Testing the awesomeJavaScript Meetup HCMC
 
Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...
Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...
Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...JavaScript Meetup HCMC
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]JavaScript Meetup HCMC
 
Khanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solutionKhanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solutionJavaScript Meetup HCMC
 

Mehr von JavaScript Meetup HCMC (8)

Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]
 
Building workflow in Javascript: Build the awesome with Gulp.
Building workflow in Javascript: Build the awesome with Gulp.   Building workflow in Javascript: Build the awesome with Gulp.
Building workflow in Javascript: Build the awesome with Gulp.
 
[Js hcm] Java script- Testing the awesome
[Js hcm] Java script- Testing the awesome[Js hcm] Java script- Testing the awesome
[Js hcm] Java script- Testing the awesome
 
Knockout js (Dennis Haney)
Knockout js (Dennis Haney)Knockout js (Dennis Haney)
Knockout js (Dennis Haney)
 
Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...
Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...
Debugging JavaScript (by Thomas Bindzus, Founder, Vinagility & Thanh Loc Vo, ...
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
Khanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solutionKhanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solution
 

Kürzlich hochgeladen

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Kürzlich hochgeladen (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Deploy Node.js with Forever and Nginx for No Downtime

  • 1. Deploying Node.js With Forever and Nginx “a no-downtime tale”
  • 2. Node.js •  Runs as a standalone server, listen its own •  •  port Just need to proxy the request to Node.js and relay the result back Installing is easy (let's try in MacOS/Ubuntu) o  sudo apt-get update sudo apt-get install python-software-properties python g++ make sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs
  • 3. Sample server with Compound.js •  sudo npm install compound -g •  compound init todo-list-app •  cd todo-list-app && npm install How to start the project: node . • 
  • 4. Making Node.js run "forever" •  Using Forever.js •  Forever.js is a "daemonized version" of your •  Node app. Will check if the app is killed and re-spawn it
  • 5. Forever.js setup and commands •  It's an npm package. o  sudo npm install forever -g o  o  o  o  start - Start SCRIPT as a daemon stop - Stop the daemon SCRIPT stopall - Stop all running forever scripts restart - Restart the daemon SCRIPT •  Main commands o  restartall - Restart all running forever scripts o  list - List all running forever script
  • 6. Let's try it! •  Identify the script to run o  o  Inspecting package.json is often a good idea Example with compound.js §  , "main": "server.js" o  Command: "node ." loads package.json, finds "main" script and executes it. •  Run on Forever: o  forever start /full-path-to-script/server.js
  • 7. Ok, a bit more of Forever.js (featuring up and inspecting) •  How to keep the log o  o  -l LOGFILE - Logs the forever output to LOGFILE -o OUTFILE - Logs stdout from child script to OUTFILE o  -e ERRFILE - Logs stderr from child script to ERRFILE o  -p PATH •  Some other useful commands §  o  - Base path for all forever related files (pid files, etc.) To make your line shorter -c COMMAND - COMMAND to execute (defaults to node) §  For when you have "more" than just "node" to run (server init params for example) •  List running processes o  forever list (easy, right?)
  • 8. Now, the cherry, "no downtime" •  forever restart /full-path-to-script/script •  If you're not sure about the script path, just do "forever list" and take it up from there
  • 9. Now we're all set, let's get serious •  Nginx o  Awesome Event-driven Asynchronous 10k-friendly o  sudo apt-get install nginx o  o  o  •  Not quite hard to setup (ubuntu)
  • 10. Configure Nginx •  Sites management o  o  o  o  o  Config files are best kept per-site 1 file per site in §  /etc/nginx/sites-available/ (standard) To activate a site, make a symbolic link to §  /etc/nginx/sites-enabled/ Restart gracefully §  sudo service nginx reload Done.
  • 11. Let's configure our proxy •  cd /etc/nginx/sites-available/ •  sudo view compoundapp.com o  (name it based on your FQDN as a best practice) •  Create a proxy block upstream node_boxes { server 127.0.0.1:3000; } Proxy Will be used as the relay o  • 
  • 12. Architecture •  •  •  Traffic Traffic goes through the load balancer nginx redirects to the "upstream" node_box Want to scale? Just add more boxes and update nginx config. nginx load balancer Node.js box Node.js box Node.js box Node.js box
  • 13. Configs: Load balancer server { # server_name yourdomain.com yourdomain; # set the domain name to bind to access_log /var/log/nginx/compountapp.com_access.log; error_log /var/log/nginx/ compountapp.com_error.log; # reroute all and pass the correct headers location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; # then proxy the request proxy_pass http://node_boxes/; proxy_redirect off; } }
  • 14. Load balancing? o  o  upstream node_boxes { server 50.20.14.8:3000; server 50.20.14.9:3001; server 50.20.14.10:3002; server 50.20.14.11:3000; } sudo service nginx reload
  • 15. What's next? •  WebSockets •  Load balancing •  What about the Databases/services? •  Centralize your logs •  Performance analysis •  Cloud
  • 16. Resources •  http://stackoverflow.com/a/5015178/519649 o  •  •  Config node.js as a proxy https://github.com/nodejitsu/forever https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager o  Install Node.js via package manager
  • 17. About us Author: Nicolas Embleton Find me at: nicolas.embleton@gmail.com Presentation made for “Javascript Ho Chi Minh City” meetup group You can find us at: •  http://meetup.com/JavaScript-Ho-Chi-Minh-City/ •  https://www.facebook.com/JavaScriptHCMC •  https://plus.google.com/communities/116105314977285194967