1、说明
记录一次远程 linux 部署 jar 的踩坑经历。事情大致上是这样,由于没有玩过 linux,第一次部署 jar 后,jar 运行成功,但是在外部 windows系统上访问部署在 linux 上的 jar 服务,总是访问不到,但是 ping linux ip 又一切正常。漫长的度娘和思考后,发现可能是 linux 的防火墙,对所部署的 jar 服务端口号不放行,于是一顿操作发现真是这个原因。关于开放特定端口号的防火墙限制,本文可能有不妥处,由于是 linux 小白,望大神指点。
2、踩坑过程
2.1 部署jar
先进入到 jar 包所在文件夹,使用命令:
nohup java -jar XXX.jar > log.file 2>&1 &
部署 XXX.jar 其中 log.file 为运行日志所在文件。
示例如下:
2.2 查看端口使用情况:
使用命令查看哪些端口号被使用:
netstat -ntlp
示例如下:
2.3 查看防火墙开放哪些端口
使用命令查看防火墙开放哪些端口:
more /etc/sysconfig/iptables
示例如下:
2.4 开放指定端口号的防火墙限制
开放端口号为5000的防火墙限制:
/sbin/iptables -I INPUT -p tcp --dport 5000 -j ACCEPT
示例如下:
接下来访问部署在 linux 上的 5000 端口服务,正常访问!