第一步:准备项目jar包上传启动一顿操作
在idea中将项目打成jar包

这里就会生成jar包,然后找到他

上传前先用xshell连接好阿里云ECS服务器,并且创建一个mkdir /root/java目录
这是root目录下就多了个java目录

cd java/切入这个目录然后上传打包好的文件jar包

上传好后查看一下,有了

执行以下命令运行jar包启动项目
java -jar (你的jar包-web-1.0-SNAPSHOT.jar)

启动成功

不用试了,肯定不能访问,看过上次我介绍的访问mysql的就知道,你得配置阿里云ECS实例的安全组,添加端口才行。
第二步:阿里云ECS安全组设置

常用的端口就一次都配置一下吧,然后用postman访问我项目接口,ok成功了
但是如果开启了防火墙,那么对不起访问不了是这样的

注意此时我的防火墙是关闭的,执行命令查看
service iptables status

查看防火墙开放的端口号
firewall-cmd --list-ports

执行失败,说明防火墙确实没开,但是如果开启你想访问就会被墙掉,想要访问必须开放相应端口,那么先开启iptables

这里有必要搞清楚iptables和firewall
iptables与firewall的关系,iptables用于过滤数据包,属于网络层防火墙,firewall能够允许哪些服务可用,那些端口可用,属于更高一层的防火墙。firewall的底层是使用iptables进行数据过滤,建立在iptables之上
好了看看能不能访问

显然是不可以的,需要开放端口,具体操作为
进入到目录:cd /etc/sysconfig,修改iptables命令:vi iptables 加上一条:-A INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8088 -j ACCEPT
也可以通过xftp客户端,或者之前上传文件时打开的xftp客户端找到这个文件打开编辑加入保存

然后重启让其生效

此时再次访问接口,发现依然不能访问,关闭后可以访问,打开后并开放了8088端口居然还是不能访问,此时的firewall防火墙是关闭的,我们打开它,查看配置了哪些端口
systemctl start firewalld.service
firewall-cmd --list-ports

此时依然不能访问,所以添加8088端口到防火墙中
firewall-cmd --zone=public --add-port=8088/tcp --permanent

访问成功

有点懵,我们捋一捋,首先关了iptables和防火墙是可以访问的,而启动iptables修改iptables添加8088相应端口配置不能成功访问,之后开启防火墙firewall添加8088端口配置是可以访问的,再次查看发现启动iptables后firewall防火墙就被停止了,启动防火墙后发现iptables被干停了。
总结:
1.二者都不开起,是可以访问的
2.只开启iptables并配置端口后依然不能访问
3.只开启firewall并配置端口是可以访问的
4.折腾这么多就是只关心防火墙有没有开放端口就行了,要么关掉防火墙,要么开启后开放端口。
网友评论