Hands with you set up your own cloud server and deploy Web applications

A. Purchase server

  1. I chose Ali cloud server, student price 9.5 yuan a month, Baidu direct search Ali cloud, then click on the upper right corner sign in, we recommend scan code to log Alipay, convenient and quick. Ali cloud more thing official website, login I am looking for a long time but could not find a server where students sell to buy when students need to be authenticated, according to his requirements like step by step, the certification takes about a couple of hours. If you are not a student would like to buy it ecs server, you can see the purchase of addresses Home ecs server, but the server is a lot more expensive than the students. Here to say about pre-selected environment, because most servers are linux system, linux centos in use is up, it is recommended that you also choose centos system, and then select the application image, the role of the main application image It is to help you pre-installed server environment, such as mysql, apache, tomcat these, and some will give you a management server panel for easy operation on the server. Application image may or may not, if you just want to quickly configure the server, it is recommended that you install linux pagoda panel, easy to use, if you want to learn or already know some use linux, you can ignore the application image. If it is used to learn the words of the geographical choice does not matter, you can choose from a near own.

2. After purchasing server successfully entered in the top right corner of the home of Ali cloud console, the console has a sidebar lightweight esc servers or server that is student server, click to enter the server you can see buy their own, the lower right corner is the ip address of your server, then to use.

II. Configuring servers

1. First set the root password click remote connections, which are connected to the server to use.

2. Then click the Add rule in the firewall ports open, I opened the port in order to facilitate the figure. You can also open these ports only 21,22,443,8080, if you are using a pagoda linux, you also need to open port 8888.

III. Manually set up a server environment

The server now have, how to use it? If you want to use the command line to manually set up the environment, the best we have to have some understanding of linux command, if you do not want to use linux command to quickly build environment, and the panel pagoda linux installed, please see Part IV directly .

  1. Tools to prepare
    we need two software to connect to the server, called Xshell, used to manipulate the server, the other is called Xftp, used for file transfer between the server and your computer. Direct Baidu or 360 can be downloaded to the treasure house of these two software .

The connection 2.Xshell
use Xshell is very convenient, first enter the IP address of your own server, you have the IP address of the server, click the link at the bottom right of Ali cloud server list, and then enter the user name root, enter the password you set in front root password, when the screen displays welcome to alibaba cloud when you explain the connection is successful.

The connection 3.Xftp
Xftp login and Xshell Similarly, enter the server IP, enter the root user, then enter the root password, the login is successful, the left border as a file on your computer, the right to file on the server, drag to the left and right upload and download files.

4.JDK installation of
these two software after installing the server environment, we can begin to build, because it is a learning environment with simple, not complicated by high, so do not use nginx, apache or redis these, java environment using a simple the tomcat + mysql, we need to use the environment to build Xshell to complete. Before installing tomcat we must first be installed jdk, jdk installed on linux system is very simple, I use the 1.8 version of the jdk, yum -y install java-1.8.0 -openjdk.x86_64 run command, Complete appears on the screen when the installation was successful. Then you can run java -version, showing the current release notes java no problem.

5.Tomcat installation
followed tomcat installation, not the source tomcat yum, it is necessary to download wget manner, first to switch to the next through the directory opt cd / opt.

运行命令wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.32.tar.gz
src="https://yqfile.alicdn.com/ac733c3534aaa8aedbfb616ce5d0603cc01eaf56.png" alt="image" title="image">

After we have finished tomcat compressed package to the next opt ​​directory, then we run the command tar xzf apache-tomcat-8.5.32.tar.gz to unpack the archive.

Now we are in the file Xftp can see these two documents, we can click decompression after pressing F2 to rename tomcat8.5, help us use the command line to operate on him.

Run /opt//tomcat8.5/bin/startup.sh run tomcat, display tomcat started, illustrate the successful launch of the

We can also enter netstat -anp | grep 8080 to see 8080

This time we are able to access from outside the network, access to your server ip address plus port number directly in your browser, for example http://39.107.104.52:8080/ , if successful visit to explain our tomcat has been configured a.

6.mysql installation of
the yum mysql resources as a problem, not just the use yum. You must also use other mysql command to get Community Edition before using yum, execute the command wget  http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm .

This time we can be installed via yum, execute yum install mysql mysql-server mysql-devel -y, the last display complete the installation was successful.

After a successful installation, we have to start mysql server through systemctl start mysql.service, then we can still perform netstat -anp | grep 3306 command to see if mysql start.

By yum install mysql is the administrator account without a password, set here by the command with the password admin, you can also set other, execute the command mysqladmin -u root password admin.

Note: Warning message does not prompt settings fail, but to tell you the password exposed, be careful someone behind.

7. Project and upload the database
we log in mysql -uroot -padmin command database, admin is the password, if you set became a different password here to replace themselves through CREATE DATABASE xxx DEFAULT CHARACTER SET utf8; command execution show databases after creating a database, remember the commands executed after entering the database to add a semicolon, xxx is the database name, the name was changed to the database you want to create when you create, you can create ;, see the database you created . Many times we are a local database After creating the import to the server , we first need to use Xftp database files to the server, we can use mysql -u root -padmin --default-character- set = utf8 xxx </ home / xxx.sql command to import database, xxx is the database name, / home / xxx.sql path data file. After the import operation is complete, we have to log in again by mysql -uroot -padmin command database, execute use xxx;, and then view the database show tables ;, imported.

Upload the project is relatively simple, we only need to project directly into tomcat's webapps directory can be, or will be packaged into a project file into the war, the war file is automatically parsed after the restart tomcat. The command to shut down tomcat /opt/tomcat8.5/bin/shutdown.sh, close and reopen complete restart.

This time you'll be able to access your project a foreign network, such as http://39.107.104.52:8080/shop/

Server set up here even if completed, if you want to do on your server to further optimize and improve the access speed and performance of the server site, see Part V --Nginx of use, use nginx Another advantage is that you can removed in 8080 without a backup (under normal circumstances we do not back up the site is unable to remove the port number to use the site default port 80), for example, can be http://39.107.104.52:8080/shop become http : //39.107.104.52/shop

IV. Pagoda panel linux environment to build

  1. Pagoda panel login
    using pagoda panel is simple, first of all from the console into the server management page, then enter the application details, click Copy

Then remote connection, the connection is successful, right to copy and paste the content, press Enter to run, will show password pagoda panel, copy it down.

Quit remote connections, click the panel home address.

Username is admin, password is copied immediately after the remote connection password.

  1. Software installing and configuring
    the software managed to find a successful login in the sidebar

Installation tomcat and mysql, I installed tomcat version 8.5, mysql version 5.7.

During this time of waiting for installation, we first open ports, click Security sidebar, 8080 release.

After installation is complete, we can then have access from outside the network to tomcat page. Access as http://39.107.104.52:8080/ , IP address to be replaced with the IP address of your server.

Upload database

From the sidebar into the database, click Add a database, the password can be randomly generated, you can also set up their own.

After successfully added Click Import to the local upload the sql database files to the server .

Upload project

Click tomcat in the software management file location, enter tomcat.

Open the tomcat webapps folder, click the top left corner of uploading, after the project file or project into the war package to restart tomcat.

This time you'll be able to access your project a foreign network, such as http://39.107.104.52:8080/shop/

Server set up here even if completed, if you want to do on your server further optimization, improve access speed and performance of the server site , see Part V --Nginx of use, use nginx Another advantage is that you can removed in 8080 without a backup (under normal circumstances we do not back up the site is unable to remove the port number to use the site default port 80), for example, can be http://39.107.104.52:8080/shop become http : //39.107.104.52/shop

V. server performance optimization (using the Nginx)

Nginx is a reverse proxy server, nginx can be achieved using static and dynamic separation and load balancing, static and dynamic separation means that when the user requests from nginx handle static requests, tomcat handle dynamic requests reduces the load tomcat, so you can focus on processing tomcat dynamic requests. Load balancing refers nginx can simultaneously connect a plurality of clusters tomcat tomcat i.e., forwards the request to the user dynamically equalized to each tomcat. So, Nginx how to use it?

1. Use the pagoda panel installation configuration Nginx
find Nginx click to install the software management, where I installed the 1.14 version.

Nginx needs to be configured after the installation is complete, click the nginx settings, go to Settings page, click Configure modify, delete all the original configuration file, change the following:

user  www www;
worker_processes auto;
error_log  /www/wwwlogs/nginx_error.log  crit;
pid        /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events

{
    use epoll;
    worker_connections 51200;
    multi_accept on;
}

http

{
    include       mime.types;
    #include luawaf.conf;

    include proxy.conf;

    default_type  application/octet-stream;

    server_names_hash_bucket_size 512;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 50m;

    sendfile   on;
    tcp_nopush on;

    keepalive_timeout 60;

    tcp_nodelay on;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
    gzip_vary on;
    gzip_proxied   expired no-cache no-store private auth;
    gzip_disable   "MSIE [1-6]\.";

    limit_conn_zone $binary_remote_addr zone=perip:10m;
    limit_conn_zone $server_name zone=perserver:10m;

    server_tokens off;
    access_log off;

upstream tomcats{

ip_hash;
server 39.107.104.52:8080;
server 39.107.104.52:8081;

}

server

{
    listen 80;
    server_name localhost;
    index index.html index.htm index.jsp;
    root  /www/server/myadmin;
  
    
    #error_page   404   /404.html;
    include enable-php.conf;

location / {

proxy_pass http://tomcats;
  
}

location ~ .(gif|jpg|png)$ {

   expires 30d;
   access_log off;
    root /www/server/myadmin;
}

一键申请SSL证书验证目录相关设置

location ~ \.well-known{
    allow all;
}
    access_log  /www/wwwlogs/access.log;
}

include /www/server/panel/vhost/nginx/*.conf;
}

This configuration file, we must understand the content has two parts, the file upstream tomcats in is our tomcat address, that is, nginx receives the dynamic requests to be forwarded address, here I am outside tomcat pagoda install in addition to, and manually install a tomcat, were installed tomcat tomcat installation please refer to part III in 8080 and 8081 ports manually, if you do not want to manually install, where you can write only one, the other will be deleted, so that only Nginx static and dynamic separation, ip_hash refers to the binding user IP, to prevent the problem after replacing the tomcat session appear, each ip only have access to a tomcat which, after these words deleted refresh the page several times you will find that you will visit different tomcat. server in the root / www / server / myadmin refers to the root of our store static files, nginx will look for files in this directory when a static requests. location ~ (gif | jpg | png ). $ means that when a request to .gif | .jpg | judged as static files directly to the root directory to find the end .png, other requests are forwarded to tomcat, of course, you can the css, js and other documents determined to be a static file, simply .js, .css added to the inside can be. Once configured, you can go visit the project, such as http://39.107.104.52:8080/shop/ can be modified to http://39.107.104.52/shop/ access, and then you will find items in the picture gone, because all with .gif | .jpg | request .png files ending nginx are blocked, we need to put these files in the root directory of nginx, but change the picture path of the project, such as the path / picture /1.png refers /www/server/myadmin/picture/1.png. Here for nginx not elaborate on the specific configuration, if you are interested in nginx, I can leave a message below, I made detailed video tutorial for you

2. Manually install Nginx
because I'm using a pagoda linux install Nginx, not personally operate manually install Nginx, it is recommended to everyone another blog https://www.cnblogs.com/taiyonghai/p/6728707.html , manually install Nginx is more complicated, interested friends can go and see. About Nginx configuration, you can refer to what I have written.

Blog here came to an end, I hope you can help and, finally, tell you is that one thing in the use Ali cloud server, any problems can be submitted work orders in the console, so programmers to Ali to help you solve the problem, but the ticket response rate may be slower.

Original link
This article Yunqi community original content may not be reproduced without permission.

Released 2315 original articles · won praise 2057 · Views 1.54 million +

Guess you like

Origin blog.csdn.net/yunqiinsight/article/details/105301364