How to publish your website to the Internet for free

Common servers that can be rented include Alibaba Cloud, Tencent Cloud, Huawei Cloud, etc. Here I introduce the trial of Alibaba Cloud.

1. Alibaba cloud server rental

(1) Choose the cloud server ESC, choose a one-month free trial, use the identity of an individual developer and choose the pre-installed system linux, mysql, etc.
![Insert picture description here](https://img-blog.csdnimg.cn/8f18de63c1174541b6f5014acc3b46e9.png
(2) First select the instance, reset the password, and operate as shown in the figure.
insert image description here(3) Select connection tools such as Xshell7 (the personal free version I use here), enter the public ip into the host, the user enters root, and enter the password you just set
![Insert picture description here](https://img-blog.csdnimg.cn/0c34203d7034471babeb70e21da77cc3.png

2. mysql local connection

(1) Mysql password reset
①Find etc/my.cnf, modify the file, and add a sentence under the [mysqld] label: skip-grant-tables
②Restart the database: service mysqld start
③Enter the database: mysql -u root
④Modify the data password command: UPDATE user SET authentication_string=password('myPassword') where user='root';
⑤Restart again, and use mysql -u root -plogin

(2) Local connection to mysql
① The connection method url is as follows, taking the yml file as an example

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
	url: jdbc:mysql://你的公网ip:3306/mysql?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
	username: root
    password: myPassword

There are two points to note here:
the first one is to pay attention to the version of mysql and the version of the locally connected mysql connector.
For details, check the official website link: https://dev.mysql.com/doc/connector-j/8.0/en /connector-j-versions.html.
The second is that MySQL can only log in through localhost or the loopback address 127.0.0.1 by default. If you want to log in with IP, you need to manually release the permissions. (It may report an error of Communications link failure)

grant all privileges on *.* to '用户名'@'IP地址' identified by '密码';
flush privileges;

② Modify the mysql database configuration, % means any ip can connect to mysql

update user set host = '%' where user = 'root' and host = 'localhost';
flush privileges;

③Add the gateway ip in the server console, configure the rules in the security group, open the mysql3306 port, and add the security rules as follows
insert image description here
insert image description here

3. Deploy the project

(1) jdk and tomcat environment (tomcat is not required to run the jar package)
①jdk
1. Download and install jdk
official website download: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
download Just unzip

tar -xvf jdk1.8.tar.gz

2. Configure the running environment
Find etc/profile and add the following configuration
jdk1.8 at the end of the file:

JAVA_HOME=/usr/local/java/jdk1.8
JRE_HOME=/usr/local/java/jdk1.8/jre
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:$PATH
export PATH JRE_HOME JAVA_HOME CLASSPATH

jdk1.11:

JAVA_HOME=/usr/tools/jdk-11.0.16.1
CLASSPATH=$JAVA_HOME/lib
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME CLASSPATH

Note that the original value of PATH here is the path of mysql /usr/local/apache/bin:/usr/local/php/bin:/usr/local/mysql/bin:, just add it on the original basis/usr/local/apache/bin:/usr/local/php/bin:/usr/local/mysql/bin:$JAVA_HOME/bin:$PATH

3. Make the profile file effective and check the result

source /etc/profile
 java -version

②tomcat
1. Download and install
Tomcat official website address: https://tomcat.apache.org/
Also download the tar package and use it tar -xvfto decompress it
2. Configure the environment
Find etc/profile and add the following configuration at the end of the file

CATALINA_BASE=/usr/local/apache/tomcat
PATH=$CATALINA_BASE/bin:$PATH
export PATH  CATALINA_BASE

3. Enter the bin directory

Open port 8080 on the Aliyun server, and add it with the secure port of mysql.
Use ./startup.sh to start, and use ip:8080 to view.
If it is not as good as being able to enter correctly at this time, it may be blocked by a firewall. Use the following command to release port 8080

systemctl unmask firewalld

systemctl start firewalld  

firewall-cmd --add-port=8080/tcp  --permanent

firewall-cmd --reload

(2) Deploy the jar package program
①Package package
xxx.jar through the clean\package of idea
②Run
and then execute xxx/xxx.jar in any directory to refer to the full path of the jar package
nohup java -jar xxx/xxx.jar 2> &1 &
There will be a startup log in the directory where the command is executed

(3) Deploy the war package program
①Package
In the project structrue-artifacts-web application:explored-from modules of Idea, you can find the war package you need to type, and then select clean\package to package aaa.war
insert image description here

②Run
Put the packaged aaa.war package in the webapps directory of tomcat, start tomcat, and log in to ip:8080/aaa to access

Guess you like

Origin blog.csdn.net/tttalk/article/details/126475415