[Re-learn the first 5] Node.js project to deploy a cloud server Tencent

Course description see here: https://www.cnblogs.com/zhangran/p/11963616.html
project github Address: https://github.com/hellozhangran/happy-egg-server

By the previous lecture, you can complete a basic node api service, and try to take over the project to deploy the cloud Tencent bought.

Access to services

  • Buy Tencent cloud container, after the purchase will account information by Tencent in the letter you sent to the cloud station, which has public ip and initial password, ssh landing will be used later.

  • Log cloud linux. Local Mac command line, type: ssh [email protected], follow the prompts to enter your password.

Installation Node environment

  • cd && mkdir download && cd download

  • Download node: wget https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz

  • Unzip the file node:tar xvf node-v12.13.0-linux-x64.tar.xz

  • Unzip good move a file to / opt / node:
    • mkdir /opt/node
    • mv ~/download/node-v12.13.0-linux-x64 /opt/node
  • Create a soft link:
    • ln -s /opt/node/node-v12.13.0-linux-x64/bin/node /usr/local/bin/node
    • ln -s /opt/node/node-v12.13.0-linux-x64/bin/npm /usr/local/bin/npm
  • Verification node and npm has been installed successfully:
    • npm -v

    • node -v

Install git

  • Installation: yum -y install gitThis installation fast, but can only install an earlier version. Below install the new version git

  • Delete an existing git:yum remove git

  • Download Source Package: wget -O ~/download/git-2.21.0.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.21.0.tar.gz

  • Install build dependencies:yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

  • Decompression:
    • tar -zxf ~/download/git-2.21.0.tar.gz
    • cd ~/donwload/git-2.21.0
  • Inspection of dependencies, set the installation path:./configure --prefix=/opt/git

  • Compile and install:make && make install

  • Configuration PATH variable:
    • vi /etc/profile
    GIT_HOME=/usr/local/git
    export PATH=$PATH:$GIT_HOME/bin
    • source /etc/profile
  • Use git clone https link the code is relatively simple, if you need to generate SSH Key locally using ssh, the current priority use https way, but may be reported fatal: Unable to find remote helper for 'https', if you encounter this problem is:
    yum install curl-devel # cd to wherever the source for git is cd /usr/local/src/git-1.7.9 ./configure make make install

Installation mongodb

  • Download Source: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.9.tgzproved, wget to download much faster than curl, curl should be suitable for the request does not fit the download package. See a lot of tutorials with curl download mongo package, explain.

  • Decompression:tar -zxvf mongodb-linux-x86_64-4.0.9.tgz

  • Move to the appropriate directory mv mongodb-linux-x86_64-3.0.6 /opt/mongodb

  • Configuration PATH:vi /etc/profile

  • Create a configuration file: cd /opt/mongodb && touch mongodb.confInput:

    # Store data in /opt/mongodb/data instead of the default /data/db
    dbpath = /opt/mongodb/data
    
    # Append logs to /opt/mongodb/log/mongodb.log
    logpath = /opt/mongodb/log/mongodb.log
    logappend = true
    
    # Only accept local connections
    bind_ip = 127.0.0.1
    

    One of the datadirectories and mongodb.logfiles you want to manually create your own

  • Start mongod services: mongod --config /opt/mongodb/mongod.conf &, & behind the increase is to service running in the background

Installation pm2

  • installation:npm install pm2@latest -g

  • Start node:pm2 start express/app.js

  • Restart:pm2 restart express/app.js

  • Open monitoring mode:pm2 monit

  • Startup configuration file:pm2 start pm2.json
    • Console.log can be configured to collect log files, etc.
    • Configure the number of instances open, pm2 do load balancing multiple instances
    • Details to view the files in this project pm2.json

Try your service

  • 3000 visit while in Tencent Tencent cloud start going through the cloud ip:: After starting the local node localhost visited by 3000

  • The 3000 can be followed by the port number to erase the configuration nginx, but you can now get yourself Tencent interfaces on the cloud server through bad way.

Skills

  • How to keep the ssh service connection is not?
    When using ssh command, the parameter setting can be increased ServerAliveInterval heartbeat time, for example 60 sec send a heartbeat packet: ssh -o ServerAliveInterval=60 [email protected]
    See: https: //ngwind.github.io/2019/01/25/%E4%BF%9D%E6% 8C% 81ssh% E6% 9C% 8D% E5% 8A% A1% E8% BF% 9E% E6% 8E% A5% E4% B8% 8D% E6% 96% AD% E5% BC% 80% E7% 9A% 84% E6% 96% B9% E6% B3% 95 /

reference:

  • Tencent cloud University https://cloud.tencent.com/edu
  • Tencent cloud computing Learning Paths lesson: https: //cloud.tencent.com/edu/paths/series/cloudcomputing
  • Tencent development environment to deploy Node cloud https://juejin.im/post/5abb32d2f265da23a141f35c

Guess you like

Origin www.cnblogs.com/zhangran/p/12066787.html