Newly installed virtual machine -2019-07-24 diary

Yesterday, newly installed a virtual machine, installed tomcat, jdk, ready to just throw up the application ran a play, and then the pit was discovered. . .

 

1, tomcat normal start is not being given, but the host is inaccessible, so he took

wget \ curl in a virtual machine to try, the results can pass, then I doubt firewall

  • Temporarily turn off the firewall
    systemctl stop firewalld
  • Self-closing boot permanent firewall
    systemctl disable firewalld
  • Temporarily open the firewall
    systemctl start firewalld
  • Firewall boot
    systemctl enable firewalld
  • Check firewall status
    systemctl status firewalld

After closing, the host will be able to visit, but the application can not access

https://blog.csdn.net/sudazf/article/details/50551822

 

2 to continue the second pit

At that time I did not pay attention to see this application is an application found in the git there to learn, and did not look carefully, a direct hit in a bag in the idea, but the embarrassing stuff here,

This application is based springboot, if want to deploy war directly coated with tomcat, packaged need to change the way, the need to change the code, POM; refer to the following manner

Here is a point, which is our springboot is integrated tomcat start all jar (no separate tomcat container can be started), so refer to the following documentation can be achieved

 https://blog.csdn.net/yalishadaa/article/details/70037846

The spring-boot program in accordance with the usual web project to publish the same vessel under tomcat

First, modify packaged form

Set in the pom.xml <packaging>war</packaging>

Second, remove the plug embedded tomcat

Found in pom.xml spring-boot-starter-webdependency nodes, the following code added thereto,

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除嵌入式tomcat插件 -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Third, adding a dependency of servlet-api

The following two methods can, optionally one

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

 

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-servlet-api</artifactId>
    <version>8.0.36</version>
    <scope>provided</scope>
</dependency>

Fourth, modify the startup class and override the initialize method

We usually start with the way the main method, there is a App start classes, as follows:

  1. @SpringBootApplication
    public class Application {
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }

We need a similar arrangement to start web.xml spring context, and add a class SpringBootStartApplication peer Application class, code is as follows:

/ ** 
 * Modify the startup class, and override inherited SpringBootServletInitializer configure method 
 * / 
public  class SpringBootStartApplication the extends SpringBootServletInitializer { 
 
    @Override 
    protected SpringApplicationBuilder configure (SpringApplicationBuilder Builder) {
         // attention here to point Application startup class originally performed by main method 
        return Builder .sources (the Application. class ); 
    } 
}

Under the project root directory (the directory that contains the pom.xml), type in the command line: 
mvn clean packageto wait for the completion of packing, there [INFO] BUILD SUCCESSis the packaging success. 
Then the war package under the target directory into the webapps directory of tomcat, tomcat startup, automatically unzip deployment. 
Finally, enter in your browser

http://localhost:[端口号]/[打包项目名]/

Successfully posted

 

 

3, and then start again the problem, run a local virtual machine or run with differences of Kazakhstan, with the database is local, then the virtual machine access will be a problem, embarrassed. . . .

solution:

If you want to connect this error occurs when your mysql:

ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server


1. Change table method. You may be allowed to log in to your account from a remote, only localhost. This time as long as that computer localhost, Login mysql, change the "mysql" database in the "user" table of "host" entry from "localhost" renamed "%"

mysql -u root -pvmwaremysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

2. Authorization Act. For example, you want to use myuser mypassword from any host connected to mysql server words.

. * * The GRANT ALL PRIVILEGES the ON the TO  'myuser' @ '%'  the IDENTIFIED BY 'mypassword' the WITH the GRANT the OPTION;
If you want to allow a user to connect to the host myuser 192.168.1.3 mysql server, and is used as a password mypassword from ip

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

 

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY '1235' WITH GRANT OPTION;

mysql> flush privileges; this sentence must be added! ! !

  • Temporarily turn off the firewall
    systemctl stop firewalld
  • Self-closing boot permanent firewall
    systemctl disable firewalld
  • Temporarily open the firewall
    systemctl start firewalld
  • Firewall boot
    systemctl enable firewalld
  • Check firewall status
    systemctl status firewalld

After closing, the host will be able to visit, but the application can not access

https://blog.csdn.net/sudazf/article/details/50551822

 

2 to continue the second pit

At that time I did not pay attention to see this application is an application found in the git there to learn, and did not look carefully, a direct hit in a bag in the idea, but the embarrassing stuff here,

This application is based springboot, if want to deploy war directly coated with tomcat, packaged need to change the way, the need to change the code, POM; refer to the following manner

Here is a point, which is our springboot is integrated tomcat start all jar (no separate tomcat container can be started), so refer to the following documentation can be achieved

 https://blog.csdn.net/yalishadaa/article/details/70037846

The spring-boot program in accordance with the usual web project to publish the same vessel under tomcat

First, modify packaged form

Set in the pom.xml <packaging>war</packaging>

Second, remove the plug embedded tomcat

Found in pom.xml spring-boot-starter-webdependency nodes, the following code added thereto,

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除嵌入式tomcat插件 -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Third, adding a dependency of servlet-api

The following two methods can, optionally one

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

 

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-servlet-api</artifactId>
    <version>8.0.36</version>
    <scope>provided</scope>
</dependency>

Fourth, modify the startup class and override the initialize method

We usually start with the way the main method, there is a App start classes, as follows:

  1. @SpringBootApplication
    public class Application {
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }

We need a similar arrangement to start web.xml spring context, and add a class SpringBootStartApplication peer Application class, code is as follows:

/ ** 
 * Modify the startup class, and override inherited SpringBootServletInitializer configure method 
 * / 
public  class SpringBootStartApplication the extends SpringBootServletInitializer { 
 
    @Override 
    protected SpringApplicationBuilder configure (SpringApplicationBuilder Builder) {
         // attention here to point Application startup class originally performed by main method 
        return Builder .sources (the Application. class ); 
    } 
}

Under the project root directory (the directory that contains the pom.xml), type in the command line: 
mvn clean packageto wait for the completion of packing, there [INFO] BUILD SUCCESSis the packaging success. 
Then the war package under the target directory into the webapps directory of tomcat, tomcat startup, automatically unzip deployment. 
Finally, enter in your browser

http://localhost:[端口号]/[打包项目名]/

Successfully posted

 

 

3, and then start again the problem, run a local virtual machine or run with differences of Kazakhstan, with the database is local, then the virtual machine access will be a problem, embarrassed. . . .

solution:

If you want to connect this error occurs when your mysql:

ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server


1. Change table method. You may be allowed to log in to your account from a remote, only localhost. This time as long as that computer localhost, Login mysql, change the "mysql" database in the "user" table of "host" entry from "localhost" renamed "%"

mysql -u root -pvmwaremysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

2. Authorization Act. For example, you want to use myuser mypassword from any host connected to mysql server words.

. * * The GRANT ALL PRIVILEGES the ON the TO  'myuser' @ '%'  the IDENTIFIED BY 'mypassword' the WITH the GRANT the OPTION;
If you want to allow a user to connect to the host myuser 192.168.1.3 mysql server, and is used as a password mypassword from ip

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

 

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY '1235' WITH GRANT OPTION;

mysql> flush privileges; this sentence must be added! ! !

Guess you like

Origin www.cnblogs.com/longxok/p/11237105.html