The author Linux pure white, a front-end engineer, cheap purchase of an ECS server, operating system is CentOS 7.4 64-bit. Real from scratch to build their own server, stepped over a lot of pits, summed up this set of station guide, pro test effective!
Step 1
Recommended tools: Xshell6 and Xftp6
Xftp6 is a very convenient tool for Windows users who are familiar with the graphical user interface (GUI) and dragging and copying files.
Official Download page:
Xshell6: Download: Product Download
Xftp6: Download: Product Download
After entering the download page, select Evaluation User/Home & School User and fill in the information freely. The download address will be sent to the email address you filled in.
Step 2
Go to your one of the cloud server console, select your server instance, click: More – Reset password, set your cloud server login password
Step 3
Click remote connection, the first connection will pop up a remote connection password page, pay attention to the screenshot save (or take a small notebook to remember), after entering the remote connection password can connect to your cloud server.
Step 4
After successfully connecting to a cloud server, type any character, it will prompt you to login to the server, after login enter the account name: root (note, everyone here is root) and just set the login password (password is dark text input, is not displayed, you just enter it), and then it will prompt you to login successfully!
Step 5
Although a remote connection to a cloud allows us to operate the cloud server, I prefer to use Xshell to operate the cloud server. Here is how to use Xshell and Xftp.
First open Xshell and click on the menu bar: File — New, in the popup new session attribute, the name is optional, the host fill in the public IP address of your server (you can see it in the cloud server instance details), click OK, the new session window will appear on the left, double-click the session name to connect to the remote server. The next step is similar to remote connection, input remote connection password, account name root and login password, you can connect successfully.
Step 6
To open Xftp6, click the green button in the shortcut toolbar or click the menu bar: Window – New File Transfer. If you login successfully, Xftp will automatically log in and then happily drag and drop files to your server
2. Install node. js and Express in CentOS.
Tips: Common Linux directives
Ll -- View all files in the current directory.cd-- Equivalent to the Windows double click command to enter the specified folder for example:cd localIn the current directorylocalFolder For example:cd. Return to parent directoryCopy the code
Step 1: Download and install Node.js
Find the binary installation package (.xz file) for Linux in node. js and copy the link address
Connect to your server in Xshell and log in successfully, type the following code (paste the url you copied) to download Node.js. For consistency, it is recommended to install the Node file in the usr/local folder
cd
cd.cd usr
cd localWget HTTP: / / https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xzCopy the code
Find the Node file you just downloaded and type the following commands to unzip and rename it (whichever file name you downloaded) :
xz -dXz tar -xf node-v12.13.0-linux-x64.tar mv node-v12.13.0-linux-x64 nodeCopy the code
To verify that Node can be used, type
cd node/bin
./node -v
Copy the code
Check the Node version. If the installation is successful, the node version is displayed.
Step 2: Configure node.js environment variables
Next, it is important to configure the Node environment variable (otherwise you cannot use the Node and NPM directives anywhere globally) by entering the following directives in any path:
vim /etc/profile
Copy the code
The system will open the text editor, move the cursor to the bottom using the up or down key, press the [I] key to start the text editing, and type the following code at the end of the text (if your node is not installed under Local, please change the following NODE_HOME values)
#set nodejs env
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules:$PATH
Copy the code
When finished, press ESC to exit text editing and type the following commands to save and exit:
:wq
Copy the code
Type the following command to restart the configuration item for the environment variable to take effect
source /etc/profile
Copy the code
At this point, the Nodejs environment has been successfully configured. You can enter the following code in any path to check the version. If the version number is displayed, OK
node -v
npm -v
Copy the code
Install the Express framework
Next install the Express framework and type the following instructions in any path
npm install -g express
Copy the code
If you want to use express instructions globally, you also need to install express-Generator
npm install -g express-generator
Copy the code
After the installation is complete, you can check the version by following instructions. If the version number appears, the installation is successful
express --version
Copy the code
(3) Use Express to set up your server quickly
Type the following command in the path where you want to create the project (in this case, in usr/local), and you can change the name of the demo
express demo
Copy the code
Then go to the Demo folder, install the dependencies and use the text editor to edit the app.js file
cd demo
npm install
vim app.js
Copy the code
Move the cursor to the end of the app.js file, type [I] to start editing mode, and add the following statement at the end
app.listen(80, function () {
console.log("service is starting at 80")});Copy the code
Press ESC to exit editing and type the following command to save and exit the file
:wq
Copy the code
Then you can happily type the following command to start your server
node app
Copy the code
If the system displays “service is starting at 80”, the server is successfully started.
Type your public IP address and port number into the browser address to view the web page, such as 172.0.0.28:80
Wait, did you not see anything? That’s because there’s one more step! Go to your one of the cloud server console, go to ECS server instance details, and click this instance security Group
Congratulations! Your first server is officially ready! Open it from your browser address!
99 yuan for ECS server
Originally published in MeCC, welcome to follow me, hehe ~