阿里云 Centos7 部署Java web [jar/war/nginx+域名服务]教程

本文涉及的产品
RDS AI 助手,专业版
RDS DuckDB + QuickBI 企业套餐,8核32GB + QuickBI 专业版
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介: 阿里云 Centos7 部署Java web [jar/war/nginx+域名服务]教程

(一)第一部分:最基本的jar包运行(无需配置tomcat)

1、配置阿里云(Esc学生服务器、镜像Centos7.7),并远程连接进入终端。
2、安装并配置JDK(参考https://www.jianshu.com/p/093413f2a04f)
申请阿里云服务时,可以使用2000元阿里云代金券,阿里云官网领取网址:https://dashi.aliyun.com/site/yun/youhui
a)安装jdk。
b)寻找jdk路径配置环境变量。
c)简单的Java hello world测试确保安装成功。

3、安装并配置mysql(mariadb)
a)安装mysql、mariadb server。
b)systemctl 开启服务。
c) 打开端口。
d) 更改mysql 的root密码,对应于项目配置文件中的密码。

阿里云服务器1核2G低至82元/年

4、利用scp进行文件传输
a)传输spring maven 的快照版本用于测试。
b)传输数据库sql文件。

5、导入数据库
a)创建sql文件对应的数据库。
b)利用文件重定向运行sql文件。
c)检查数据库是否导入成功

6、运行jar文件,控制台获取公网IP,本机输入IP:8081测试。
7、设置后台运行
a)contrl+c中止。
b)然后通过nohup 和 & 来后台运行。
c)ps通过pid来停止后台运行进程。

运行结果
整体过程:

[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 ~]#
控制台开端口

利用scp传文件
利用scp传文件.png

运行mysql 文件

[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)

访问http.png

(二)第二部分:利用Tomcat容器对war包进行处理(需要Tomcat)

1、安装Tomcat
a)本地下载tomcat,然后利用scp文件传输
b)设置访问权限
c)设置服务配置
d)输入IP:8080测试是否已经开启服务

2、数据库/端口配置
a)数据库root 密码 和服务器对应
b)端口配置,在上面已经开启了8080端口

3、利用scp传输war包,放到webapp里边(直接会解析出文件)
4、重启tomcat服务
a)bin下的shutdown.sh
b)bin下的startup.sh

5、本机测试访问
a)注意要添加访问的资源的路径/myJPetStore_war/index.jsp,然后tomcat容器会自动到webapp下去寻找
b) 已设置tomcat容器

运行结果
整体过程

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]#
利用systemctl查看tomcat的状态
利用systemctl查.png

验证是否开启tomcat服务
验证是否开启t.png

将war包直接传入webapp中
将war包直接.png

然后webapp会自动解析war包(即myJPetStore_war)

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

(三)第三部分:指定域名进行访问

1、配置virmach vps,达到可以通过IP进行访问
a)过程同第一步,最后设置为后台运行。
b) 已配置

2、服务器安装web server
3、在域名提供商 name(或者cloudflare)进行DNS域名解析,进行请求中转。
a)ping 域名(ping crf.codes)查看是否绑定成功。
4、修改nginx 配置文件
a)Web server 设定域名
b)Location 配置index界面
c)开放Linux系统防火墙
d)访问crf.code

运行结果
域名提供商(name)配置dns
域名提供商(name).png

验证dns是否配置成功
ping crf.codes,可以看到
可以看到.png

修改nginx配置文件

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;
#}

访问crf.codes
访问crf.png

相关文章
|
7月前
|
安全 Java API
Java Web 在线商城项目最新技术实操指南帮助开发者高效完成商城项目开发
本项目基于Spring Boot 3.2与Vue 3构建现代化在线商城,涵盖技术选型、核心功能实现、安全控制与容器化部署,助开发者掌握最新Java Web全栈开发实践。
700 1
|
7月前
|
弹性计算 安全 数据安全/隐私保护
2025年阿里云域名备案流程(新手图文详细流程)
本文图文详解阿里云账号注册、服务器租赁、域名购买及备案全流程,涵盖企业实名认证、信息模板创建、域名备案提交与管局审核等关键步骤,助您快速完成网站上线前的准备工作。
3390 84
2025年阿里云域名备案流程(新手图文详细流程)
|
7月前
|
存储 前端开发 Java
【JAVA】Java 项目实战之 Java Web 在线商城项目开发实战指南
本文介绍基于Java Web的在线商城技术方案与实现,涵盖三层架构设计、MySQL数据库建模及核心功能开发。通过Spring MVC + MyBatis + Thymeleaf实现商品展示、购物车等模块,提供完整代码示例,助力掌握Java Web项目实战技能。(238字)
834 0
|
7月前
|
监控 安全 网络协议
阿里云CDN域名怎么迁移到另一个账号?
阿里云CDN域名支持跨账号迁移,需确保原账号与目标账号均无欠费,且具备相应权限。仅支持单个迁移,需提前处理证书、回源鉴权及监控日志配置,避免业务中断。通过DNS或文件验证完成归属校验后,即可在控制台操作迁入。
|
7月前
|
弹性计算
阿里云域名备案流程(图文教程)2025年最新
2025年最新阿里云ICP备案流程图文教程,共5个步骤,最快2天完成备案。首先提交备案材料,阿里云初审(1个工作日内),通过后提交管局,接着进行工信部短信核验,最后等待管局审核(1-20天)。前4步最快1天完成,整体约2-21天。个人或企业均可操作,材料齐全更高效。需搭配阿里云中国大陆地域服务器备案。
5259 18
|
7月前
|
存储 域名解析 弹性计算
阿里云上云流程参考:云服务器+域名+备案+域名解析绑定,全流程图文详解
对于初次通过阿里云完成上云的企业和个人用户来说,很多用户不仅是需要选购云服务器,同时还需要注册域名以及完成备案和域名的解析相关流程,从而实现网站的上线。本文将以上云操作流程为核心,结合阿里云的活动政策与用户系统梳理云服务器选购、域名注册、备案申请及域名绑定四大关键环节,以供用户完成线上业务部署做出参考。
|
7月前
|
安全 数据建模 网络安全
阿里云SSL证书价格一年多少钱?单域名和通配符SSL证书收费价格表
阿里云SSL证书提供免费及多种付费选择,免费版为DigiCert品牌,有效期3个月。付费证书涵盖DV、OV、EV类型,支持DigiCert、GlobalSign等品牌,价格从238元至万元不等,满足不同网站安全需求。
1051 0
|
8月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
1422 69
|
7月前
|
存储 分布式计算 Linux
安装篇--CentOS 7 虚拟机安装
VMware 装 CentOS 7 不知道从哪下手?这篇超详细图文教程手把手教你在 VMware Workstation 中完成 CentOS 7 桌面系统的完整安装流程。从 ISO 镜像下载、虚拟机配置,到安装图形界面、设置用户密码,每一步都有截图讲解,适合零基础新手快速上手。装好之后无论你是要搭 Hadoop 集群,还是练 Linux ,这个环境都够你折腾一整天!
3101 3
|
8月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
702 78

热门文章

最新文章

下一篇
开通oss服务