Ali cloud centos builds nodeJS server

Purchase Ali Cloud server

Logging In to the Cloud Server

For the first time login

SSH root@Cloud server external IP addressCopy the code

Create a user

useradd yourname
passwd yourname
Copy the code

Log back in

ssh yourname@ip
Copy the code

Install NodeJS using NVM

Switch to user root (high permission)

Use Git directly to clone the source code to the local ~/. NVM directory and check the latest version.

yum install git
git clone https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
Copy the code

Activate the NVM

echo ". ~/.nvm/nvm.sh" >> /etc/profile
source /etc/profile
Copy the code

In this step, a message may be displayed indicating that you do not have permission. You can change the permission to 777 and restore the permission after running the preceding command

chmod 777 /etc/profile
Copy the code

List all versions of Node.js

nvm list-remote
Copy the code

Install multiple versions of Node.js

NVM install v7.4.0 NVM install v10.15.1Copy the code

Run NVM use 10.15.1 to switch node.js to v7.4.0

Install postgreSql

Run the following commands in sequence

yum update -y yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm - y yum install Postgresql95 -server postgresQL95 -contrib -y /usr/pgSQL-9.5 /bin/ postgresQL95 -setup initdb systemctlenablePostgresql - 9.5. Service systemctl start postgresql - 9.5. ServiceCopy the code

verification

ps aux |grep postgres
Copy the code

Create a new user named pgone

createuser -s pgone
Copy the code

-s means to create user dbuser as superuser

Create a database named pg_db1

createdb pg_db1
Copy the code

Logging In to the Database

psql pg_db1 -U pgone
Copy the code

Where -u means to log in as user xx

Modify the postgres configuration file

In the default security policy, postgres is disabled for machine access. You need to modify postgres

9.5 / vim/var/lib/PGSQL/data/pg_hba. ConfCopy the code

At the end of the file, make the following changes

Systemctl restart postgresql 9.5. ServiceCopy the code

Adding a Security Group for a Cloud Server (Exposed Ports)

Log in ali Cloud console, click the left menu security group

Click Configure rules

Click Add Security Group Rule

The installation package

Git Clone pulls the code

Transfer the local installation package to the cloud server over SFTP

Local:

Tar CVF./demo.tar./demo SFTP username @ip put./demo.tarCopy the code

Cloud server:

tar xvf demo.tar
Copy the code

Deployment of pm2

Install the pm2

npm install pm2 -g
Copy the code

Pm2 start to open

Project entry

pm2 start index.js
Copy the code

Common commands

pm2 ls

Pm2 MonIT local monitoring

Pm2 logs View logs

Pm2 stop closing

Pm2 restart Restart (stop and start)

Pm2 reload No refresh restart