Ali cloud centos7 server deployment springboot project, project packaging, upload, install jdk8, tomcat8, mysql5.7

0, you first need to purchase a lightweight Ali cloud server, I sell a student machine packages. The system I chose centos7.24 the age and identity of the certification, students can buy packages, student packages Address: https://promotion.aliyun.com/ntms/act/campus2018.html

Had wanted to plan a cheap buy a single product, has been found not selected:

Always pop this thing, how is this election.

There is no way to force me to buy aliyun student packages:

Hell he was able to chose: it wants to buy.

Students can not buy packages can be purchased as follows:

You can choose to create an instance into the purchase on the first page:

1, the first installed in front of me, Baidu bunch of garbage tutorial article, according to the operation, a lot of the pit, cause my server installation mess, which is set, so I'm going to re-initialize the disk, becomes the new Linux system to facilitate the later installation. If this is the first installation of the new machine to skip this first step.

      ->       

The server needs to stop off in order to re-initialize the disk:

Came the configuration information here:

I will jump here:

Need to re-set the server password:

This password is to use our remote connection to the server, and then verify the message is the need for two-dimensional code. After the completion of the re-start a new instance of the disk.

 

2, the cloud server management console -> Mirror instance -> example, the public network ip address, remote connectivity worse this time passwords, we need to reset your password:

              ->             

 

3, download and install XShell, with his connection to the remote server, I'm not here to provide a download link and install the tutorial, you need the resolve on their own.

  • Connection account: public network server ip
  • Connection password: we reset the password

 

4, connected up, and we need to upload something you need to install a software:

yum install lrzsz

After a successful installation, we enter the command:

rz

A file selection box will pop up to let us upload a file, this time we can upload files. Here to do some preparation for the subsequent uploads.

 

5, first installation jdk1.8:

Came to the official website: https://www.oracle.com/cn/java/technologies/javase-downloads.html

Copy Link Location. There may let you log in, I offer here one may expire:

https://download.oracle.com/otn/java/jdk/8u241-b07/1f5b5a70bf22433b84d0e960903adac8/jdk-8u241-linux-x64.tar.gz

Then use wget command to download, if there is no prompt wget command, we need to install: yum install wget

wget fight on the link you copied

Local test link timeout, can not download, I downloaded locally and then upload go up.

The following installation :( Sometimes you just copy the full path and command below, may be error, you need to fill in order reloading the file name, press the tab key will auto-complete)

  • First create a new directory: mkdir / usr / the Java
  • Was added to extract the executable permissions and / usr / Java: the chmod + X-8u241 JDK-Linux-x64.tar.gz
  • Extracting:  the tar-8u241 the xzf JDK-Linux-x64.tar.gz -C   / usr / Java
  • Set the environment variable: VI / etc / Profile        Press   i  key to add the following:
  • # set java environment
    export JAVA_HOME=/usr/java/jdk1.8.0_241
    export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
    export PATH=$JAVA_HOME/bin:$PATH
  • Save and exit: press the  esc  key, plus    : wq      Enter.
  • Run    source / etc / profile     command to load environment variables.
  • Run    java -version    command displays JDK version information.

Successful installation.

 

6, before installing tomcat, we need to do some preparatory actions:

  • Ali cloud server management console, in the left navigation bar, click Network and Security> Security group.
  • Add a set of ports 80, for future operation.
  • Permanently turn off the firewall: systemctl disable firewalld
  • Close SELinux, view the status: getenforce
  • Disabled is turned off, Enforcing the ON state. We want to permanently shut him: Run the command vi / etc / selinux / config edit SELinux configuration file. Enter, move the cursor to SELINUX=enforcingthe line, press ienter the edit mode, modify SELINUX=disabled, press Escand then enter :wqand press Enter to save and close SELinux profile.
  • Creating www average user to run Tomcat: useradd www
  • Create a site root directory:  mkdir -p / the Data / wwwroot / default
  • Java Web project will need to deploy the WAR file package uploaded to the web root directory and the website root directory file permissions to www. In this example, the following command will be run in order to create a new Tomcat test page directly in the web root directory and the website root directory file permissions to www:
  • echo Tomcat test > /data/wwwroot/default/index.jsp
  • chown -R www.www /data/wwwroot

 

7, installation tomcat8: wget  https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz

The link also from the official website: https://tomcat.apache.org/download-80.cgi

  • Decompression: tar xzf the Apache-Tomcat-8.5.51.tar.gz
  • Rename the Tomcat directory: mv the Apache-Tomcat-8.5.51 / usr / local / Tomcat /
  • Set user rights: chown -R & lt www.www / usr / local / Tomcat /
  • webapps directory under tomcat to put our war package.
  • cd /usr/local/tomcat/conf/
  • Edit the server.xml file: vi server.xml
  • The following copy into it: you can access the project through ip address, you need to change the connection port 80, so each time you visit you do not need to write a 8080 port
  • <?xml version="1.0" encoding="UTF-8"?>
    <Server port="8006" shutdown="SHUTDOWN">
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
    <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
    <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
     type="org.apache.catalina.UserDatabase"
     description="User database that can be updated and saved"
     factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
     pathname="conf/tomcat-users.xml"/>
    </GlobalNamingResources>
    <Service name="Catalina">
    <Connector port="8080"
     protocol="HTTP/1.1"
     connectionTimeout="20000"
     redirectPort="8443"
     maxThreads="1000"
     minSpareThreads="20"
     acceptCount="1000"
     maxHttpHeaderSize="65536"
     debug="0"
     disableUploadTimeout="true"
     useBodyEncodingForURI="true"
     enableLookups="false"
     URIEncoding="UTF-8"/>
    <Engine name="Catalina" defaultHost="localhost">
    <Realm className="org.apache.catalina.realm.LockOutRealm">
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
      resourceName="UserDatabase"/>
    </Realm>
    <Host name="localhost" appBase="/data/wwwroot/default" unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="/data/wwwroot/default" debug="0" reloadable="false" crossContext="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
    prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    </Host>
    </Engine>
    </Service>
    </Server>
  • Set JVM memory parameters: vi /usr/local/tomcat/bin/setenv.sh

  • Add the following into account: JAVA_OPTS = '- Djava.security.egd = file: / dev /./ urandom -server -Xms256m -Xmx496m -Dfile.encoding = UTF-8' 

  • Setting Tomcat since the launch script: wget https://github.com/lj2007331/oneinstack/raw/master/init.d/Tomcat-init

  • Download successful show like this:

  • Rename the init-Tomcat: mv Tomcat-the init /etc/init.d/tomcat

  • Add executable permissions: chmod + the X-/etc/init.d/tomcat

  • Provided startup script the JAVA_HOME: Sed -i 'S @ ^ Export JAVA_HOME=.*@export the JAVA_HOME = / usr / Java / jdk1.8.0_241 @' /etc/init.d/tomcat

  • Setting Tomcat boot from the start: chkconfig --add Tomcat 

  • chkconfig tomcat on    

  • Start Tomcat: Service Start Tomcat

  •                          

 

8, install MySQL: https://blog.csdn.net/qq_41723615/article/details/93001225

 

9, upload the sql file, the database project I use the mysql, I need to project to the next sql dump stored. Rz command input, select our local store sql file upload.

 

10, create a database, and run our sql file: Source xxx.sql

 

11, we need to give our projects labeled as war bag before packing, we need to modify some of the resources in the project path, if there are pictures or other resources to the project document, as well as database connection configuration also need to be modified.

For example, we intend to install in centos mysql, and create a database named myweb, mysql need to set up an account and password, the project configuration will change overnight.

Project Resource path to change the root of the site we set and I am not going to use the object store, all directly put into the server in the cloud Ali.

Find the current directory command: pwd

 

The project labeled as war package:

  • Add dependence:
  • <dependency><!--打war包第一步-->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
  • Will build into:
  • <build>
        <finalName>myweb</finalName><!--打war包第二步-->
        <plugins>
            <plugin>
                <!--<groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>-->
    
                <!--打war包第三步-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • Add to:
    <packaging>war</packaging><!--打war包第四步-->
  • Master Boot class needs to inherit something, and rewrite:
  • @SpringBootApplication
    public class MywebApplication extends SpringBootServletInitializer {
    
        /**
         * 需要把web项目打成war包部署到外部tomcat运行时需要改变启动方式
         */
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            return builder.sources(MywebApplication.class);
        }
    
        public static void main(String[] args) {
            SpringApplication.run(MywebApplication.class, args);
        }
    
    }
  • Use cmd into the local project root directory, use the mvn command to fight the war package: MVC Package Penalty for Clean
  • An error may occur:  No Compiler IS Provided in the this Environment Perhaps you are running the JRE ON A A The Rather Within last the JDK.?
  • I do not know how to solve this problem? Internet that need jdk inside jre, there are two jre, need to distinguish. I choose here to use the idea to package:
  • Select Package Location:
  • Create a directory out of the box:
  • Select the classes directory:
  • We selected the project, point ok.
  • Such projects can be run in a manner war package and a jar.
  • Then our war package can be uploaded to our website in the root directory of the server settings.

 

12, the public network can not access the ip: 8080 how to do?

You can use the command to find the problem, enter tomcat / bin directory: ./catalina.sh & RUN 

I have here is the emergence of the port is occupied port occupies one of the 8006

View this port: netstat -anp | grep 8006

Kill the process: kill -9 xxxx

 

 

Published 753 original articles · won praise 72 · views 130 000 +

Guess you like

Origin blog.csdn.net/qq_41723615/article/details/104861425