In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Project needs, applied for three test machines, fortunately, there is nothing bare in the test machine, I can learn to play a good game! Next, in the form of picture and text, let's talk about the pit I encountered and the small harvest.
I. preparatory work
First of all, you need to have a linux server that you can play with and know your user name and password. Then you need to install two tools on your windows computer that can connect to the linux server, Xshell 5 and Xftp 5. The installation tutorial is not too much, and the supplementary picture shows how to connect to the server:
The xshell connection interface is as follows. Enter the host ip and click OK, and xshell will pop up a window to enter the user name and password to connect successfully!
Xftp connection interface is as follows, fill in the blanks on it, very simple not to say, mention here why to choose SFTP rather than FTP, see the difference between FTP and SFTP to know how much can understand!
II. Installation and deployment
If you want to deploy a project to a linux server, it is necessary to install jdk and tomcat. It is important to emphasize here that if you want to deploy multiple applications on one server, you need to have your own tomcat for each application, because the configuration of tomcat is definitely different under different applications. In this case, you can install a tomcat installation directory and a working directory for tomcat under multiple applications. For the same part of the tomcat that can share the installation directory, here is a detailed description of how to do it and how to install tomcat and jdk to your server
1. Catalogue division
This is a very important step. You can create a new directory as shown below. Under the directory, you can put some files related to project startup and deployment access. You can see that I have placed multiple versions of jdk and multiple versions of tomcat under this directory. Which tomcat and jdk are used in the project deployment process can be implemented through configuration.
For practical applications, we specifically place the name of each application in an instance directory, and then place the corresponding war package and the decompressed files under the directory, waiting for tomcat to read the directory and deploy the application, as follows:
two。 Modify configuration
We also put the tomcat under each application under a directory for easy management, as shown below, but we should pay attention to the configuration of each tomcat.
Under the / bin directory, both the start.sh file and the stop.sh file need to be modified. First, specify the jdk path, which is similar to configuring the environment variable. The second is to specify the tomcat path of the tomcat working directory. You can notice that CATALINA_HOME and CATALINA_BASE correspond to the installation directory and working directory of tomcat, respectively. Then you can see from the last line that the project starts using the start.sh under the installation directory, but the tomcat configuration file used for project startup is the configuration file configured by each application tomcat. The same goes for stop.sh.
Permission is required for using xshell to execute. / start.sh and. / stop.sh. If there is no permission, we can use xftp to modify the permission for start.sh email, as shown in the figure, check it.
Under the / conf directory, you need to pay attention to the modified configuration: first, the server.xml file. Modify the corresponding port number. The tomcat of each application needs to modify a different port number, otherwise the port will be occupied and cannot be started when starting multiple tomcat. It is best to remember the port number of the tomcat configured by this application, which will be used later when using nginx for port mapping.
Another area to modify is the ROOT.xml file in the localhost directory under the Catalina directory, which is used to specify the project instance in which directory to load when tomcat starts.
Other / logs directory, / temp directory, / webapps directory, / work directory do not need to be modified; as can be seen from the above, the directory division is very clear, which is divided into service installation directory (jdk, tomcat, nginx, etc.), application instance directory, and application deployment directory. You can also use linux server to deploy multiple projects in this way.
Implementation of Port 80 reverse proxy with 3.nginx
According to reason, at this time, we can upload our own application war package to the corresponding directory to decompress, and then go to the corresponding application tomcat working directory to execute. / start.sh can start the project! You might as well have a try first.
After the project is deployed, we have configured hosts to start accessing. At this time, we will find that we have to add the tomcat port number configured above to access it. Can we access it without adding the port number (using the default port 80)? As mentioned above, we have configured different port numbers for different tomcat. The reason is that a port number can only be used by one tomcat, which means that project access must be added with port number access. However, to ensure that every application can use port 80 access, we can also do it. At this time, we need to use nginx. After installing nginx, we can add some configurations to achieve reverse proxy. The port 80 access used by different applications is forwarded to the corresponding port number. In tomcat's view, the external request still uses the port number configured by tomcat, which achieves the desired effect. The specific configuration is as follows (of course, we have to do the corresponding directory partition work):
The nginx directory is as follows:
We only need to care about the nginx.conf configuration file under the / conf directory. I also opened the specific configuration information to show you. Did you notice the last line, "include domains/*", which means that the configuration is not finished and contains all the configuration files under the / domains directory?
At this time, we can configure the nginx of each application with a different named file.
Then let's take a look at how to configure it. Listen for auction.center.jd.net:80 domain name access, and then forward it to port 1605 of the native 127.0.0.1. From the configuration, we can also see that some abnormal states, such as http_500 http_502 http_504, will be recorded and handled differently. In general, you can jump to the home page of the website, etc., and then log. After configuring this configuration file, we must not forget to create a new log directory, otherwise nginx can not find the directory, startup will report an error.
After all this work, we need to restart nginx. I won't say much about how to restart it. There are many related materials on Baidu. If the restart fails, let's just kill the nginx process, and then use the nginx service start command to start the nginx service.
After we have done all this work, will we be able to access it in the way we are familiar with (without adding the port number)? yes, that's right. Many people are worried about whether to restart tomcat and redeploy the application. That only shows that you do not understand the nginx route translation layer of the network layer. The domain name we visit is first parsed by DNS through the hosts we configured and converted to the corresponding Ip. Find the server corresponding to ip, go through the server's firewall, and then when we configure Nginx on the server, Nginx will first intercept the request, process and distribute the request, and finally call the corresponding tomcat (personal understanding, may not understand enough, do not spray), then we can confidently visit the domain name to send the request!
4. Step on the pit
Uh.. Not good! Empty joy, jump to the home page, still can not access the specified application, when I tried to add the port number, "miraculously" can access, which shows that our configuration of Nginx does not work, what is the problem?
Let's talk about my ideas for solving the problem. first of all, we have to make sure that all requests go to Nginx, which reflects the benefits of logging. When we use port 80 to access our application, stare at the log twice and three times. There is no log, at this time, we can roughly conclude that there is no Nginx service at all, and we are not sure that the nginx service does not work for the server, because maybe there is something wrong with our log configuration. At this time, I made a bold operation, that is, turn off, access the nginx service, or jump to the home page of the website. What happened? Isn't it configured to jump to the home page through nginx? Indeed, the company has already dealt with it at the network layer. At this time, I was very confused and made all kinds of attempts. You might as well modify the tomcat configuration and configure one of the applications to port 80, so that you can always access it. Soon, the modification is completed and deployed, waiting for the address bar to enter the domain name for access, because the Nginx service has been shut down. At this time, the request must be called directly to the tomcat and visited twice or three times. Miraculously unable to access, Nani? At this time, a flash, absolutely is the server firewall disabled port 80, quickly try in the local telnet 192.168.108.37 80 really can not access, proved that my guess is right, this time is easy to do, as long as the firewall open port 80 access, the following supplement under the CentOS under how to configure iptables firewall to release port 80.
1. Open the iptables configuration file with the following code: vi / etc/sysconfig/iptables
two。 Through / etc/init.d/iptables status, the command queries whether port 80 is open, and if not, it can be handled in two ways
3. The first way is to modify the vi / etc/sysconfig/iptables command to make the firewall open port 80, as follows:
The copy code is as follows:-A RH-Firewall-1-INPUT-m state-- state NEW-m tcp-p tcp-- dport 80-j ACCEPT
4. The firewall code for shutting down / enabling / restarting is as follows: / etc/init.d/iptables stop (# start enabled, # restart restart)
5. The second way: add the port through the command, the code is as follows:
[root@centos httpd] # / sbin/iptables-I INPUT-p tcp-- dport 80-j ACCEPT [root@centos httpd] # / etc/rc.d/init.d/iptables save [root@centos httpd] # / etc/init.d/iptables restart
6. View results: [root@centos httpd] # / etc/init.d/iptables status
7. In addition, the second method is recommended, which is easy to operate and has a high success rate. Take me, for example, when I use the first way to modify the firewall configuration, the restart fails, using the second way, it is a perfect success.
III. Summary
The final result is also expected, even if the tomcat is configured with port 1605, we can still use port 80 to access, this is the power of nginx, but a few megabytes of installation package, can actually play so much role, this is I just learned the introduction to nginx, understand is very crude, but through this practice let me have a good feeling to nginx, slowly I will learn to know (although can not know each other).
Add: so much of the above is based on some basic linux commands, for do not know how to create files, modify files, upload war package, start tomcat, view the process, view logs and other basic commands, it is best to learn the basic linux commands first, slowly you will find that many things that can be done with the xftp visual interface, we prefer to use command operations.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.