当前位置:网站首页>Complete deployment process of alicloud for nodejs project

Complete deployment process of alicloud for nodejs project

2020-11-10 12:04:40 Noosphere

nodejs Project deployment Alibaba cloud Complete process

  • Reference documents :http://blog.csdn.net/chenlinIT/article/details/73343793
  • Pay attention to the details :1. start-up nodejs The service needs to open two Alibaba cloud Host window , One is the database mongoose service , One is nodejs The server 2. If nodejs The server is listening to your Alibaba cloud host ip Failure , You can try to use 0.0.0.0.( because Alibaba cloud Limited port number , Officially it's 3398 Port, but the author tried to invalid ,0.0.0.0 Of ip Indicates listening to all port numbers of the current host )

1.1- preparation

  • 1. Run one nodejs What process is needed for the program

    • (1) Your computer has node
    • (2) Your computer has npm

      • By default node,npm It's also installed
    • (3) Your computer has a database installed

      • Usually nodejs Project use mongodb database
    • (4) Write your project source code
    • (5) start-up mongodb service

      • cd To mongodb Install package path using terminal command :mongod --dbpath=[ Yours data Folder path ]
    • (6) start-up node Run your program

      • cd To node.exe Use the terminal command in the directory :node [ Your project server portal file app.js route ]

        • Install by default node Will automatically help you configure environment variables , We can use... In any directory node command
  • 2. The server-side project is deployed to Alibaba cloud Principle

    • It's just to install all the processes in the previous step in Alibaba cloud On a host of

      • It can be understood as : bought Alibaba cloud After the server of , Alibaba cloud I have prepared a computer which can be accessed by Internet , And then we're going to run our nodejs Program

1.2- Deploy your... From scratch nodejs project

 Picture description here

 Picture description here

  • 2. Purchase domain name

    • There's nothing to say , The better the domain name , The more expensive it is

 Picture description here

  • 3. Buying databases 【 Optional 】

    • After we bought the server , The default server has a certain amount of storage space , If the number of users is not large , There's no need to buy a database alone
    • The database configuration is the same , If you want to learn nodejs Development , You can not buy , Direct use of server host storage , Saving a little money is a little money

 Picture description here

  • 4. Access control , Start deploying the project

 Picture description here

  • Find the lightweight server you just bought

 Picture description here

 Picture description here

  • Be careful : The terminal of the server is based on linux, And mac The system is the same , And windows There are some differences in system part commands

 Picture description here

  • 5. Bind domain name : Click just now nodejs The server enters the details interface and binds the domain name

 Picture description here

  • 6. Use XShell Remote connection server

    • By default , We operate remote servers in Alibaba cloud Click remote connection on the page of , It will pop up the terminal window of your remote server on the web page , It's not convenient for us to operate this way directly , Use XShell The tool can visually see some files on your remote server
    • SChell Another benefit is that we're going to write nodejs It is more convenient to upload project files to remote server
    • Download address by Baidu , Here the author gives a reference download address :http://rj.baidu.com/soft/detail/15201.html?ald
  • Open after installation XShell panel

 Picture description here

 Picture description here

  • 7. To configure Alibaba cloud Server computer node The environment and npm Environmental Science
  • Use ls Command to view the server's file list
  • Use cd Command to enter the corresponding folder
  • Use node -v and npm -v Check your node Version and npm edition

  • If you want to upgrade your Alibaba cloud Server's node Version and npm edition , Enter the following commands at the terminal in order ( Optional )

    • wget Command download Node.js Installation package :wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz

      • The installation package is a compiled file , After decompression , stay bin The folder already exists node and npm, No need to compile again .
    • Unzip the file :tar xvf node-v6.9.5-linux-x64.tar.xz
  • 8. install mongodb

    • Enter the command at the terminal to wait for installation :wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.5.tgz

      • It takes a long time , Please be patient
    • Unzip the installation package :tar zxvf mongodb-linux-x86_64-3.4.5.tgz
    • Reorder the folder to mongodb:mv mongodb-linux-x86_64-3.4.5 mongodb
    • Create and store mongodb Data data Folder :mkdir /root/mymongodbmkdir /root/mymongodb/data

      • Be careful : there /root It refers to your Alibaba cloud The name of the server root directory , The default is root
  • 9. start-up mongodb

    • cd To your mongodb Of bin Catalog , For example, I mongodb The installation path is :cd /root/mongodb/bin
    • function mongodb service :mongod --dbpath=[ Just created data Folder path ], For example, here I am mongod --dbpath=/root/mymongodb/data

 Picture description here

 Picture description here

  • If appear wating for connection on port 27017 It means success

    • Is it the same as deploying on your own computer ? Don't worry. , It's just half way through
  • 10.mongodb The service needs to occupy a separate terminal window , So for the moment, the terminal window doesn't move , We start another window to start our nodejs project
  • 11. wait ? Do we have any terminal projects on our servers at present ? I don't think so ?

    • So the key point is 11 Step , We need to deploy our source code to Alibaba cloud On the server host
  • 12. download Xftp

  • 13. utilize Xshell To start up Xftp

    • Xftp Let's put it aside after downloading , There is no need to start it alone , Because as long as you install Xftp, You can use Xshell To start up

      • If you configure it separately Xftp Be sure to pay attention to the port number and our Xshell Agreement , If you look up the picture carefully, you can see my Xshell The port number is 22

 Picture description here

  • 14. Upload nodejs Project files to Alibaba cloud The server

    • start-up xftp Also need to enter your server password , Don't forget.
    • On the right is your local project , On the left is your Alibaba cloud Host Directory , Drag it directly

 Picture description here

  • 15. stay Alibaba cloud The server starts your nodejs project
  • a key , a key , a key

    • 1.app.js The port number of file listening cannot be written as your server ip Address , The proposal is written as 0.0.0.0

      • The reasons are endless , Because you don't know Alibaba cloud What ports are allowed to listen on ( I don't know what port is authorized to listen to )
      • 0.0.0.0 And 127.0.0.1 It's all about this machine ip, The only difference between them is ,0.0.0.0 This is equivalent to listening on all ports of this server
    • 2.Xshell the mongodb Don't close your window , We need to open another window to activate our nodej project

//4. Monitor port number 
server.listen(3000,'0.0.0.0',function () {
    console.log(' Server started successfully ');
});

 Picture description here

  • 16. Be accomplished , Enter your domain name directly on any networked device , I'll use mine here iphone Enter my domain name

    • a key , a key , a key

      • 1. If the domain name is not filed , This website will pop up and you are not allowed to visit it , Pages requiring filing , Never mind , Just refresh it a few more times OK

        • 4G The Internet is 100% useless ,wifi Just refresh it a few times
      • 2. Yours nodejs In addition to the import module in the project , There can be no relative path anywhere else ./, as a result of nodejs The relative path in is equivalent to what you type node The directory where the command is located

 Picture description here

  • Additional explanation , We can use it in the terminal vim To modify the code online , About vim Operation of their own Baidu

    • viw [ File path ]: Check the file source code
    • keyboard i: Enter editor
    • keyboard esc Exit the editor
    • Console :wq: Save and exit vim

版权声明
本文为[Noosphere]所创,转载请带上原文链接,感谢