不用重新打包,直接替换项目jar 包中的log4j2 的 jar 包
source /etc/profile
# xxx包路径
RDMS_DDM_HOME=/usr/setup/ddm/work_ddm/rdms_proxy
# xxxx包路径
DDM_HOME_BIGDATA=/usr/setup/ddm/work_ddm/bigdata_proxy
#时间
CURRENT_DATE="`date +%Y%m%d%H%M%S`"
# xxx包路径
DDM_HOME=/usr/setup/ddm/work_ddm/admin/
#关系型log4j jar包替换
function rdms_log4j()
{
if [ -d /usr/setup/ddm/work_ddm/rdms_proxy ] ; then
RDMS_RDMS_DDM_HOME=/usr/setup/ddm/work_ddm/rdms_proxy
fi
mkdir $RDMS_DDM_HOME/lib/jarbak$CURRENT_DATE
#删除重复升级的可能的影响
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager.sh
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager.zip
#拆包
head -291 $RDMS_DDM_HOME/lib/proxy_file_manager.jar > $RDMS_DDM_HOME/lib/proxy_file_manager.sh
#解压
unzip $RDMS_DDM_HOME/lib/proxy_file_manager.jar -d $RDMS_DDM_HOME/lib/proxy_file_manager
#升级log4j jar包
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager/BOOT-INF/lib/log4j-api-2.11.2.jar
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager/BOOT-INF/lib/log4j-core-2.11.2.jar
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager/BOOT-INF/lib/log4j-jul-2.11.2.jar
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager/BOOT-INF/lib/log4j-slf4j-impl-2.11.2.jar
#新包覆盖
cp -rf *.jar $RDMS_DDM_HOME/lib/proxy_file_manager/BOOT-INF/lib/
#重新打包
pushd $RDMS_DDM_HOME/lib/proxy_file_manager
jar -cfvM0 $RDMS_DDM_HOME/lib/proxy_file_manager.zip *
popd
#备份安装包
mv $RDMS_DDM_HOME/lib/proxy_file_manager.jar $RDMS_DDM_HOME/lib/jarbak$CURRENT_DATE
#组包
cat $RDMS_DDM_HOME/lib/proxy_file_manager.sh $RDMS_DDM_HOME/lib/proxy_file_manager.zip > $RDMS_DDM_HOME/lib/proxy_file_manager.jar
#删除解压后的文件
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager.sh
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager.zip
rm -rf $RDMS_DDM_HOME/lib/proxy_file_manager
chmod a+x $RDMS_DDM_HOME/lib/*.jar
systemctl restart camphord
}
# 管理端log4j jar包替换
function uplog4j_admin()
{
#多安装目录自动判断
if [ -d /usr/setup/ddm/work_ddm/admin ] ; then
DDM_HOME=/usr/setup/ddm/work_ddm/admin
fi
CURRENT_DATE="`date +%Y%m%d%H%M%S`"
mkdir $DDM_HOME/lib/jarbak$CURRENT_DATE
#删除重复升级的可能的影响
rm -rf $DDM_HOME/lib/admin
rm -rf $DDM_HOME/lib/admin.sh
rm -rf $DDM_HOME/lib/admin.zip
#拆包
head -291 $DDM_HOME/lib/admin.jar > $DDM_HOME/lib/admin.sh
#解压
unzip $DDM_HOME/lib/admin.jar -d $DDM_HOME/lib/admin
#升级jar包
rm -rf $DDM_HOME/lib/admin/BOOT-INF/lib/log4j-api-2.11.2.jar
rm -rf $DDM_HOME/lib/admin/BOOT-INF/lib/log4j-core-2.11.2.jar
rm -rf $DDM_HOME/lib/admin/BOOT-INF/lib/log4j-jul-2.11.2.jar
rm -rf $DDM_HOME/lib/admin/BOOT-INF/lib/log4j-slf4j-impl-2.11.2.jar
#新包覆盖
cp -rf *.jar $DDM_HOME/lib/admin/BOOT-INF/lib/
#重新打包
pushd $DDM_HOME/lib/admin
jar -cfvM0 $DDM_HOME/lib/admin.zip *
popd
#备份安装包
mv $DDM_HOME/lib/admin.jar $DDM_HOME/lib/jarbak$CURRENT_DATE
#组包
cat $DDM_HOME/lib/admin.sh $DDM_HOME/lib/admin.zip > $DDM_HOME/lib/admin.jar
rm -rf $DDM_HOME/lib/admin.sh
rm -rf $DDM_HOME/lib/admin.zip
rm -rf $DDM_HOME/lib/admin
chmod a+x $DDM_HOME/lib/*.jar
systemctl restart ddm-admin
}
#非关系型log4j jar包替换
function uplog4j_bigdata()
{
cd $DDM_HOME_BIGDATA/lib
mkdir $DDM_HOME_BIGDATA/lib/jarbak$CURRENT_DATE
for file_name in `ls *.jar`
do basename $file_name .jar
done > ls.log
#循环文件夹下文件
for fileName in $(cat ls.log)
do
head -291 $DDM_HOME_BIGDATA/lib/${fileName}.jar > $DDM_HOME_BIGDATA/lib/${fileName}.sh
unzip $DDM_HOME_BIGDATA/lib/${fileName}.jar -d $DDM_HOME_BIGDATA/lib/${fileName}
rm -rf $DDM_HOME_BIGDATA/lib/${fileName}/BOOT-INF/lib/log4j-api-2.11.2.jar
rm -rf $DDM_HOME_BIGDATA/lib/${fileName}/BOOT-INF/lib/log4j-core-2.11.2.jar
rm -rf $DDM_HOME_BIGDATA/lib/${fileName}/BOOT-INF/lib/log4j-jul-2.11.2.jar
rm -rf $DDM_HOME_BIGDATA/lib/${fileName}/BOOT-INF/lib/log4j-slf4j-impl-2.11.2.jar
#新包覆盖,修改路径
cp /home/setup/admin.jar $DDM_HOME_BIGDATA/lib/${fileName}/BOOT-INF/lib/
#重新打包
pushd $DDM_HOME_BIGDATA/lib/${fileName}
jar -cfvM0 $DDM_HOME_BIGDATA/lib/${fileName}.zip *
popd
#备份安装包
mv $DDM_HOME_BIGDATA/lib/${fileName}.jar $DDM_HOME_BIGDATA/lib/jarbak$CURRENT_DATE
#组包
cat $DDM_HOME_BIGDATA/lib/${fileName}.sh $DDM_HOME_BIGDATA/lib/${fileName}.zip > $DDM_HOME_BIGDATA/lib/${fileName}.jar
rm -rf $DDM_HOME_BIGDATA/lib/${fileName}.sh
rm -rf $DDM_HOME_BIGDATA/lib/${fileName}.zip
rm -rf $DDM_HOME_BIGDATA/lib/${fileName}
done
chmod +x $DDM_HOME_BIGDATA/lib/*.jar
systemctl restart ddm-proxy-bigdata
}
rdms_log4j
uplog4j_admin
uplog4j_bigdata
rm -rf $DDM_HOME_BIGDATA/lib/ls.log
log4j2 补丁包地址:log4j_2.1.5.zip-Java文档类资源-CSDN下载
将jar 包上传到/home/setup 目录下,然后执行脚本
注:脚本中需要升级的jar 包目录变量需要替换为自己的jar 包目录,然后为三个函数调用,第三个函数uplog4j_bigdata 为替换目录下的多个jar 包,具体根据自己jar 包目录替换路径