How to quickly build your own server detailed tutorial (Java environment)

How to quickly build your own server detailed tutorial (Java environment)

1. Purchase of Server

1. I chose Alibaba Cloud's server, which is priced at 9.5 yuan per month for students. Search Alibaba Cloud on Baidu and click on the upper right corner to log in. I recommend that you log in by scanning the QR code with Alipay, which is quick and convenient. There are a lot of things on Alibaba Cloud’s official website. After logging in, I searched for a long time but couldn’t find where to sell student servers. Finally, I found this website in the consultation, https://promotion.aliyun.com/ntms/campus2017.html. When purchasing, you need to undergo student certification. Just follow his requirements step by step. The certification takes about a few hours. If you are not a student, you can directly purchase an ecs server. You can see the purchase address of the ecs server on the homepage, but it is much more expensive than a student server. Here I want to talk about the choice of pre-installed environment, because most servers are Linux systems, and CentOS is the most widely used among Linux, so it is recommended that you choose the CentOS system, and then the choice of application image. The function of application image is mainly to help you pre-install the server environment, such as MySQL, Apache, Tomcat, etc. Some will also provide you with a server management panel to facilitate server operation. Application images are optional. If you just want to quickly configure the server, we recommend that you install the Baota Linux panel, which is very convenient to use. If you want to learn or already know some usage of Linux, you can ignore the application image and configure it manually. If you are going to study, the choice of location doesn’t matter, you can choose one that is close to you.

2. After successfully purchasing the server, enter the console in the upper right corner of the Alibaba Cloud homepage. In the sidebar of the console, there is an esc server or lightweight server, which is a student server. After clicking to enter, you can see the server you purchased. The IP address of your server is in the lower right corner, which will be used next.

2. Server Configuration

1. First, click on Set root password in remote connection, which is required to connect to the server.

2. Then click Add Rule in the firewall to open the port. Only after the port is opened can others access the program or service on the server. Since I am using it for my own study, there is no security issue. For convenience, I opened all ports. You can also open only ports 21, 22, 443, and 8080. If you are using Baota Linux, you also need to open port 8888.

3. Manually build the server environment

Now that the server is available, how do I use it? If you want to use the command line to manually build the environment, it is best for everyone to have some understanding of Linux commands. If you do not want to use Linux commands to build the environment, and have installed the Baota Linux panel, please go directly to the fourth part, you can quickly and easily complete the environment construction and use the panel to control the server. If you want to learn about Docker and use it to complete the environment setup, please see Part 6.

1. Tool Preparation

We need two software to connect to the server. One is called Xshell, which is used to remotely connect to the server, and the other is called Xftp, which is used to transfer files between the server and your own computer. You can download these two software directly from Baidu or in the 360 ​​Treasure House. If you have already installed git, you can also use git or the command line tools that come with Mac to use ssh and scp to connect to the server and transfer files.

2.Xshell connection

Xshell is very easy to use. First, enter the IP address of your server. Your server's IP address is in the lower right corner of the Alibaba Cloud server list. Click Connect, then enter root as the username and the root password you set earlier as the password. When the screen displays "welcome to alibaba cloud", it means you have connected successfully.

3. Xftp connection

The login of Xftp is similar to that of Xshell. Enter the server IP, the user enters root, and then enters the root password. After a successful login, the left frame is the files on your own computer, and the right is the files on the server. Drag left and right to upload and download files.

4. JDK installation

After installing these two software, we can start setting up the server environment. Because it is a simple environment for learning and the concurrency is not high, we do not use nginx, apache or redis. The java environment used is a simple tomcat+mysql. We need to use Xshell to complete the environment construction. Before installing tomcat, we must first install jdk. The installation of jdk on the Linux system is very simple. I use version 1.8 of jdk. Run the command yum -y install java-1.8.0-openjdk.x86_64. When Complete appears on the screen, it means that the installation is successful. Then you can run java -version, which will show that there is no problem with the current java version.

5.Tomcat installation

Next is the installation of tomcat. There is no tomcat source on yum, so you need to download it using wget. First, switch to the opt directory via cd /opt.

Run the command wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.32.tar.gz. The address after wget is the download address on the official website. Some students reported that they could not download it. In that case, you can find other tomcat download addresses on the Internet and change them.

After the execution is complete, we have downloaded the tomcat compressed package to the opt directory, and then we run the command tar xzf apache-tomcat-8.5.32.tar.gz to decompress the compressed package.

Now we can see these two files in Xftp. We can click the unzipped file and press F2 to rename it to tomcat8.5, which is convenient for us to operate it using the command line, or we can execute the command mv apache-tomcat-8.5.32 tomcat8.5 to change the name.

Execute the command /opt//tomcat8.5/bin/startup.sh to run tomcat. If tomcat started is displayed, it means that the startup is successful.

We can also enter netstat -anp | grep 8080 to view port 8080

At this point we can access it from the Internet. Directly access your server IP address plus port number on your browser, for example, http://39.107.104.52:8080/. If the access is successful, it means that our tomcat has been configured.

6. Installation of mysql

There is a problem with the mysql resources on yum, so you can't just use yum. Before using yum, you need to use other commands to obtain the MySQL community version. Execute the command wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm, and continue to execute rpm -ivh mysql-community-release-el7-5.noarch.rpm.

At this time, we can install it through yum, execute yum install mysql mysql-server mysql-devel -y, and finally display complete, which means the installation is successful.

After successful installation, we start the MySQL server through systemctl start mysql.service, and then we can still execute the netstat -anp|grep 3306 command to check whether MySQL is started.

The administrator account of MySQL installed through yum has no password. Here, set its password to admin through the command. You can also set it to other values ​​by executing the command mysqladmin -u root password admin.

Note: The Warning message does not indicate that the setup has failed, but rather tells you that your password has been exposed, so be careful of someone behind you.

7. Upload of projects and databases

We log in to the database through the mysql -uroot -padmin command. admin is the password. If you have set another password, please change it to your own password here. Create a database through the CREATE DATABASE xxx DEFAULT CHARACTER SET utf8; command. Remember to add a semicolon after the command executed after entering the database. xxx is the database name. Change it to the database name you want to create when creating it. After creation, execute show databases; to see the database you created. In many cases, the database is created locally and then imported to the server. We first need to use Xftp to transfer the database file to the server. We can import the database through the mysql -u root -padmin --default-character-set=utf8 xxx < /home/xxx.sql command, where xxx is the database name and /home/xxx.sql is the path of the data file. After the import operation is completed, we log in to the database again through the mysql -uroot -padmin command, execute use xxx;, and then show tables; to view the imported database.

Uploading the project is relatively simple. We only need to put the project directly into the webapps directory of tomcat, or package the project into a war file and put it in. After restarting tomcat, the war file will be automatically parsed. The command to shut down Tomcat is /opt/tomcat8.5/bin/shutdown.sh. After shutting down, reopen it to complete the restart.

At this time, you can access your project on the external network, for example, http://39.107.104.52:8080/shop/.

The server setup is now complete. If you want to further optimize your server to improve the website access speed and server performance, please see the fifth part - the use of Nginx. Another advantage of using nginx is that you can remove port 8080 without backing up the website (normally we cannot remove the port number and use the website's default port 80 if we don't back up the website). For example, you can change http://39.107.104.52:8080/shop to http://39.107.104.52/shop.

4. Building the Baota Linux Panel Environment

1. Login to Baota Panel

The use of Baota panel is relatively simple. First, enter the server management page from the console, then enter the application details, click Copy

Then connect remotely. After the connection is successful, right-click to paste the copied content, press Enter to run, and the password of the Pagoda panel will be displayed. Copy it.

Exit the remote connection and click the panel home page address.

The user name is admin and the password is the password you copied after connecting remotely.

2. Software Installation and Configuration

After successful login, find the software management in the sidebar

Install tomcat and mysql. I installed tomcat version 8.5 and mysql version 5.7.

While waiting for the installation, we open the port first. Click Security in the sidebar and release port 8080.

After the installation is complete, we can now access the tomcat page from the external network. Visit http://39.107.104.52:8080/, and replace the IP address with the IP address of your own server.

Upload Database

Enter the database from the sidebar and click Add Database. The password can be randomly generated or set by yourself.

After adding successfully, click Import to upload the local sql database file to the server.

Upload Project

In the software management, click the file location of tomcat to enter tomcat.

Open the webapps folder of tomcat, click Upload in the upper left corner, put the project file or the war package of the project in, and restart tomcat.

At this time, you can access your project on the external network, for example, http://39.107.104.52:8080/shop/.

The server setup is now complete. If you want to further optimize your server to improve the website access speed and server performance, please see the fifth part - the use of Nginx. Another advantage of using nginx is that you can remove port 8080 without backing up the website (normally we cannot remove the port number and use the website's default port 80 if we don't back up the website). For example, you can change http://39.107.104.52:8080/shop to http://39.107.104.52/shop.

5. Server performance optimization (Use of Nginx)

Nginx is a reverse proxy server. Using nginx can achieve dynamic and static separation and load balancing. Dynamic and static separation means that when processing user requests, nginx handles static requests and tomcat handles dynamic requests, which reduces the load of tomcat and allows tomcat to focus on processing dynamic requests. Load balancing means that nginx can connect to multiple tomcats, namely tomcat clusters, at the same time, and forward the user's dynamic requests to each tomcat in a balanced manner. So, how to use Nginx?

1. Use the pagoda panel to install and configure Nginx

Find Nginx in the software management and click to install. Here I installed version 1.14.

After the installation is complete, you need to configure nginx. Click nginx settings to enter the settings page, click configuration modification, delete all the original configuration files, and change them to 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;
 }
#One-click application for SSL certificate verification directory related settings location ~ \.well-known{
 allow all;
 }
 
 
 access_log /www/wwwlogs/access.log;
 }
include /www/server/panel/vhost/nginx/*.conf;
}

There are two parts in this configuration file that we must understand. The upstream tomcats in the file is our tomcat address, which is the address that nginx will forward after receiving dynamic requests. Here, in addition to the tomcat installed by Baota, I manually installed another tomcat, on ports 8080 and 8081 respectively. For manual installation of tomcat, please refer to the tomcat installation in the third part. If you don’t want to install it manually, you can only write one here and delete the other, so that Nginx only does dynamic and static separation. ip_hash refers to binding user IP to prevent session problems after changing tomcat. Each ip can only access one tomcat. After deleting this sentence and refreshing the page a few times, you will find that you will access different tomcats. The root /www/server/myadmin in server refers to the root directory where we store static files. When there is a static request, nginx will look for files in this directory. location ~ \.(gif|jpg|png)$ means that when a request ends with .gif|.jpg|.png, it is judged as a static file and is searched directly in the root directory. Other requests are forwarded to tomcat. Of course, you can also judge css, js and other files as static files by adding .js and .css to them. After the configuration is complete, you can access the project. For example, http://39.107.104.52:8080/shop/ can be changed to http://39.107.104.52/shop/ for access. At this time, you will find that the pictures in the project are gone, because all file requests ending with .gif|.jpg|.png are intercepted by nginx. We need to put these files in the root directory of nginx and change the picture path in the project. For example, the path /picture/1.png refers to /www/server/myadmin/picture/1.png. I won’t go into details about the specific configuration of nginx here. If you are interested in nginx, you can leave me a message below and I will send you a detailed video tutorial.

2. Manually install Nginx

Because I used Nginx installed by Baota Linux and did not manually install Nginx myself, I recommend another blog to you https://www.jb51.net/article/189359.htm. Friends who are interested can go and have a look. Regarding the configuration of Nginx, you can refer to what I wrote above.

6. Installation of docker

Docker requires the CentOS kernel version to be higher than 3.10. Check the prerequisites on this page to verify whether your CentOS version supports Docker.

1. Update the software library

yum update -y

2. Install Docker

yum install docker -y

3. Start the docker service

service docker start

4. Other related commands

service docker restart // Restart the docker service service docker stop // Stop the docker service

The following situation occurred when resetting the system on Mac and connecting again:

Execute ssh-keygen -R the IP address you want to access.

This concludes this article on how to quickly build your own server with a detailed tutorial (Java environment). For more information on building a Java server environment, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Java obtains the server environment example detailed explanation
  • Detailed explanation of Java environment variables and Tomcat server configuration

<<:  Implementation example of scan code payment in vue project (with demo)

>>:  Detailed explanation of the principle and usage of MySQL stored procedures

Recommend

React non-parent-child component parameter passing example code

React is a JAVASCRIPT library for building user i...

Summary of nginx configuration location method

location matching order 1. "=" prefix i...

Six important selectors in CSS (remember them in three seconds)

From: https://blog.csdn.net/qq_44761243/article/d...

CSS implements the web component function of sliding the message panel

Hello everyone, I wonder if you have the same con...

JavaScript to implement simple tab bar switching content bar

This article shares the specific code of JavaScri...

Steps to deploy hyper-V to achieve desktop virtualization (graphic tutorial)

The hardware requirements for deploying Hyper-V a...

Play with the connect function with timeout in Linux

In the previous article, we played with timeouts ...

Summary of common functions of PostgreSQL regular expressions

Summary of common functions of PostgreSQL regular...

MySQL 8.0.12 installation and configuration method graphic tutorial (windows10)

This article records the installation graphic tut...

How to use cookies to remember passwords for 7 days on the vue login page

Problem Description In the login page of the proj...

Analysis of three parameters of MySQL replication problem

Table of contents 01 sql_slave_skip_counter param...

How to design MySQL statistical data tables

Table of contents Is real-time update required? M...