我的shell记录
##!/bin/bash
# addJar.sh
#在已有的jar包中添加新的依赖jar包
path=BOOT-INF/lib
jarName=$1
if [ "$1" = "" ];
then
echo -e "未输入替换包名,程序退出!!!"
exit 1
fi
cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
file=${files%\.*}
echo "创建文件夹:${file}"
mkdir -m 750 ${file}
echo "移动文件${files} 至 ${file}中"
mv ${files} $file
echo "解压jar包"
cd $file
jar xf $files
echo "删除${files}包"
rm $files
ls
echo "Copy新包至目标路径下"
echo "此刻路径: $(pwd)"
cp ../../$jarName $path
jar cf0M $files *
echo "将新包移动至 $(pwd) ../../"
mv $files ../../
echo "此刻路径: $(pwd)"
cd ../
echo "此刻路径: $(pwd)"
echo "完成${files}的添加!!!"
echo ""
echo ""
done
##!/bin/bash
#replaceJar.sh
#替换jar包
path=BOOT-INF/lib
jarName=$1
if [ "$1" = "" ];
then
echo -e "未输入替换包名,程序退出!!!"
exit 1
fi
if [ ! -d "bak" ];then
mkdir -m 750 bak
fi
cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
file=${files%\.*}
echo "创建文件夹:${file}"
mkdir -m 750 ${file}
echo "移动文件${files} 至 ${file}中"
mv ${files} $file
echo "解压jar包"
cd $file
jar xf $files
echo "删除${files}包"
rm $files
echo "删除目标包 ${jarName}"
rm $path/$jarName
ls
echo "Copy新包至目标路径下"
echo "此刻路径: $(pwd)"
cp ../../$jarName $path
jar cf0M $files *
echo "将新包移动至 $(pwd) ../../"
mv $files ../../
echo "此刻路径: $(pwd)"
cd ../
echo "此刻路径: $(pwd)"
echo "完成${files}的替换!!!"
echo ""
echo ""
done
##!/bin/bash
# addOrReplaceFileToConfig.sh
#在已有的jar包中添加替换新的文件
path=BOOT-INF/lib
fileName=$1
if [ "$1" = "" ];
then
echo -e "未输入添加的文件名,程序退出!!!"
exit 1
fi
if [ ! -d "bak" ];then
mkdir -m 750 bak
fi
cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
file=${files%\.*}
echo "创建文件夹:${file}"
mkdir -m 750 ${file}
echo "移动文件${files} 至 ${file}中"
mv ${files} $file
echo "解压jar包"
cd $file
jar xf $files
echo "删除原 ${files} 包"
rm $files
echo "进入 $path 中"
cd $path
mkdir -m 750 bak
cd bak
mv ../*-config-1.0.0-SNAPSHOT.jar ./
jarName=$(ls *.jar)
jar xf *-config-1.0.0-SNAPSHOT.jar
echo "复制文件至 bak中 "
echo "此刻路径: $(pwd)"
rm my-logback-spring.xml
cp ../../../../../$fileName ./
rm *-config-1.0.0-SNAPSHOT.jar
jar cf0M $jarName *
mv $jarName ../
cd ../
rm -rf bak
cd ../../
echo "此刻路径: $(pwd)"
jar cf0M $files *
echo "将新包移动至 $(pwd) ../../"
mv $files ../../
echo "此刻路径: $(pwd)"
cd ../
echo "此刻路径: $(pwd)"
echo "完成${files}中 $fileName 文件的添加!!!"
echo ""
done
echo ""
echo "删除bak文件夹"
cd ../
rm -rf bak
#!/bin/bash
# addWordsToyml.sh
#在已有的jar包中 对yml文件进行添加 词的动作
path=BOOT-INF/lib
if [ ! -d "bak" ];then
mkdir -m 750 bak
fi
cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
file=${files%\.*}
echo "创建文件夹:${file}"
mkdir -m 750 ${file}
echo "移动文件${files} 至 ${file}中"
mv ${files} $file
echo "解压jar包"
cd $file
jar xf $files
echo "删除原 ${files} 包"
rm $files
echo "进入 $path 中"
cd $path
mkdir -m 750 bak
cd bak
mv ../*-config-1.0.0-SNAPSHOT.jar ./
jarName=$(ls *.jar)
jar xf *-config-1.0.0-SNAPSHOT.jar
sed -i '/logging/a\ config: classpath:my-logback-spring.xml' application-pre.yml
sed -i 's/
//g' application-pre.yml
rm *-config-1.0.0-SNAPSHOT.jar
jar cf0M $jarName *
mv $jarName ../
cd ../
rm -rf bak
cd ../../
echo "此刻路径: $(pwd)"
jar cf0M $files *
echo "将新包移动至 $(pwd) ../../"
mv $files ../../
echo "此刻路径: $(pwd)"
cd ../
echo "此刻路径: $(pwd)"
echo "完成${files}中 yml 文件关键词的添加!!!"
echo ""
echo ""
done
#!/bin/bash
#mdir.sh
#批量创建文件夹
echo "开始时间:"`date "+%Y-%m-%d %H:%M:%S"`
/usr/bin/expect -c "
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.61 mkdir -p /app/tomcat/scms/easyloan/afterloan
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.62 mkdir -p /app/tomcat/scms/easyloan/afterloan
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.101 mkdir -p /app/tomcat/scms/easyloan/archives
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.102 mkdir -p /app/tomcat/scms/easyloan/archives
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.141 mkdir -p /app/tomcat/scms/easyloan/badassets
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.142 mkdir -p /app/tomcat/scms/easyloan/badassets
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.151 mkdir -p /app/tomcat/scms/easyloan/classify
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.152 mkdir -p /app/tomcat/scms/easyloan/classify
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.131 mkdir -p /app/tomcat/scms/easyloan/credit
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.132 mkdir -p /app/tomcat/scms/easyloan/credit
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.71 mkdir -p /app/tomcat/scms/easyloan/customer
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.72 mkdir -p /app/tomcat/scms/easyloan/customer
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.121 mkdir -p /app/tomcat/scms/easyloan/loan
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
spawn ssh -f -o StrictHostKeyChecking=no tomcat@10.11.149.122 mkdir -p /app/tomcat/scms/easyloan/loan
expect {
\"(yes/no)?\" { send \"yes\r\";exp_continue }
\"*ssword:\" { send \"Edxd@123\r\";exp_continue }
}
"
echo "结束时间:"`date "+%Y-%m-%d %H:%M:%S"`
#!/bin/bash
#replaceWordsYml.sh
# 对yml中的 关键词进行替换
path=BOOT-INF/lib
key1=$1
key2=$2
if [ "$1" = "" ];
then
echo -e "请输入目标关键词!!!"
exit 1
fi
if [ "$2" = "" ];
then
echo -e "请输入替换词!!!"
exit 1
fi
if [ ! -d "bak" ];then
mkdir -m 750 bak
fi
cd bak
rm -rf *
cp ../*springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
file=${files%\.*}
echo "创建文件夹:${file}"
mkdir -m 750 ${file}
echo "移动文件${files} 至 ${file}中"
mv ${files} $file
echo "解压jar包"
cd $file
jar xf $files
echo "删除原 ${files} 包"
rm $files
echo "进入 $path 中"
cd $path
mkdir -m 750 bak
cd bak
mv ../*-config-1.0.0-SNAPSHOT.jar ./
jarName=$(ls *.jar)
jar xf *-config-1.0.0-SNAPSHOT.jar
sed -i "s/$key1/$key2/g" application-pre.yml
rm *-config-1.0.0-SNAPSHOT.jar
jar cf0M $jarName *
mv $jarName ../
cd ../
rm -rf bak
cd ../../
echo "此刻路径: $(pwd)"
jar cf0M $files *
echo "将新包移动至 $(pwd) ../../"
mv $files ../../
echo "此刻路径: $(pwd)"
cd ../
echo "此刻路径: $(pwd)"
echo "完成${files}中 yml 文件关键词的替换!!!"
echo ""
echo ""
done
#!/bin/bash
#startall.sh
#调用spring-boot.sh
# 当 $1 输入为 dr 时 启动备库
appCount=`(ls *-springboot-1.0.0-SNAPSHOT.jar | wc -l)`
echo "检测到【${appCount}】个系统服务"
if [ $appCount -gt 0 ];then
for appTName in $(ls *-springboot-1.0.0-SNAPSHOT.jar)
do
#echo "appTName is ${appTName} "
appName="${appTName%%-*}"
echo "启动 $appName 服务"
if [ ! -d "logs" ];then
mkdir -m 755 logs
fi
sh spring-boot.sh start $appName $1
sh spring-boot.sh status $appName $1
done
else
echo "没有检测到可执行的jar包,程序停止。。。"
fi
#!/bin/bash
#spring-boot.sh
#jar包启动脚本2
SpringBoot=$2
current=`date "+%Y-%m-%d %H:%M:%S"`
basepath=/app/tomcat/scms
#本机 IP
IP=$(hostname -I)
#本机 Hostname
service=$2
#Redis集群节点
nodes="10.11.149.30:6001,10.11.149.30:6002,10.11.149.30:6003,10.11.149.31:6001,10.11.149.31:6002,10.11.149.31:6003,10.11.149.32:6001,10.11.149.32:6002,10.11.149.32:6003,10.11.149.33:6001,10.11.149.33:6002,10.11.149.33:6003,10.11.149.34:6001,10.11.149.34:6002,10.11.149.34:6003"
#数据库源
DB="jdbc:oracle:thin:@10.12.149.45:1521/loandb"
#数据库连接池大小
DBmaxActive=300
#注册中心
defaultZone="http://10.11.149.21:8761/eureka,http://10.11.149.22:8761/eureka"
#日志路径
logPath="/app/tomcat/scms/logs"
#日志级别 默认 ERROR
logLevel="INFO"
#日志文件大小(需要加size单位:KB,MB...) 默认512000KB
logSize="5GB"
#批量服务中心
job_address="http://10.11.149.191:9090"
#zipkin服务中心
zipkin_address="http://10.11.149.182:9411"
#sessionTime 50小时
sessionTime=360000000
case "$2" in
"afterloan")
DBmaxActive=100;;
"accounting")
DBmaxActive=100;;
"archives")
DBmaxActive=100;;
"asset")
DBmaxActive=100;;
"badassets")
DBmaxActive=100;;
"billSystem")
DBmaxActive=100;;
"classify")
DBmaxActive=100;;
"credit")
DBmaxActive=100;;
"customer")
DBmaxActive=100;;
"dataApplication")
DBmaxActive=100;;
"loan")
DBmaxActive=100;;
"rating")
DBmaxActive=100;;
"riskwarn")
DBmaxActive=100;;
"system")
DBmaxActive=100;;
*)
esac
if [ "$1" = "" ];
then
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
exit 1
fi
if [ "$SpringBoot" = "" ];
then
echo -e "\033[0;31m 未输入应用名 \033[0m"
exit 1
fi
#在 灾备环境启动时 切换环境配置
if [ "$1" == "start" -o "$1" == "restart" ];then
if [ "$3" == "dr" ];then
DB="jdbc:oracle:thin:@10.225.149.45:1521/loandbdr"
#Redis节点
nodes="10.224.149.30:6001,10.224.149.30:6002,10.224.149.30:6003,10.224.149.31:6001,10.224.149.31:6002,10.224.149.31:6003,10.224.149.32:6001,10.224.149.32:6002,10.224.149.32:6003,10.224.149.33:6001,10.224.149.33:6002,10.224.149.33:6003,10.224.149.34:6001,10.224.149.34:6002,10.224.149.34:6003"
#注册中心
defaultZone="http://10.224.149.21:8761/eureka,http://10.224.149.22:8761/eureka"
#批量服务中心
job_address="http://10.224.149.191:9090"
#zipkin服务中心
zipkin_address="http://10.224.149.182:9411"
echo "........................DB 启动备库......................"
fi
fi
function start()
{
count=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "【$current】$SpringBoot is running..."
else
if [ ! -d "/app/tomcat/scms/logs" ];then
mkdir -m 755 /app/tomcat/scms/logs
fi
echo "【$current】Start $SpringBoot success..."
nohup java -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=1024m -Xms1024m -Xmx12G -Xmn2G -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -jar $basepath/easyloan/$SpringBoot-springboot-1.0.0-SNAPSHOT.jar --spring.profiles.active=pre --edbPath=/app/edb/ --server.tomcat.max-threads=2000 --server.tomcat.connections=2000 --eureka.client.service-url.defaultZone=$defaultZone --spring.redis.lettuce.pool.max-waitMillis=1200 --spring.redis.cluster.nodes=$nodes --spring.redis.cluster.timeout=2500 --spring.redis.cluster.maxAttempts=20 --spring.redis.cluster.max-redirects=3 --server.tomcat.connection-timeout=60000 --server.compression.enabled=true --server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain --server.compression.min-response-size=512 --spring.datasource.druid.master.maxActive=$DBmaxActive --spring.datasource.druid.slave.maxActive=$DBmaxActive --eureka.instance.prefer-ip-address=true --easy.job.admin.addresses=$job_address --easy.job.executor.ip=$IP --feign.httpclient.enabled=true --feign.httpclient.max-connections-per-route=1000 --feign.httpclient.max-connections=3000 --spring.datasource.druid.stat-view-servlet.reset-enable=true --spring.datasource.druid.filter.wall.enabled=true --spring.zipkin.base-url=$zipkin_address --spring.datasource.druid.master.url=$DB --jwt.expiration=$sessionTime --spring.datasource.druid.slave.url=$DB --application.name=$service --log.path=$logPath --log.level=$logLevel --log.size=$logSize > /dev/null 2>&1 &
fi
}
function stop()
{
echo "【$current】Stop $SpringBoot"
boot_id=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|awk '{print $2}'`
count=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo $boot_id
kill $boot_id
count=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|wc -l`
boot_id=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|awk '{print $2}'`
echo $boot_id
kill -9 $boot_id
fi
}
function restart()
{
stop
sleep 2
start
}
function status()
{
count=`ps -ef |grep java|grep $SpringBoot-springboot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "【$current】$SpringBoot is running..."
else
echo "【$current】$SpringBoot is not running..."
fi
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
echo -e "\033[0;31m Usage: \033[0m \033[0;34m sh $0 {start|stop|restart|status} {SpringBootJarName} \033[0m
\033[0;31m Example: \033[0m
\033[0;33m sh $0 start esmart-test.jar \033[0m"
esac
#!/bin/bash
#startall.sh
#停止脚本
# 当 $1 输入为 dr 时 启动备库
appCount=`(ls *-springboot-1.0.0-SNAPSHOT.jar | wc -l)`
echo "检测到【${appCount}】个系统服务"
if [ $appCount -gt 0 ];then
for appTName in $(ls *-springboot-1.0.0-SNAPSHOT.jar)
do
#echo "appTName is ${appTName} "
appName="${appTName%%-*}"
echo "启动 $appName 服务"
if [ ! -d "logs" ];then
mkdir -m 755 logs
fi
sh spring-boot.sh start $appName $1
sh spring-boot.sh status $appName $1
done
else
echo "没有检测到可执行的jar包,程序停止。。。"
fi
#startZipkin.sh
#启动Zipkin
nohup java -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=1024m -Xms1024m -Xmx12G -Xmn2G -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -jar zipkin.jar > zipkin.log 2>&1 &
#stopZipkin.sh
#停止Zipkin
boot_id=`ps -ef |grep java|grep zipkin|grep -v grep|awk '{print $2}'`
count=`ps -ef |grep java|grep zipkin|grep -v grep|wc -l`
if [ $count != 0 ];then
echo $boot_id
kill $boot_id
#count=`ps -ef |grep java|grep zipkin|grep -v grep|wc -l`
#boot_id=`ps -ef |grep java|grep zipkin|grep -v grep|awk '{print $2}'`
#echo $boot_id
#kill -9 $boot_id
echo "【Stop】 zipkin success!!"
fi
#!/bin/bash
# takeDirForJar.sh
#jar包中提取 文件(夹)
path=BOOT-INF/classes
if [ ! -d "rules" ];then
mkdir -m 750 rules
fi
for appTName in $(ls *-springboot-1.0.0-SNAPSHOT.jar)
do
if [ ! -d "bak" ];then
mkdir -m 750 bak
fi
#echo "appTName is ${appTName} "
appName="${appTName%%-*}"
echo "提取 ${appName} 中 rules kettle 文件 "
if [ ! -d "rules/${appName}" ];then
mkdir -m 750 rules/${appName}
fi
cd bak
rm -rf *
cp ../${appName}-springboot-1.0.0-SNAPSHOT.jar ./
for files in $(ls)
do
file=${files%\.*}
echo "创建文件夹:${file}"
mkdir -m 750 ${file}
echo "移动文件${files} 至 ${file}中"
mv ${files} $file
echo "解压jar包"
cd $file
jar xf $files
echo "删除原 ${files} 包"
rm $files
echo "进入 $path 中"
cd $path
echo "复制rules kettle 至 easyloan "
cp rules/* ../../../../rules/${appName}
if [ -d "kettle" ];then
cp -r kettle/ ../../../../
fi
cd ../../../../
echo "此刻路径: $(pwd)"
echo "完成${files}中 rules kettle 文件的提取!!!"
echo ""
echo ""
done
done
rm -rf bak
echo "此刻路径: $(pwd)"
#!/bin/sh
# start.sh
# 启动(每个)redis
./redis-server ./6001/redis.conf
./redis-server ./6002/redis.conf
./redis-server ./6003/redis.conf
#./redis-server ./6004/redis.conf
#./redis-server ./6005/redis.conf
#./redis-server ./6006/redis.conf
#./redis-cli --cluster create 10.11.149.30:6001 10.11.149.31:6001 10.11.149.32:6001 10.11.149.33:6001 10.11.149.34:6001 10.11.149.35:6001 10.11.149.36:6001 10.11.149.37:6001 10.11.149.38:6001 10.11.149.39:6001 --cluster-replicas 1
#!/bin/sh
# 停止redis
/app/redis/redis-5.0.5/src/redis-cli -c -p 6001 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6002 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6003 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6004 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6005 shutdown
/app/redis/redis-5.0.5/src/redis-cli -c -p 6006 shutdown
#启动redis集群 一主两从
# 创建集群时 要先启动每一个 redis
./redis-cli --cluster create 10.224.149.30:6001 10.224.149.30:6002 10.224.149.30:6003 10.224.149.31:6001 10.224.149.31:6002 10.224.149.31:6003 10.224.149.32:6001 10.224.149.32:6002 10.224.149.32:6003 10.224.149.33:6001 10.224.149.33:6002 10.224.149.33:6003 10.224.149.34:6001 10.224.149.34:6002 10.224.149.34:6003 --cluster-replicas 2