docker-compose编排nginx+tomcat+fastdfs+mysql
[docker compose 部署nginx-tomcat平台}(https://blog.51cto.com/1014810/2114707
)
Jenkins-job之间依赖关系配置
svn,git分支版本发布
Jenkins+svn设置分支和版本号部署
jenkins选择分支构建
svn://****/$branch@$revision
配置git
用ssh拉取git源码 先在gitlab上配置好生成的公钥,然后在jenkin站点的凭据-系统-添加域 配置域的凭据,配置好凭据用户 ,选择SSH Username with private key 然后设置与公钥对应的私钥 Private Key 然后保存即可
jenkins credentials & git ssh 认证
配置与jenkins在同一台服务器上tomcat
### 用于tomcat7自动部署的管理用户必须具有manager-script角色,manager-gui角色是不够的,不然会有错误出现:
The username you provided is not allowed to use the text-based Tomcat Manager (error 403)
在/etc/tomcat7/tomcat-users.xml文件中为管理用户添加manager-script角色即可。
username 和 password 则是登陆tomcat管理界面需要的账号密码。
### 如果还不行
/webapps/manager/META_INF/context.xml文件,将文件中对访问的来源受限设置注释
# deploy war to a container配置
WAR/EAR files : target/***.war
Context path : projectname (在tomcat的webapp下的目录)
Containers : Tomcat URL 请求路径带端口
原文地址:https://blog.csdn.net/jay_1989/article/details/52861620
参考:
GitLab配置ssh key
Linux配置SSH公钥认证与Jenkins远程登录进行自动发布
jenkins SSH登录 Git配置(通过eclipse生成SSH 密钥)
根据版本更新发布
安装gitlab-plugin ( gitlab hook plugin这个不行)
在 构建触发器中 先择Build when a change is pushed to GitLab. GitLab webhook URL: http://ip/jenkins/project/name
在gitlab该project界面点击side bar最下面的settings图标 * Integrations Settings 然后再点击侧边栏中的“web Hooks”,在“URL”一栏输入在第5步骤中的(3)中的URL,还要点开右下角的 高级:随后点击右下角的 Generate 按钮,生成 Secret token; 在 Secret Token 一栏中输入生成的 Secret token;然后测试成功就说明gitlab和jenkins关联成功
在高级里面的Allowed branches 选择Filter branches by name Include master 允许master分支上的变化触发构建
jenkins实现git提交后自动化构建
https://www.jianshu.com/p/eeb15a408d88
shell发布tomcat
#!/bin/bash
export BUILD_ID=dontkillme #随便写
export JAVA_HOME=/usr/java/jdk1.7.0_80 #tomcat需要的jdk
#
# __auther__: zhan
# __ time __: 2018年08月16日 22:00:00
# __ 作用 __: 用于jenkins build完成之后的最后操作shell脚本
# __ 使用 __: 定义jenkins
#
#---------------------------------- 文件路径配置 ----------------------------------
#tomcat服务器获取系统时间以 2018-08-16 显示
timedate=$(date +%Y-%m-%d)
#client服务器tomcat安装路径
TOMCAT_HOME=/web/tomcat-jih-8080
#tomcat服务器备份文件存放路径
BACKUP_HOME=$TOMCAT_HOME/bak
#tomcat服务器war包服务器更新包名称
WAR__NAME=yk
#tomcat服务器最新版本文件存放路径
PUBLISHVERSION_HOME=/web/appwar/yk
#client服务器以时间的方式备份发布前的项目文件目录名称
BACK_TIME=`date +%Y%m%d%H%M`
#tomcat服务器项目发布后的路径
PUBLISHED_PATH=$TOMCAT_HOME/webapps/$WAR__NAME
#war包远程jenkins服务器项目配置文件
PROJECT_CONFIG_FILE=/web/appwar/yk/classes
#war包远程jenkins服务器地址
WAR_SERVER_IP='192.168.2.20'
#war包远程jenkins服务器存放路径
WAR_SERVER_HOME='/web/appwar/yk'
#---------------------- 远程复制war包 [需要SSH免密码登陆设置]-------------------
#复制远程jenkins服务器war包到tomcat服务器上最新版本文件存放路径
scp -r $WAR_SERVER_IP:/$WAR_SERVER_HOME/$WAR__NAME.war $PUBLISHVERSION_HOME
#--------------------------------- tomcat服务器备份文件 -------------------------------------
echo go to $BACKUP_HOME
cd $BACKUP_HOME
echo backup time $BACK_TIME
/bin/mkdir $BACK_TIME
echo go to $BACK_TIME
cd $BACK_TIME
echo "backup path"
pwd
echo "start copy project files"
#复制项目文件
cp $PUBLISHED_PATH . -R
#------------------------------- tomcat服务器解压war包 ---------------------------------------
#进入要发布版本的文件夹
cd $PUBLISHVERSION_HOME
echo "go to $PUBLISHVERSION_HOME"
#解压前先删除旧解压后的文件
rm -rf $WAR__NAME
echo "rm successfull"
#解压项目war包
/bin/unzip $WAR__NAME.war -d $WAR__NAME/ &>/dev/null
echo "unzip successfull"
#复制远程服务器war包最新配置文件到本地服务器配置文件存放路径
scp -r $WAR_SERVER_IP:/$PROJECT_CONFIG_FILE/* $PUBLISHVERSION_HOME/$WAR__NAME/WEB-INF/classes
#最后删除war包,以便下次更新下载最新war包
rm -rf $WAR__NAME.war
echo "$WAR__NAME.war rm successfull"
-------------------------------------------- 说明 ----------------------------------------------------------------------------------
#下面的命令会将【PROJECT_CONFIG_FILE=/web/appwar/yj/classes】classes目录给拷贝到本地文件的properties目录的
#scp -r $WAR_SERVER_IP:/$PROJECT_CONFIG_FILE/ $PUBLISHVERSION_HOME/$WAR__NAME/WEB-INF/classes/properties
#将远程【PROJECT_CONFIG_FILE=/web/appwar/yj/classes】classes目录下的所有文件(不包含classes目录)拷贝本地properties目录下
#scp -r $WAR_SERVER_IP:/$PROJECT_CONFIG_FILE/* $PUBLISHVERSION_HOME/$WAR__NAME/WEB-INF/classes/properties
#将远程classes目录下的文件拷贝本地classes目录下
#scp -r $WAR_SERVER_IP:/$PROJECT_CONFIG_FILE/* $PUBLISHVERSION_HOME/$WAR__NAME/WEB-INF/classes
#或者用scp -r $WAR_SERVER_IP:/$PROJECT_CONFIG_FILE/ $PUBLISHVERSION_HOME/$WAR__NAME/WEB-INF到这里即可,就直接将classes目录放到WEB-INF下面了
-------------------------------------------- 说明 ----------------------------------------------------------------------------------
#------------------------------- tomcat服务器部署文件 ---------------------------------------
#关闭tomcat
#/sbin/service tomcat stop
#$TOMCAT_HOME/bin/shutdown.sh
cd $TOMCAT_HOME/bin
#查看进程
ps -ef|grep $TOMCAT_HOME|grep -v grep|grep -v kill
#上一个命令退出后就执行kill进程号,否则是执行下一个语句说明
#【if [ $? -eq 0 ]:代表上一个命令执行后的退出状态:0为成功,非0为失败】
if [ $? -eq 0 ];then
kill -9 `ps -ef|grep $TOMCAT_HOME|grep -v grep|grep -v kill|awk '{print $2}'`
sleep 3
echo "停止tomcat服务成功"
else
echo $TOMCAT_HOME ' 该目录进程已KILL或项目未启动'
fi
#删除项目文件
rm -rf $PUBLISHED_PATH/*
#删除临时文件、log日志
rm -rf $TOMCAT_HOME/temp/*
rm -rf $TOMCAT_HOME/conf/Catalina/*
rm -rf $TOMCAT_HOME/work/*
#拷贝最新版本更新文件到项目发布路径下
cp $PUBLISHVERSION_HOME/$WAR__NAME/* $PUBLISHED_PATH/ -R
#复制配置文件
# cp $PUBLISHVERSION_HOME/classes/* $PUBLISHED_PATH/WEB-INF/classes -R
#启动tomcat,使用service命令时,使用普通用户需要输入密码,所以直接暂不采用service的方式启动和关闭tomcat
#/sbin/service tomcat start
$TOMCAT_HOME/bin/startup.sh
#tail -f $TOMCAT_HOME/logs/catalina.$timedate.out
#------------------------------- tnew ---------------------------------------
#!/bin/bash
echo "==================start deploy project========================="
ps -aux | grep /usr/local/tomcat/ | grep -v grep > tomcat_info.txt
sed 's/ / /g' tomcat_info.txt > tomcat_info1.txt
sed 's/ / /g' tomcat_info1.txt > tomcat_info.txt
sed 's/ / /g' tomcat_info.txt > tomcat_info1.txt
cat tomcat_info1.txt | cut -d' ' -f 2 > tomcat_info.txt
for line in `cat tomcat_info.txt`
do
kill -9 $line
done
cd /usr/local/tomcat/webapps
rm -rf youxuan_api*
mv /usr/local/jenkinsTempFolder/youxuan_api /usr/local/tomcat/webapps
/etc/init.d/tomcat start
sync
echo 3 > /proc/sys/vm/drop_caches
echo "==================deploy project success========================="
https://blog.51cto.com/meiling/2333265
本地 tomcat部署项目脚本
#/bin/bash
export BUILD_ID=dontkillme
echo "stop tomcat..."
/usr/local/tomcat/bin/catalina.sh stop
pidlist=`ps -ef | grep tomcat_name | grep -v "grep" | grep -v "tail" |awk '{print $2}' `
kill -9 $pidlist
warDir = /war/projectname
warName = `ls -t $warDir | head -1`
appDir = "/usr/local/tomcat/webapps"
if rm -rf $appDir/*
then
mv $warDir/$warName $appDir/ROOT.war && echo "build success!"
sleep 10s
echo "start tomcat..."
/usr/local/tomcat/bin/catalina.sh start
fi
---------
rm -rf /usr/local/tomcat8/webapps/hua.war
\cp -f target/***.war /usr/local/tomcat8/webapps/hua.war
unzip -oqhua.war -d hua
rm -rf /usr/local/tomcat-admin/mywebapps/app/*
\cp -rf /home/zyy/wars/bulls-admin/target/$adminwar /usr/local/tomcat-admin/mywebapps/app.war
unzip -oq /usr/local/tomcat-admin/mywebapps/app.war -d /usr/local/tomcat-admin/mywebapps/app
----------------------------
#/bin/bash
export BUILD_ID=dontkillme
echo "stop tomcat..."
/usr/local/tomcat8/bin/catalina.sh stop
pidlist=`ps -ef | grep tomcat8 | grep -v "grep" | grep -v "tail" |awk '{print $2}' `
kill -9 $pidlist
if rm -rf /usr/local/tomcat/webapps/*****.war
then
\cp -f target/***.war /usr/local/tomcat8/webapps/*****.war && echo "build success!"
sleep 1s
echo "start tomcat..."
/usr/local/tomcat8/bin/catalina.sh start
fi
https://blog.csdn.net/weixin_39483907/article/details/80840948
https://blog.csdn.net/cx118118/article/details/82461966
https://blog.csdn.net/u013887008/article/details/83003665
shell远程部署tomcat
#安装 Publish over SSH插件
1.先在系统设置里设置ssh 可以创建一个用户,用用户和密码登录也可以用证书登录,证书在jenkins服务器上生成,然后将公钥发给应用服务器上,之后在jenkins上配置私钥后就可以访问应用服务器了。
2.设置send build artifacts over ssh 插件
Source files target/*.war or **/*.war
Remove prefix target war包前面的目录
Remote directory /opt/war/ (远程服务器的临时存放路径,配置好后会自动上传到这里,也可以直接放到tomcat目录下)
Exec command
export JAVA_HOME=/usr/local/jdk
cd /opt/apache-tomcat-7.0.63/bin/
./deploy.sh
deploy.sh内容
#desc:在jenkins构建完成后,ROOT.war已经是最新的
#重启tomcat
bash /opt/apache-tomcat-7.0.63/bin/catalina.sh stop
#确保进程正常结束
sleep 2 #具体时间就看你得webapp在调用shutdown.sh后多久后处于僵死状态
ps -ef | grep ‘tomcat’ | grep -v grep| awk ‘{print $2}’ | xargs kill -9
#删除webapps下的weixin工程
rm -rf /opt/apache-tomcat-7.0.63/webapps/ROOT
#备份
#mv /opt/apache-tomcat-7.0.63/webapps/ROOT.war /opt/apache-tomcat-7.0.63/bak/ROOT.war.date +%Y%m%d%H%M%S.bak
#重启并打印日志
nohup bash /opt/apache-tomcat-7.0.63/bin/catalina.sh start & tailf /opt/apache-tomcat-7.0.63/logs/catalina.out
#!/bin/sh
warName=`ls -t /home/wars/ | head -1`x
echo $warName
\mv -f /home/wars/$warName /usr/local/tomcat8/webapps/xxxx.war
chmod -777 /usr/local/tomcat8/webapps/xxxx.war
特别注意的地方:应用服务器上的tomcat应用目录对上传war包的用户要有所有权,最好是同一用户,不然上传完war包后,因为没有权限导致解压不了。或者也可以修改文件的权限即可
https://blog.csdn.net/u011277123/article/details/77865741
https://www.cnblogs.com/cheng95/p/6542036.html
https://blog.csdn.net/weixin_39483907/article/details/80840948
https://www.jianshu.com/p/b3717d4679b6
https://www.cnblogs.com/YatHo/p/6739814.html
https://www.jianshu.com/p/3c6473755773
https://www.cnblogs.com/linjiqin/p/7776691.html
https://blog.csdn.net/tototuzuoquan/article/details/78568655
https://www.cnblogs.com/Dev0ps/p/9045762.html
http://www.mamicode.com/info-detail-1264849.html
tomcat部署到docker
#操作/项目路径(Dockerfile存放的路劲)
BASE_PATH=/data/paywallet/accounting
#端口(与Dockerfile中的EXPOSE相同)
PORT=8003
#docker 容器中jar目录(与Dockerfile中的CMD的jar目录相同)
DOCKER_PATH=/app
#docker 镜像/容器名字或者jar名字 这里都命名为这个(建议与Dockerfile中的MAINTAINER相同)
SERVER_NAME=paywallet-accounting
LOG_PATH=/data/canteen/app/logs
#容器id
CID=$(docker ps -a | grep "$SERVER_NAME" | awk '{print $1}')
#镜像id
IID=$(docker images | grep "$SERVER_NAME" | awk '{print $3}')
DATE=`date +%Y%m%d%H%M`
# 构建docker镜像
function build(){
if [ -n "$IID" ]; then
echo "存在$SERVER_NAME镜像,IID=$IID"
else
echo "不存在$SERVER_NAME镜像,开始构建镜像"
cd $BASE_PATH
docker build -t $SERVER_NAME .
fi
}
# 运行docker容器
function run(){
build
if [ -n "$CID" ]; then
echo "存在$SERVER_NAME容器,CID=$CID,重启docker容器 ..."
docker restart $SERVER_NAME
echo "$SERVER_NAME容器重启完成"
else
echo "不存在$SERVER_NAME容器,docker run创建容器..."
docker run --name $SERVER_NAME -v $BASE_PATH:$DOCKER_PATH -v $LOG_PATH:/logs -d -p $PORT:$PORT $SERVER_NAME
echo "$SERVER_NAME容器创建完成"
fi
}
#入口
run
---------
vim docker.sh
#操作/项目路径(Dockerfile存放的路劲)
BASE_PATH=/usr/ms_backend
# 源jar路径 即jenkins构建后存放的路径(
)
SOURCE_PATH=/var/lib/jenkins/workspace
#docker 镜像/容器名字或者jar名字 这里都命名为这个
SERVER_NAME=ms_backend
#容器id
CID=$(docker ps | grep "$SERVER_NAME" | awk '{print $1}')
#镜像id
IID=$(docker images | grep "$SERVER_NAME" | awk '{print $3}')
echo "最新构建代码 $SOURCE_PATH/$SERVER_NAME/target/ms_backend.jar 迁移至 $BASE_PATH ...."
#把项目从jenkins构建后的目录移动到我们的项目目录下同时重命名下
mv $SOURCE_PATH/$SERVER_NAME/target/ms_backend-0.0.1-SNAPSHOT.jar $BASE_PATH/ms_backend.jar
#修改文件的权限
chmod 777 /usr/ms_backend/ms_backend.jar
echo "迁移完成"
# 构建docker镜像
if [ -n "$IID" ]; then
echo "存在$SERVER_NAME镜像,IID=$IID"
else
echo "不存在$SERVER_NAME镜像,开始构建镜像"
cd $BASE_PATH
docker build -t $SERVER_NAME .
fi
# 运行docker容器
docker rm $SERVER_NAME //删除原来的容器
# --name docker-test 容器的名字为docker-test
# -d 容器后台运行
# -p 3636:3636 指定容器映射的端口和主机对应的端口都为3636
# -v /usr/ms_backend/:/usr/ms_backend/ 将主机的/usr/ms_backend/目录挂载到容器的/usr/ms_backend/ 目录中(不可少每次本地更新jar包重启容器即可,不用重新构建镜像
docker run --name $SERVER_NAME -v $BASE_PATH:$BASE_PATH -d -p 8040:8040 $SERVER_NAME
echo "$SERVER_NAME容器创建完成"
----
# Jenkins机器:编译完成后,build生成一个新版本的镜像,push到远程docker仓库
# Variables
JENKINS_WAR_HOME='/home/jenkins/.jenkins/workspace/godseyeBranchForNov/godseye-container/target'
DOCKERFILE_HOME='/home/jenkins/docker-file/godseye_war'
HARBOR_IP='172.16.206.32'
REPOSITORIES='godseye_war/godseye'
HARBOR_USER='jkzhao'
HARBOR_USER_PASSWD='Wisedu123'
HARBOR_USER_EMAIL='[email protected]'
# Copy the newest war to docker-file directory.
\cp -f ${JENKINS_WAR_HOME}/godseye-container-wisedu.war ${DOCKERFILE_HOME}/godseye.war
# Delete image early version.
sudo docker login -u ${HARBOR_USER} -p ${HARBOR_USER_PASSWD} -e ${HARBOR_USER_EMAIL} ${HARBOR_IP}
IMAGE_ID=`sudo docker images | grep ${REPOSITORIES} | awk '{print $3}'`
if [ -n "${IMAGE_ID}" ];then
sudo docker rmi ${IMAGE_ID}
fi
# Build image.
cd ${DOCKERFILE_HOME}
TAG=`date +%Y%m%d-%H%M%S`
sudo docker build -t ${HARBOR_IP}/${REPOSITORIES}:${TAG} . &>/dev/null
# Push to the harbor registry.
sudo docker push ${HARBOR_IP}/${REPOSITORIES}:${TAG} &>/dev/null
-----
#操作/项目路径(Dockerfile存放的路劲)
BASE_PATH=/data2/dockerFile
# 源jar路径
SOURCE_PATH=/app/soft/docker-config/jenkins/workspace/lfeel
#docker 镜像/容器名字或者jar名字 这里都命名为这个
SERVER_NAME=lfeel-admin
#容器id
CID=$(docker ps | grep "$SERVER_NAME" | awk '{print $1}')
#镜像id
IID=$(docker images | grep "$SERVER_NAME" | awk '{print $3}')
DATE=`date +%Y%m%d%H%M`
# 最新构建代码 移动到项目环境
function transfer(){
echo "最新构建代码 $SOURCE_PATH/$SERVER_NAME/target/$SERVER_NAME.jar 迁移至 $BASE_PATH/$SERVER_NAME ...."
cp $SOURCE_PATH/$SERVER_NAME/target/$SERVER_NAME.jar $BASE_PATH/$SERVER_NAME
cp $SOURCE_PATH/$SERVER_NAME/docker/Dockerfile $BASE_PATH/$SERVER_NAME
echo "迁移完成"
}
# 备份
function backup(){
if [ -f "$BASE_PATH/$SERVER_NAME/$SERVER_NAME.jar" ]; then
echo "$SERVER_NAME.jar 备份..."
cp $BASE_PATH/$SERVER_NAME/$SERVER_NAME.jar $BASE_PATH/$SERVER_NAME/backup/$SERVER_NAME-$DATE.jar
echo "备份 $SERVER_NAME.jar 完成"
else
echo "$BASE_PATH/$SERVER_NAME/$SERVER_NAME.jar不存在,跳过备份"
fi
}
# 构建docker镜像
function build(){
if [ -n "$IID" ]; then
echo "存在$SERVER_NAME镜像,IID=$IID"
else
echo "不存在$SERVER_NAME镜像,开始构建镜像"
cd $BASE_PATH/$SERVER_NAME
docker build -t $SERVER_NAME .
fi
}
# 运行docker容器
function run(){
backup
transfer
build
if [ -n "$CID" ]; then
echo "存在$SERVER_NAME容器,CID=$CID,重启docker容器 ..."
docker restart $SERVER_NAME
echo "$SERVER_NAME容器重启完成"
else
echo "不存在$SERVER_NAME容器,docker run创建容器..."
docker run --name $SERVER_NAME -v /data2/upload:/data2/upload -v /data2/logs/lfeel/lfeel-admin:/data2/logs/lfeel/lfeel-admin -d -p 8080:8080 $SERVER_NAME
echo "$SERVER_NAME容器创建完成"
fi
}
#入口
run
https://blog.csdn.net/w531128724/article/details/90672944
https://www.cnblogs.com/wang-yaz/p/10437377.html
https://www.cnblogs.com/wang-yaz/p/10437377.html
https://www.cnblogs.com/zhaojiankai/p/7828181.html
使用 Jenkins 和 Docker 实现持续集成和自动化部署
docker安装与使用
使用Jenkins pipeline流水线构建docker镜像和发布
https://segmentfault.com/a/1190000007837054
https://blog.csdn.net/jomexiaotao/article/details/83271458
部署vue前端项目
安装 NodeJS插件
npm install -g cnpm --registry=https://registry.npm.taobao.org # 添加镜像
https://nodejs.org/en/download/
# 下载源码包
wget https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.xz
tar xvJf ***.tar.xz -C /usr/local
cd /usr/local
ln -s node-v10.15.3/ nodejs
vi /etc/profile 添加以下内容
PATH=$PATH:/usr/local/node-v10.15.3-linux-x64/bin
source /etc/profile
node -v
# Provide Node & npm bin/ folder to PATH
选择系统工具里设置的nodejs安装的配置
# 构建 执行shell 填写node shell内容
npm install --registry https://registry.npm.taobao.org
cnpm install
npm run build
cd dist
rm -rf ****.tar.gz #删除上次打包生成的文件
tar -zcvf ****.tar.gz * #把生成的项目文件打包方便传输到远程服务器 解压后也是里面的文件
-- tar zcvf dist.tar.gz dist/ #解压后会有dist目录
cd ../
# 构建后操作 send build artifacts over ssh
source files dist/***.tar.gz
remove prefix dist
remote directory /vue/packages/
exec commond 如下:
cp /vue/packages/dist/***.tar.gz /usr/local/nginx/packages/
cd /usr/local/nginx/packages/
tar -zxvf ***.tar.gz
rm -rf ***.tar.gz
chmod -R 777 /usr/local/nginx/packages/dist
------------
npm install --registry https://registry.npm.taobao.org
npm run dev
tar zcvf dist.tar.gz dist/
rm -rf /usr/local/nginx/html/dist
cp dist.tar.gz /usr/local/nginx/web_flower/
cd /usr/local/nginx/html/
tar -zxvf dist.tar.gz
rm -rf dist.tar.gz
chmod -R 777 /usr/local/nginx/html/dist
----------
npm install --registry https://registry.npm.taobao.org
npm run test
tar zcvf dist.tar.gz dist/
pwd
rm -rf /usr/local/nginx/web_flower/dist.tar.gz
cp /home/flower/dist/dist.tar.gz /usr/local/nginx/html/
cd /usr/local/nginx/html/
tar -zxvf dist.tar.gz
chmod -R 777 /usr/local/nginx/html/dist/
https://blog.csdn.net/jonsonler/article/details/81317352
https://blog.csdn.net/wangzl1163/article/details/83018630
http://www.cnblogs.com/jingrf/p/10382509.html
npm install -g cnpm --registry=https://registry.npm.taobao.org
首先我们安装webpack-dev-server
在CMD中安装执行npm intall webpack-dev-server -g
在项目目录执行安装依赖命令: npm install --save-dev webpack-dev-server
npm install webpack -g
npm install webpack --save-dev
https://www.cnblogs.com/yupinghua/p/6308515.html