Alibaba cloud Centos7 deploys Java web [jar/war/virmach+vps + domain name service]

(1) Part 1: basic jar package running (Tomcat does not need to be configured)

[http://60.205.183.114:8081/]

  • 1. Configure Alibaba cloud (Esc student server, image Centos7.7) and connect to the terminal remotely.
  • 2. Install and configure the JDK (refer to https://www.jianshu.com/p/093413f2a04f)
    a) Install the jdk.

b) Find the jdk path configuration environment variable.
c) Simple Java hello world testing ensures a successful installation.

b)systemctl starts the service.
c) Open the port. (alicloud needs to open it on the console, please refer to https://yq.aliyun.com/articles/701181)
d) Change the root password of mysql, which corresponds to the password in the project configuration file.

b) Transfer the database sql file.

  • 5. Import database
    a) Create the database corresponding to the sql file.

b) Run sql file with file redirection.
c) Check whether the database is imported successfully

  • 6. Run the jar file, obtain the public IP from the console, and input the IP:8081 test.
  • 7. Set background run (set: http://60.205.183.114:8081/)
    a)contrl+c aborted.

b) Then run in the background through nohup and.
c)ps uses pid to stop the background running process.

Operation results
Overall process:

[root@iZ2ze4r3b4xcztbcsey08cZ ~]# history
    1   MAKRER=SHOW_LOCALE;printf $MAKRER""; locale; MAKRER=SHOW_LOCALE;printf $MAKRER"";
    2  yum install -y mysql
    3  yum install -y mariadb-server mariadb
    4  systemctl start mariadb
    5  systemctl enable mariadb
    6  yum install -y mysql-devel
    7  firewall-cmd --zone=public --add-port=3306/tcp --permanent
    8   CHECK_TYPE=SHELL; echo "INFO=${CHECK_TYPE} PID=$$ PPID=$PPID TTY=$(tty) SHELL=$0 HOME=$HOME PWD=$PWD| CHECK_SHELL_END"
    9  ls
   10  ifconfig
   11  ls
   12  yum list
   13  java -version
   14  ls
   15  yum search java-1.8
   16  yum -y install java-1.8.0-openjdk-devel.x86_64
   17  java -version
   18  cd /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64/
   19  pwd
   20  vim /etc/profile
   21  . /etc/profile
   22  vim Demo.java
   23  javac  Demo.java
   24  java Demo
   25  su
   26   MAKRER=SHOW_LOCALE;printf $MAKRER""; locale; MAKRER=SHOW_LOCALE;printf $MAKRER"";
   27   CHECK_TYPE=SHELL; echo "INFO=${CHECK_TYPE} PID=$$ PPID=$PPID TTY=$(tty) SHELL=$0 HOME=$HOME PWD=$PWD| CHECK_SHELL_END"
   28  mysql -u root
   29  ls
   30  pwd
   31  ifconfig
   32  ls
   33  mysql
   34  mysql -u root jpetstore < jpetstore.sql
   35  mariadb
   36  mysql
   37  java -jar mypetstore-0.0.3-SNAPSHOT.jar
   38  nohup java -jar mypetstore-0.0.3-SNAPSHOT.jar &
   39  ps
   40  history
[root@iZ2ze4r3b4xcztbcsey08cZ ~]# 

Console open port

Using scp to transfer files

Run mysql file

[root@iZ2ze4r3b4xcztbcsey08cZ ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database jpetstore;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> quit
Bye
[root@iZ2ze4r3b4xcztbcsey08cZ ~]# mysql -u root jpetstore < jpetstore.sql 
[root@iZ2ze4r3b4xcztbcsey08cZ ~]# mariadb
-bash: mariadb: command not found
[root@iZ2ze4r3b4xcztbcsey08cZ ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| jpetstore          |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> use jpetstore;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [jpetstore]> show tables;
+---------------------+
| Tables_in_jpetstore |
+---------------------+
| account             |
| addlog              |
| bannerdata          |
| browselog           |
| cart                |
| cartitem            |
| category            |
| inventory           |
| item                |
| lineitem            |
| orders              |
| orderstatus         |
| product             |
| profile             |
| sequence            |
| signon              |
| supplier            |
+---------------------+
17 rows in set (0.00 sec)

visit http://60.205.183.114:8081/

(2) Part 2: use Tomcat container to process war package (Tomcat is required)

[http://60.205.183.114:8080/myJPetStore_war/index.jsp]

b) Set access rights
c) Set service configuration
d) Input IP:8080 to test whether the service has been started

  • 2. Database / port configuration
    a) Database root password corresponds to server

b) Port configuration, port 8080 has been opened on it

  • 3. Use scp to transfer war package and put it into webapp (the file will be parsed directly)
  • 4. Restart tomcat service
    a)bin shutdown.sh

b)bin startup.sh

  • 5. Native test access
    a) Note the path of the resource to be added / myJPetStore_war/index.jsp , and then the tomcat container will automatically go to webapp to find

b) tomcat container set: http://60.205.183.114:8080/myJPetStore_war/index.jsp

Operation results
Overall process

   52  ls
   53  sudo mkdir /opt/tomcat
   54  sudo tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
   55  cd /opt/tomcat
   56  sudo chgrp -R tomcat /opt/tomcat
   57  sudo chmod -R g+r conf
   58  sudo chmod g+x conf
   59  sudo chown -R tomcat webapps/ work/ temp/ logs/
   60  sudo vi /etc/systemd/system/tomcat.service
   61  sudo systemctl daemon-reload
   62  sudo systemctl start tomcat
   63  sudo systemctl status tomcat
   64  sudo systemctl enable tomcat
   65  ls
   66  cd webapps/
   67  pwd
   68  ls
   69  sudo systemctl restart tomcat
   70  cd ../bin/
   71  ls
   72  sh shutdown.sh 
   73  sh startup.sh 
   74  history
[root@iZ2ze4r3b4xcztbcsey08cZ bin]# 

Using systemctl to view the status of tomcat

Verify that the tomcat service is turned on

Pass the war package directly into webapp

webapp then automatically parses the war package (myJPetStore_war)

[root@iZ2ze4r3b4xcztbcsey08cZ webapps]# pwd
/opt/tomcat/webapps
[root@iZ2ze4r3b4xcztbcsey08cZ webapps]# ls
docs  examples  host-manager  manager  myJPetStore_war  myJPetStore_war.war  ROOT

visit http://60.205.183.114:8080/myJPetStore_war/index.jsp

(3) Part 3: designated domain name for access

[http://crf.codes/]

  • 1. Configure virmach vps so that it can be accessed through IP
    a) The process is the same as the first step. Finally, it is set to run in the background.

b) Configured: http://198.12.120.212:8081/

  • 2. Server install web server (install nginx, refer to http://blog.kenyang.net/2019/02/26/upgrade-nginx-to-latest-version-on-centos)
  • 3. DNS domain name resolution is performed at the domain name provider name (or cloudflare) to request transfer.
    a)ping domain name (Ping crf.codes )Check whether the binding is successful.
  • 4. Modify nginx configuration file
    a)Web server setting domain name

b)Location configuration index interface
c) Open Linux system firewall
d) Visit crf.code http://crf.codes/

Operation results
Domain name provider (name) configuration dns

Verify that dns is configured successfully
ping crf.codes , you can see

Modify nginx configuration file

server {
    listen       80;
    server_name   crf.codes;

    #charset koi8-r;
    access_log  /var/log/nginx/host.access.log  main;

    location / {
        # root   /usr/share/nginx/html;
        index  index.html index.htm;
        proxy_pass http://127.0.0.1:8081/;
        # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

visit crf.codes

Tags: Java Tomcat MariaDB MySQL sudo

Posted on Sun, 31 May 2020 11:37:58 -0400 by LuAn