Linux安装Java环境
1、在usr目录下建立java安装目录
mkdir /usr/java
2、将jdk-11.0.18_linux-x64_bin.tar.gz拷贝到java目录下
jdk11下载地址:https://www.oracle.com/java/technologies/downloads/#java11
3、解压jdk到当前目录
tar -zxvf jdk-11.0.18_linux-x64_bin.tar.gz
4、安装完毕为他建立一个链接以节省目录长度
ln -s /usr/java/jdk-11.0.18 /usr/jdk11
5、编辑配置文件,配置环境变量
vi /etc/profile
6、在文本的末尾添加如下内容:
export JAVA_HOME=/usr/jdk11
export CLASSPATH=$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
7、执行命令刷新 :
source /etc/profile
8、查看是否安装成功
java -version
打包发布
1、在idea的maven中先clean,禁用test选项,后package打包,则可以在target目录中得到jar包文件;
2、将生成的jar包文件拷入/home/filename/中,app.sh脚本拷进filename中
3、sh app.sh start 运行app.sh文件则可以启动系统,watch.out为启动日志。
4、执行sh文件出错,将windows格式转换为unix格式。
yum install dos2unix
dos2unix app.sh
5、查看实时日志
tail -f watch.out
6、开放端口号并刷新
4、开放指定端口
firewall-cmd --zone=public --add-port=10090/tcp --permanent
5、重启防火墙
firewall-cmd --reload
app.sh脚本
#!/bin/sh
echo "======================================="
echo "Shell: $0"
# 获得本地路径
CURR_FOLDER=`pwd`
echo "Application folder: ${CURR_FOLDER}"
cd ${CURR_FOLDER}
# 获得jar文件的名字
JAR_NAME=`ls -l ${CURR_FOLDER} | grep .jar | grep -v grep | awk '{print $9}'`
echo "Application jar file: ${JAR_NAME}"
echo "======================================="
OUT_FILE="watch.out"
# 函数部分
hasrun(){
pid=`ps --no-heading -ef | grep ${JAR_NAME} | grep -v grep | awk '{print $2}'`
# -n 判断字符串长度不为0 -z 判断字符串长度为0
if [ -z ${pid} ]; then
echo 0
else
echo ${pid}
fi
}
start(){
# 是否已运行
result=$(hasrun)
if [ $result -ne "0" ]; then
echo "Application has already started, the pid is $result"
exit 1
else
# 启动程序
echo "Starting application ... "
nohup java -jar ${JAR_NAME} > ${OUT_FILE} 2>&1 &
echo "Application has started, the pid is $! you can check file in ${OUT_FILE} for deatils."
fi
}
stop(){
# 是否已运行
result=$(hasrun)
if [ $result -eq "0" ]; then
# 程序没有运行
echo "Application is not running ..."
exit 1
else
# 程序在运行中
echo "Stopping application ..."
kill ${result}
# 用循环的方式检测程序是否关闭
count=0
while [ $count -lt 1 ]; do
sleep 1s
count=0
exist=`ps --no-heading -p ${result}`
if [ -z ${exist} ] ; then
count=1
echo "Applicatoin has stoped."
fi
done
fi
}
restart(){
stop
start
}
case $1 in
"start")
start
;;
"stop")
stop
;;
"restart")
restart
;;
*)
echo "there is no command"
exit 1;
;;
esac
标签:java,部署,jar,系统,echo,--,sh,result,Linux
From: https://www.cnblogs.com/coolsheep/p/17324064.html