In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to deploy NodeJS under Linux". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to deploy NodeJS under Linux" can help you solve your doubts.
one。 Install and configure Node.js
Download installation package or source code from Node.js official website http://nodejs.cn/download/
Download node
Log in to the Linux server through xshell to upload the installation package to the specified installation directory. It is best to plan the installation directory in advance.
# create the mongodb,node,project project in advance. These folders [root@hadoop214 ~] # lsanaconda-ks.cfg install.log install.log.syslog [root@hadoop214 ~] # cd / home [root@hadoop214 home] # lsmongodb node project rar [root@hadoop214 home] #
Upload files through xshell (use rz and sz commands to upload files, lrzsz toolkit needs to be installed on remote Linux systems)
[root@hadoop214 ~] # yum install lrzsz# enter the node folder [root@hadoop214 ~] # cd / home/node# upload [root@hadoop214 node] # rz# will pop up a Windows dialog box, select the file to upload # Note that the file cannot be empty, that is, a file with a size of 0 bytes is not allowed, it is not possible for the file to be empty, it will always be uploaded
Extract the node installation package
[root@hadoop214 node] # tar-zxvf node-v6.2.0-linux-x64.tar# are four parameters x: extract the file from the tar package z: it means that the tar package is compressed by gzip, so you need to decompress it with gunzip. V: displays details f xxx. [tar.gz] specifies that the file to be processed is xxx. [tar.gz]
Enter the decompressed directory under the node-v6.2.0-linux-x64/bin directory
[root@hadoop214 node] # cd node-v6.2.0-linux-x64/bin/# can now display the node version number [root@hadoop214 bin] #. / node- vv6.2.0# but not the npm version number [root@hadoop214 node]. / npm-v
After simple configuration, Node.js is installed successfully, but every time you must go to / home/nodenode-v6.2.0-linux-x64/bin directory to execute the node command, establish a soft connection for node and npm, and execute node and npm in any directory.
[root@hadoop214 node] # ln-s node / usr/bin/node [root@hadoop214 node] # ln-s npm / usr/bin/npm# can now execute node and NPM [root @ hadoop214] # node-v [root@hadoop214 ~] # npm-v in any directory
If the soft connection fails, it can also be achieved by configuring environment variables
# install nano[ root @ hadoop214] # yum install nano# editor ~ / .bashrc [root@hadoop214] # nano ~ / .bashrc # and finally add: every time export PATH=/home/node/node-v6.2.0-linux-x64/bin:$PATH# modifies .bashrc, the use of source ~ / .bashrc is effective immediately. After saving and exiting, you can display the npm version of [root@hadoop214 ~] # npm-v3.8.9 [root@hadoop214 ~] # node- vv6.2.0 II. Install and configure MongoDB
Download the installation package on the official website of MongoDB (CentOS chooses RHEL, it is best to choose even items, the latest version is not the best)
MongoDB download
Upload and decompress as node, and change the name mongodb-linux-x86_64-rhel62-3.4.0 to mongodb.
[root@hadoop214 mongodb] # mv mongodb-linux-x86_64-rhel62-3.4.0 mongodb
Then create a database location and log file for mongodb, which is under / data/db by default, and also set up a corresponding directory under mongodb for convenience
[root@hadoop214 mongodb] # mkdir data [root@hadoop214 mongodb] # cd data# later store the database in db [root@hadoop214 data] # mkdir db# new log file log [root@hadoop214 mongodb] # mkdir log# create a log file [root@hadoop214 mongodb] # touch logs
Start the Mongodb database
# enter the bin file [root@hadoop214 mongodb] # cd bin# configuration path [root@hadoop214 bin] #. / mongod-- dbpath=/home/mongodb/mongodb/data/db-- fork-- logpath=/home/mongodb/mongodb/log/logs# parameter description:-- dbpath: used to specify the database where the mongodb is stored-- fork: executed in the background, otherwise executed in the foreground. The fork parameter enables the exit mongodb path to run-- logpath: used to specify the log file in which the mongodb is stored
Open the rc.local file and add the CentOS boot entry
Nano / etc/rc.d/rc.local# add startup commands to this file / home/mongodb/mongodb/bin/mongod-- dbpath=/home/mongodb/mongodb/data/db-- fork-- logpath=/home/mongodb/mongodb/log/logs
After the third step, mongodb is already running in the background.
three。 Deploy the Node.js project
Install rar. Download the latest version of http://linux.softpedia.com/get/System/Archiving/RAR-2380.shtml#download rar software from the official website. You don't need to install it. You can decompress it directly to / usr/local. The following operations require root permission.
# tar zxvf rarlinux-3.8.0.tar.gz-C / usr/local
At this point, there are rar commands and unrar commands under / usr/local/rar. You can create a connection under / usr/local/bin
# ln-s / usr/local/rar/rar / usr/local/bin/rar#ln-s / usr/local/rar/unrar / usr/local/bin/unrar
Use xshell to upload the project to the specified project folder
[root@hadoop214 ~] # cd / home/project/ChatRooom [root@hadoop214 bin] # rz [root@hadoop214 bin] # unrar x ChatRoom.rar install npm package and run # enter the project [root@hadoop214 ~] # / home/project/ChatRoom/# to set up the Taobao image of npm [root@hadoop214 ChatRoom] # npm config set registry https://registry.npm.taobao.org# if the package dependencies in package.json under the node project are written in Then npm install will automatically download the required package [root@hadoop214 ChatRoom] # npm install#. Some packages need to be manually added. For example, express-handlebars,moment, etc., follow the prompts to add [root@hadoop214 ChatRoom] # npm install express-handlebars# to run the nodejs project [root@hadoop214 ChatRoom] # node bin/www &
These bags are stored in the node_modules folder
four。 Using nodejs pm2
❝
Pm2 is an application process manager with load balancing function, similar to Supervisor,forever.
Installation
# npm install-g pm2
Start
# pm2 start bin/www# pm2 start bin/www-- name my-api # my-api is the PM2 process name # pm2 start bin/www-I 0 # launched according to the number of CPU cores # pm2 start bin/www-- watch # real-time monitoring bin/www. When the bin/www file changes, pm2 will automatically reload
View the process
# pm2 list# pm2 show 0 or # pm2 info 0 # to view process details, 0 is PM2 process id
Monitor and control
# pm2 monit
Stop it
# pm2 stop all # stop all processes in the PM2 list # pm2 stop 0 # stop the process in the PM2 list with process 0
Heavy load
# pm2 reload all # reload all processes in the PM2 list # pm2 reload 0 # reload the process with process 0 in the PM2 list
Restart
# pm2 restart all # restart all processes in the PM2 list # pm2 restart 0 # restart the process with process 0 in the PM2 list
Delete the PM2 process
# pm2 delete 0 # Delete processes with process 0 in PM2 list # pm2 delete all # Delete all processes in PM2 list
Log operation
# pm2 logs [--raw] # Display all processes logs in streaming# pm2 flush # Empty all log file# pm2 reloadLogs # Reload all logs
Upgrade PM2
# npm install pm2@lastest-g # install the latest PM2 version # pm2 updatePM2 # upgrade pm2
For more command parameters, see help.
# pm2--help here, the article "how to deploy NodeJS under Linux" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to learn more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.