Tuesday, January 2, 2024

Git 增量打版抽取脚本

 

patch.sh

# 定义sed -i 参数(数组)
# Default case for Linux sed, just use "-i"
sedi=(-i)
case "$(uname)" in
 # For macOS, use two parameters
Darwin*) sedi=(-i "")
esac

function getTargetpathLog(){
 if [ -f targetpath.log ];then
 echo "存在targetpath,将删除该文件!";
 rm -rf targetpath.log
 fi;
 #取最新两条tag写入gitversion.log
 # git checkout origin/uat
 # git pull origin yat
 #git fetch --tags origin
 rm -rf git.log
 echo "请输入new分支名称(quit退出):"
 while true
 do
  read newbaseline
   newbaseline=$(eval echo $newbaseline)
   if [ $newbaseline = "quit" ];then
     exit 0;
   fi
   dev=`git branch | grep ".* ${newbaseline}$"`
  if [ -n "$dev" ];then
    break;
   else
     echo "当前工作区下此new分支不存在,请重新输入: "
   fi
 done
 echo "请输入old分支名称(quit退出): "
 while true
 do
  read oldbaseline
   if [ $oldbaseline = "quit" ];then
     exit 0;
   fi
   oldbaseline=$(eval echo $oldbaseline)
   feat=`git branch | grep ".* ${oldbaseline}$"`
  if [ -n "$feat" ];then
    break;
   else
     echo "当前工作区下此old分支不存在,请重新输入: "
   fi
 done
 git diff --name-status $oldbaseline $newbaseline > targetpath.log
}

function judgeSpeciel(){
 str="TaskWorkListServlet.java"
 res=$(echo ${full_path}| grep "${str}")
 if [ -n "$res" ]
 then
   #TODO
   tem=${full_path/\/src\/main\/java\/com\/hylandtec\/intelliplatform\/webapp/}
   target_path=${targetDir}/${tem%/*}
  copyFile
  return 1
 fi
}


function copyFile(){
if [ "${source_path}" == "./" ]
then
  return
fi
if [ -f "${source_path}" ]
then
  if [ ! -d "${target_path}" ]
  then
    mkdir -p ${target_path}
  fi
fi
echo "复制[${source_path}]到[${target_path}]"
cp ${source_path} ${target_path}
}

function copyCommon (){
 type1="webapp"
 type2="resources"
 type3=".java"
 type4="database"
 res1=$(echo ${full_path} | grep "${type1}")
 res2=$(echo ${full_path} | grep "${type2}")
 res3=$(echo ${full_path} | grep "${type3}")
 res4=$(echo ${full_path}| grep "${type4}")
 source_path= ${source}/${full_path}
 echo "源路径:${source_path}"
 if [ -n "$res1" ]
 then
   #TODO
   var= ${full_path/\/src\/main\/webapp/}
   target_path= ${targetDir}/${var%/*}
 elif [ -n "$res2" ]
 then
   #TODO
   if [ $project_name == "tfb-web"]
   then
     var=${full_path/\/src\/main\/resources\/WEB-INF\/classes}
     target_path= ${targetDir}/${var%/*}
    copyFile
    return
   fi
   var=${full_path/\/src\/main\/resources/}
   target_path=${targetDir}/${var%/*}
 elif [ -n "$res3" ]
 then
   #TODO
  judgeSpeciel
   flag=$?
   if [ $flag == 1 ]
   then
    return
   fi
   var=${full_path/\.java/\.class}
   var=${var/src\/main\/java/target\/classes}
   source_path=${source}/${var}
   if [ $project_name != "tfb-web" ]
   then
     var1=${var/\/target\/classes/}
     target_path=${targetDir}/${var1%/*}
    copyFile
     s=${var%/*}
     source_path="${source}/${s}""\$*.class"
    copyFile
    return
   fi
   var1=${var/target/WEB-INF}
   target_path=${targetDir}/${var1%/*}
  copyFile
   s=${var%.*}
   source_path="${source}/${s}""\$*.class"
 elif [ -n "$res4"]
 then
   #TODO
   echo "====${res4}======"
   source_path=${source}/${full_path}
   target_path=${targetDir}/${full_path%/*}
 fi
copyFile
}

function getBatchzip (){
 echo "INFO:dealing batch"
 ls;
 rm -rf tfbbatch;
 mkdir tfbbatch;

 cp -r ${filePath}/* tfbbatch/
 cd tfbbatch
 #delete web in patch.txt
 sed "${sedi[@]}" '/tfb-web,/d' patch.txt;
 #delete dir
 rm -rf database
 rm -rf tfb-web
 if [[ $(ls | wc -l) -eq 1 ]];then
   echo "INFO:There is not other files but patch.txt,exit";
   cd ..
   rm -rf tfbbatch
   result=-1;
  return 1
 fi
 #move the batch.zip
zip -r tfbbatch.zip *
 mv tfbbatch.zip ../.
 cd ..
 rm -rf tfbbatch
 echo "INFO;tfbbatch.zip success!"
 result=0;
}


function getWebZip(){
  echo "INFO:dealing web"
  ls;
  rm -rf tfbweb;
  mkdir tfbweb;
  cp -r ${filePath}/* tfbweb/

  cd tfbweb
  #delete batch in patch.txt
  #delete all other files
  sed "${sedi[@]}" '/hytfb-batch,/d' patch.txt;
  rm -rf database
  rm -rf hytfb-batch
  if [[ $(ls | wc -l) -eq 1 ]];then
     echo "ERROR:There is not files but patch.txt,exit"
     cd ..
     rm -rf tfbweb
     result=-1
    return 1;
  fi
  #仅生成打包一个web
  zip -r tfbweb.zip *
  mv tfbweb.zip ../.
  cd ..
  rm -rf tfbweb
  echo "INFO;tfb-web.zip auccess!"
  result=0;
}


main(){
getTargetpathLog
 source=.
 target=./tfbsit
 date=` date +%Y%m%d`
 filePath="tfb_uat"
 targetDir=${target}/${date}/${filePath}
 if [ -d "${targetDir}" ]
 then
   rm -r ${targetDir}
 fi

 #读取targetpach.log
 while read line
 do
   info=($line)
   full_path=${info[1]}
   #echo $full_path
   project_name=${full_path%%/*}
   echo "======${project_name}========="
  copyCommon
 done < targetpath.log

 cd ${target}/${date}
pwd
 #生成patch.txt文件
 find ${filePath} | xargs ls -ld | grep -v ^d |grep -v '.*patch,txt' | grep -Ev '*\.sh'| grep -Ev '*\.sql'|grep -Ev '*\.tar'> ${filePath}/patch.txt
 sed "${sedi[@]}" 's/.*'${filePath}'\//r,/g' ${filePath}/patch.txt
 sed "${sedi[@]}" 's/\//,/' ${filePath}/patch.txt
 #生成zip文件
 #run batch
 if [[ $(ls ${filePath} | grep -v tfb-web | wc -l) -gt 0 ]];then
  getBatchzip;
 fi
 #run web
 if [[ $(ls ${filePath}| grep -v hytfb-batch | wc -l) -gt 0 ]];then
  getWebZip;
 fi
}

main

使用

./patch.sh

new 分支一般使用 UAT, 分支, old 分支一般是 feat 分支合并到 UAT 分支后打了一个 tag, 这个 tag 就是 old 分支。结合 Git 实战指南博客使用更佳哦。

Linux 下常用软件的安装

 

查看进程、端口、防火墙

# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload

step1 查找ES进程号

ps -ef | grep elastic
ps -ef | grep tomcat

查看端口是否占用

netstat -anp|grep 65511
lsof -i:65511

杀死进程

kill -9 3250

清理缓存

sync
echo 3 >/proc/sys/vm/drop_caches

JDK

vi /etc/profile

export JAVA_HOME=/usr/java/jdk1.8.0_131
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

激活环境变量

source /etc/profile

Redis安装步骤

1、 上传服务器:

将jemalloc-3.6.0-1.el6.art.x86_64.rpm和redis-3.2.10-2.el6.x86_64.rpm包上传到服务器上;

2、 先安装jemalloc:

输入命令rpm –ivh jemalloc-3.6.0-1.el6.art.x86_64.rpm即可;

3、 然后再安装redis:

输入命令rpm -ivh redis-3.2.10-2.el6.x86_64.rpm便可安装完成。

4、 修改Redis的配置文件:

使用命令vi /etc/redis.conf 来编辑redis的配置文件,该文件是安装Redis后便存在的。将bind行修改为:bind 0.0.0.0,然后将原来的bind 127.0.0.1使用#注释掉。

5、 设置密码:

requirepass xxxx! ,另外Redis默认的端口号为6379,可根据需要选择是否修改。

6、 启动redis服务:

使用redis-server命令可启动Redis,这是linux上的服务端,启动后的页面如下。

7、 将Redis设置为开机自启动:

使用命令chkconfig redis on,启动完成后可使用命令chkconfig --list redis查看。

启动后再看看状态:systemctl start redis

重启 redis

systemctl restart redis.service

MongoDB安装步骤

1、 上传服务器:

将MongoDB安装rpm包上传到服务器上;

2、 安装MongoDB:

rpm –ivh mongodb-org-mongos-4.2.6-1.el7.x86_64.rpm

rpm –ivh mongodb-org-server-4.2.6-1.el7.x86_64.rpm

rpm –ivh mongodb-org-shell-4.2.6-1.el7.x86_64.rpm

rpm –ivh mongodb-org-tools-4.2.6-1.el7.x86_64.rpm

3、 修改配置文件

vim /etc/mongod.conf

net:bindIp: 127.0.0.1 改为 0.0.0.0

4、 启动并开机自启

systemctl start mongod       #启动

systemctl enable mongod #配置开机自启

systemctl restart mongod #重启

5、 连接数据库

mongo --host 127.0.0.1:27017

6、 查看所有数据库

show dbs

7、 进入admin数据库

use admin

8、 设置超级管理员

//db.addUser(“weitu2019”,”weitu2019!”)

db.createUser(

{

user: "xxxx",

pwd: "xxxx!",

roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]

}

)

db.createUser(

{

user: "xxxx",

pwd: "xxxx!",

roles: [ { role: "readWrite", db: "local" }]

}

)

9、 验证用户名密码

db.auth("weitu2020", "xxxx!")

Nginx 安装步骤

1、 上传服务器:

将Nginx安装rpm包上传到服务器上;

2、 安装Nginx:

进入到 Nginx文件目录下,运行 install.sh文件;

3、 配置Nginx

配置文件的默认路径在 /etc/nginx/ 下:vim /etc/nginx/nginx.conf

也可在 /etc/nginx/conf.d/下新增.conf文件

请求返回 413 Request Entity Too Large

Nginx 限制上传文件只能有1M, 在 http{} 中加入 client_max_body_size 10m;

4、 重启Nginx

修改完后重启Nginx: /usr/sbin/nginx -s reload

Mysql8.0安装步骤

1、 上传服务器:

将Mysql安装rpm包上传到服务器上;

2、 安装Mysql:

进入到Mysql文件目录下,运行install.sh文件;

rpm -ivh mysql-community-common-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-compat-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-embedded-compat-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-8.0.20-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm

如果报错:file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.27-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64

则执行 yum remove mysql-libs

3、 修改配置文件:

修改/etc/my.cnf文件,在文件的最后面加入下面信息:

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

关闭服务,修改mysql配置文件:

systemctl stop mysqld.service

修改配置文件

vi /etc/my.cnf

mysqld下面添加skip-grant-tables 保存退出启动服务(如图)。

重启服务:

systemctl start mysqld.service

修改root密码:

mysql -u root  # 刚才添加了skip,这种情况下不需要密码直接回车

use mysql # 指定库

update user set authentication_string=password('sfj#12348') where user='root' and host='localhost';

flush privileges; # 清空权限表缓存

exit;

vi /etc/my.cnf #把 skip-grant-tables # 把这句删除保存退出重启mysql服务,恢复密码登录。

重启服务

systemctl restart mysqld.service

查看密码等级:

show variables like 'validate_password%';

set global validate_password_policy=0;

flush privileges;



ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'sfj#12348'

创建数据库:

登入:

mysql -h localhost -u root –p

输入密码:

weitu@123456

创建数据库

create database ermsDb;

创建用户

create user 'haiguan'@'%' identified by 'WT@weitu2020';

ALTER USER 'haiguan'@'%' IDENTIFIED WITH mysql_native_password BY 'WT@weitu2020';

给用户赋值权限

grant all privileges on *.* to 'haiguan'@'%' identified by 'WT@weitu2020' with grant option;

GRANT ALL ON *.* TO 'root'@'%';
FLUSH PRIVILEGES ;

另,给普通用户远程连接的权限: 1、授权 myuser 用户对指定库的所有表,所有权限并设置远程访问

GRANT ALL ON *.* TO haiguan@'%';

FLUSH PRIVILEGES ;



update user set authentication_string=password('weitu@123456') where user='root' and host='localhost';



update user set authentication_string=password("weitu@123456") where user='root' and host='localhost';



ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'weitu@123456';



SET PASSWORD FOR 'root'@'localhost'= "weitu@123456"

出现大小写敏感时要修改,修改配置文件vi /etc/my.cnf

vi /etc/my.cnf

最开始增加:

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

# 在[mysqld]里面增加:

# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB

lower_case_table_names=1

max_allowed_packet=16M

MySQL7.0 安装步骤

1、 上传服务器:

将Mysql安装rpm包上传到服务器上;

2、 安装Mysql:

进入到Mysql文件目录下,运行install.sh文件;

rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-embedded-compat-5.7.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm

如果报错:file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.27-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64

则执行 yum remove mysql-libs

3、 修改配置文件:

修改/etc/my.cnf文件,在文件的最后面加入下面信息:

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

关闭服务,修改mysql配置文件:

systemctl stop mysqld.service

修改配置文件

vi /etc/my.cnf

mysqld下面添加skip-grant-tables 保存退出启动服务(如图)。

重启服务:

systemctl start mysqld.service

修改root密码:

mysql -u root  # 刚才添加了skip,这种情况下不需要密码直接回车

use mysql # 指定库

update user set authentication_string=password('sfj#12348') where user='root' and host='localhost';

flush privileges; # 清空权限表缓存

exit;

vi /etc/my.cnf #把 skip-grant-tables # 把这句删除保存退出重启mysql服务,恢复密码登录。

重启服务

systemctl restart mysqld.service

查看密码等级:

show variables like 'validate_password%';

set global validate_password_policy=0;

flush privileges;

alter user 'root'@'localhost' identified by 'sfj#12348';

flush privileges;

创建用户

set global validate_password_policy=0;

flush privileges;

create user songda@'%' identified by 'sfj#12348';

给用户赋值权限

grant all privileges on *.* to 'songda'@'%' identified by 'sfj#12348' with grant option;

数据库报错:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 问题

mysqld下面添加skip-grant-tables 保存退出启动服务(如图)。

重启服务:

systemctl start mysqld.service

在mysql5.7以下的版本如下:

mysql> UPDATE user SET Password=PASSWORD('sfj#12348') where USER='root' and host='127.0.0.1' or host='localhost';//把空的用户密码都修改成非空的密码就行了。

在mysql5.7版本如下:

update mysql.user set authentication_string=password('sfj#12348') where user='root' and host='127.0.0.1' or host='localhost';


mysql> FLUSH PRIVILEGES;

ERROR 2006 (HY000): MySQL server has gone away 问题

vi /etc/my.cnf

max_allowed_packet=1073741824

Spring 知识

编程性事务 注意.使用Spring自带的事,在抛RuntimeException时会自动回演,代码抛其他异常不会回滚。 国结批处理中若需要支持回滚,可使用以下方法 import org . springframework . jdbc . datasource . DataSo...