Teach you how to deploy application services to Alibaba Cloud server (with docker basic teaching)

Preface

I have successfully deployed my system in the past two days, and there have been many problems during this period. I hereby record it and give it to readers who come to see it for convenience! Just do it step by step.
I bought it on Alibaba Cloud servers, and the servers on other platforms should be similar. Just follow the steps. This is the server address I purchased . Alibaba Cloud Student Server purchased 1 core 2G5M .

Buy server

After entering the page, we choose a lightweight application server with any length of time. The first purchase of this activity is a discount for students, as long as they are authenticated. Here I choose 12 months.
Insert picture description here
After clicking Buy Now, the configuration will pop up. Just choose the one closest to us for the region. For the type of image, we choose the system image CentOS, which is empty. If you choose an application image, some applications will be initialized in different application images, depending on the situation. It depends (I wouldn't say that because I installed the application mirror and finally my mentality exploded, I restored all the things I cried and changed to the system mirror o(╥﹏╥)o). We can directly use the original one. Then just buy it directly, because I have bought it, so it is more than 1,000...This is too expensive... The poor ghost is crying.
Insert picture description here
After buying it, enter our platform interface, you can see that the server information in the middle has a public network IP and an internal network IP. The public network means that we can access from external servers (such as our own computer), and the internal network IP is on the server. The address that can be accessed in. It is equivalent to that we can access 127.0.0.1. If allowed, you can configure a domain name, click enter to purchase, and then it can be used for filing analysis.
Insert picture description here
We can connect to our server by clicking on the remote connection in the upper right corner, or use software such as xShell to connect via ip, account and password. The unified account is root (it should be), and the right side of the password can be reset, or the system default can be used. This connection is entered.
Insert picture description here

Configuration project required configuration

After connecting to the server, we start to configure the configuration required for the project to run. I am using java project, so I need to install java JDK. We directly enter yum -y install java-1.8.0-openjdk * Run it and you can install jdk1.8 directly. If Jy is installed here,
Insert picture description here
it will not be installed. After installing jdk, if there are no other components such as database, Redis, etc., you can directly take the jar package to run, just jump directly to the part that introduces the jar package operation later .
Since there are other components used in Jy's application project, I have to continue to install it. Redis is used in my project, so I have to install redis. We directly use Docker for assembly, which is really easy to use, simple and fast. Students who have never known before can first learn about a wave of docker.
We can download docker by calling yum -y install docker .
Insert picture description here
Install it and change the source for docker, because the default source address is abroad, the download speed is extremely slow, we can't stand it.
Call vim /etc/docker/daemon.json to enter the docker configuration file and modify the source address.
Copy this code into it and it's OK.

{
    
    
 
"registry-mirrors":["https://registry.docker-cn.com"]
 
}

Then call systemctl restart docker to restart docker, that is, the source is successfully changed. There is the configuration needed to start downloading.
Insert picture description here
Start downloading redis. Before downloading, friends can first docker search redis to see which images are available for us to download. If you directly pull, it is to choose the default one. Just
Insert picture description here
choose our docker pull redis , and wait for him to download it.
After downloading, you can use docker images to view the downloaded image.
Insert picture description here
Once the mirror is available, you have to enable the mirror. Redis can be started with a custom configuration file. Here, you can start it simply and rudely. docker run -d -p 6379:6379 --name redis redis -d means background execution, -p means The 6379 port of the current server is mapped to the 6379 port in the docker container, -name sets the name of the container, and the last redis is the image name. After startup, you can view the started container through docker ps . (I think this is docker teaching...)
Insert picture description here
Then I also used rabbitmq. The configuration process is surprisingly similar, so I won't repeat nonsense. Nacos is also used as the registration center in the project. Nacos does not need to be installed by docker, we download it directly. Because nacos is surprisingly slow to download on the official website, of course Jy is ready for everyone here. Network disk link nacos1.3.1 password: zwol
everyone can go in, you can use windows to download and drag in first, or useDownload with wget command. After downloading or dragging it in, just find a folder and unzip it. Jy is placed in the /usr/local path
Insert picture description here
and then use tar -zxvf to compress the file name .tar.gz to decompress it, and a nacos folder will appear, cd nacos/bin , and then start the service. If it is started, ./startup . sh can be started. We can use the ip address: 8848/nacos to enter and view through the external network.
Here we have all configured. If you can't get in, you have to go to the firewall on the platform to open port 8848 to access the Internet.
In addition, if you have a small partner who bought a cloud database, you need to add the allowed IP address through a whitelist during configuration, otherwise you cannot access the database.

JAR package analysis, deployment service

Ok, here Jy has led everyone to configure all the configurations and systems, and the final step is to deploy. So what to deploy...Take SpringBoot as an example, we can use the jar package to deploy, then where is the jar package...
Open our idea, there is a Maven logo on the right, we click to open it, and click to the position of the picture. First use clean to clear the previously generated jar package, and then call package to generate a new jar package. (Additionally, if a small partner has no effect because of changing the configuration file under static, you also need to empty and repackage it) The
Insert picture description here
generated jar package is under the target of each module, and the one with jar behind it is. Then we sorted out the jar packages of multiple modules to the server first. Here I recommend a tool (also recommended to me by previous classmates) called WinSCP . Everyone can go up and down to Baidu. Jy forgot to download it because it took too long, anyway.
Insert picture description here
It looks like this when you open it. On the left is our windows, and on the right is the server we want to connect to. We click New Session to start the connection.
Insert picture description here
Just enter the account and password to connect, the same as the previous connection methods such as xShell.
Insert picture description here
After connecting, just drag our jar file into it. Jy is placed in the /home/admin directory.
Insert picture description here

ok, the last step, we start the jar package. There are some things to pay attention to here. If we deploy on the server, we cannot use the old version of java -jar xxx.jar . If this method is started, the service will be closed as the current window is closed. So we need to deploy in another way. I recommend a big guy's website, I also learned from this (the dish wants to cry). This is a big guy's article
I will briefly summarize which way we want to start.
nohup java -jar XXX.jar> /dev/null 2>&1 &
nohup java -jar xxx.jar & means to run the command without hanging up. When the account is exited or the terminal is closed, the program is still running. Note that all the output of this job is redirected to the nohup.out file. /dev/null 2>&1 means to output all output to /dev/null, /dev/null is a special file, and the content written to it will be discarded; if you try to read content from this file, Then nothing can be read. But the /dev/null file is very useful. Redirecting the output of a command to it will have the effect of "prohibiting output". Because we have internal logs, these outputs can be discarded.
We can start it like this, one jar package is executed once, and two jar packages are executed twice, both in the background.
Insert picture description here
This is done, everyone can go to the website to try the IP: The port is fine. If you can't access it, go to the application platform to see if the firewall is turned on.
Insert picture description here
Okay, then there is a problem again. Now that it is deployed in the background, there is nothing to see or eat, so how to close it when you want to close it. Jy must be ready for this kind of problem. We call ps -ef | grep java on the server because it is a java file, which can be found later with java.
This is the effect. The 29329 in front is what we used to close it. bykill -9 29329 can close it
Insert picture description here

Concluding remarks

That's all! I hope all the friends who see this article can successfully deploy the project.
In addition, I will post a wave of my website. Although it is not mature yet, I can barely read it hahaha. Future articles may be published on it first. Welcome everyone~ there is a blog that welcomes you

Guess you like

Origin blog.csdn.net/qq_41762594/article/details/107748973