记录一次全新的Java项目部署过程
一、初始环境准备
yum install wget -y
yum install vim -y
yum install net-tools -y
mkdir /data
mkdir /data/html
mkdir /data/backend
一、安装JDK 17
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
sudo yum -y install ./jdk-17_linux-x64_bin.rpm
java -version
java version "17.0.11" 2024-04-16 LTS
Java(TM) SE Runtime Environment (build 17.0.11+7-LTS-207)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.11+7-LTS-207, mixed mode, sharing)
二、安装和配置Nginx
1 安装nginx
yum install epel-release
yum install nginx -y
2 配置nginx
cd /etc/nginx/conf.d/
vim sh.conf
三、安装redis
yum install redis -y
service redis start
service redis stop
service redis status
ps -ef | grep redis
chkconfig redis on
vi /etc/redis.conf
- 查找 requirepass并修改密码
四、测试环境打包
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.7.166
plat=${1}
folder=/data/chaiyou/oils-backend-template
distFolder=/data/chaiyou/bash/dist/server/
cd ${folder}
git pull
./gradlew :oils-backend:build -x test -x processTestResources -x checkstyleMain -x spotbugsMain -x verifyMergedCoverage -x compileTestJava -Dorg.gradle.java.home='/usr/local/jdk-17.0.8' -Dorg.gradle.daemon=true
if [ $? -ne 0 ];then
echo " build fail "
exit 1
fi
scp ${folder}/oils-backend/build/libs/oils-backend-0.0.1-SNAPSHOT.jar root@192.168.7.166:/data/backend/
ssh root@192.168.7.166 << remotessh
cd /data/backend
bash restart.sh
exit
五、服务器上的重启脚本
- 检查端口是否被占用的脚本(8080/8081端口交替使用)
- checkPort.sh(位于/data/backend)
#!/bin/bash
port=${1}
pIDa=`lsof -i :${port}|grep -v "PID" | awk '{print $2}'`
if [ "$pIDa" != "" ];
then
echo "1"
else
echo "0"
fi
port=8080
portOld=8081
datestr=`date +"%Y%m%d%H%M%S"`
echo $datestr > date.log
isPortInUse=`bash ./checkPort.sh ${port}`
if [ "$isPortInUse" == "1" ];
then
echo "端口不可用"
port=$[$port+1]
portOld=8080
else
portOld=8081
echo "端口可用"
fi
echo '准备在端口'${port}'启动docker'
nohup java -Dspring.profiles.active=test -Dserver.port=${port} -jar oils-backend-0.0.1-SNAPSHOT.jar > output.${port}.log 2>&1 &
echo '正在启动程序,请耐心等待'
tail -f /data/backend/output.${port}.log | sed '/Started OilsApplication in\|JVM running for/q'
echo '准备修改nginx配置并重启'
echo 'proxy_pass http://127.0.0.1:'${port}'/web/;' > /etc/nginx/conf.d/server.stream
echo 'proxy_pass http://127.0.0.1:'${port}'/wx/;' > /etc/nginx/conf.d/server.wx.stream
echo 'proxy_pass http://127.0.0.1:'${port}';' > /etc/nginx/conf.d/doc.stream
nginx -s reload
echo '10秒后向原服务发出退出请求'
sleep 10
echo '正在请求原程序优雅退出'
exitResult=`curl http://127.0.0.1:${portOld}/systemd/graceful/exit`
echo '优雅退出结果:'${exitResult}
if [ "$exitResult" != "1" ]; then
echo '优雅退出失败'
exit 1
else
echo '优雅退出成功'
fi
六、安装tesseract
yum install tesseract -y
yum install tesseract-langpack-deu -y
七、提前准备好RDS