自动化部署shell
yum install curl policycoreutils openssh-server openssh-clients postfix
[root@linux-node2 ~]# yum install curl policycoreutils openssh-server openssh-clients postfix
[root@linux-node2 ~]# systemctl start postfix
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh| sudo bash
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh| bash
yum install -y gitlab-ce
[root@linux-node2 ~]# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
[root@linux-node2 ~]# yum makecache
[root@linux-node2 ~]# yum install gitlab-ce
/etc/gitlab
[root@node2 gitlab]# egrep -v "^$|^#" gitlab.rb
external_url 'http://192.168.3.4.com'
gitlab-ctl reconfigure
gitlab-ctl status
关闭gitlab:[root@linux-node2 ~]# gitlab-ctl stop
启动gitlab:[root@linux-node2 ~]# gitlab-ctl start
重启gitlab:[root@linux-node2 ~]# gitlab-ctl restart
最终脚本
#!/bin/bash
# Dir List
# mkdir -p /deploy/code/web-demo
# mkdir -p /deploy/config/web-demo/base
# mkdir -p /deploy/config/web-demo/other
# mkdir -p /deploy/tar
# mkdir -p /deploy/tmp
# mkdir -p /opt/webroot
# mkdir -p /webroot
# chown -R www.www /deploy
# chown -R www.www /opt/webroot
# chown -R www.www /webroot
# Node List
PRE_LIST="192.168.3.3"
GROUP2_LIST="192.168.3.4"
NODE_LIST="192.168.3.3 192.168.3.4"
ROLLBACK_LIST="192.168.3.3 192.168.3.4"
# Date/Time Veriables
LOG_CTIME=$(date "+%H-%M-%S")
LOG_CDATE=$(date "+%Y-%m-%d")
CTIME="date +%Y-%m-%d"
CDATE="date +%H-%M-%S"
# Shell Env
PRO_NAME="web-demo"
SHELL_NAME="deploy.sh"
SHELL_DIR="/home/www/"
SHELL_LOG="${SHELL_DIR}/${SHELL_NAME}.log"
LOCK_FILE="/tmp/deploy.lock"
# Code Env
CODE_DIR="/deploy/code/web-demo"
CONFIG_DIR="/deploy/config/web-demo"
TMP_DIR="/deploy/tmp"
TAR_DIR="/deploy/tar"
url_test(){
URL=$1
curl -s --head $1 |grep '200 OK'
if [ $? -ne 0 ]; then
shell_unlock;
writelog "test error" &&exit;
fi
}
usage(){
echo $"Usage $0 { deploy | rollback [ list | version ] }"
}
writelog(){
LOGINFO=$1
echo "`${CDATE}` `${CTIME}`: ${SHELL_NAME} : ${LOGINFO} " >> ${SHELL_LOG}
}
shell_lock(){
touch ${LOCK_FILE}
}
shell_unlock(){
rm -f ${LOCK_FILE}
}
code_get(){
echo code_get
writelog "code_get"
cd ${CODE_DIR} && git pull
cp -rp ${CODE_DIR} ${TMP_DIR}/
API_VERL=`git show|grep commit|cut -d ' ' -f2`
API_VER=${API_VERL:0:6}
}
code_build(){
echo code_build
}
code_config(){
echo code_config
writelog "code_config"
/bin/cp -rp ${CONFIG_DIR}/base/* ${TMP_DIR}/${PRO_NAME}
PKG_NAME="${PRO_NAME}"_"${API_VER}"-"`$CDATE`-`${CTIME}`"
cd ${TMP_DIR} && mv ${PRO_NAME} ${PKG_NAME}
}
code_tar(){
echo code_tar
writelog "code_tar"
cd ${TMP_DIR} && tar czf ${PKG_NAME}.tar.gz ${PKG_NAME}
writelog "${PKG_NAME}.tar.gz"
}
code_scp(){
echo code_scp
writelog "code_scp"
for node in $PRE_LIST ;do
scp ${TMP_DIR}/${PKG_NAME}.tar.gz $node:/opt/webroot/
done
for node in $GROUP2_LIST ;do
scp ${TMP_DIR}/${PKG_NAME}.tar.gz $node:/opt/webroot/
done
}
cluster_node_remove(){
writelog "cluster_node_remove"
echo cluster_node_remove
}
pre_deploy(){
writelog "remove from cluster pre"
echo code_deploy
for node in $PRE_LIST ;do
ssh $node "cd /opt/webroot && tar zxf ${PKG_NAME}.tar.gz"
ssh $node "rm -f /webroot/web-demo && ln -s /opt/webroot/${PKG_NAME} /webroot/web-demo"
done
}
pre_test(){
url_test "http://${PRE_LIST}/index.html"
echo "add to cluster pre"
}
group2_deploy(){
writelog "remove from cluster 2"
for node in $GROUP2_LIST ;do
ssh $node "cd /opt/webroot && tar zxf ${PKG_NAME}.tar.gz"
ssh $node "rm -f /webroot/web-demo && ln -s /opt/webroot/${PKG_NAME} /webroot/web-demo"
done
scp ${CONFIG_DIR}/other/192.168.3.4.crontab.xml 192.168.3.4:/webroot/web-demo/crontab.xml
}
group2_test(){
for node in $GROUP2_LIST ;do
url_test "http://${node}/index.html"
done
echo "add to cluster group2"
}
config_diff(){
echo config_diff
}
code_test(){
echo code_test
}
cluster_node_in(){
echo cluster_node_in
}
rollback_fun(){
[ -z $1 ] && echo "input rollback version" &&return
for node in $ROLLBACK_LIST ;do
ssh $node "[ -d /opt/webroot/$1 ] && rm -f /webroot/web-demo && ln -s /opt/webroot/$1 /webroot/web-demo"
done
}
rollback (){
case $1 in
list)
ls -l /opt/webroot/*.tar.gz
;;
*)
rollback_fun $1
esac
}
main(){
if [ -f $LOCK_FILE ]; then
echo "Deploy is running" && exit;
fi
shell_lock
DEPLOY_METHOD=$1
ROLLBACK_VER=$2
case $DEPLOY_METHOD in
deploy)
code_get;
code_build;
code_config;
code_tar;
code_scp;
pre_deploy;
pre_test;
group2_deploy;
group2_test;
config_diff;
code_test;
cluster_node_in;
;;
rollback)
rollback $ROLLBACK_VER
;;
*)
usage;
esac
shell_unlock
}
main $1 $2
自动化部署shell的更多相关文章
- 自动化部署--shell脚本--1
传统部署方式1.纯手工scp2.纯手工登录git pull .svn update3.纯手工xftp往上拉4.开发给打一个压缩包,rz上去.解压 传统部署缺点:1.全程运维参与,占用大量时间2.上线速 ...
- 自动化部署--shell脚本--2
node1和node2都装apache [root@linux-node1 ~]# yum install httpd -y Loaded plugins: fastestmirror Loadi ...
- 自动化部署--shell脚本--3
登录gitlab第一次登录gitlab,需要为root用户修改密码,root用户也是gitlab的超级管理员.http://192.168.58.11设置密码是gitlab 密码不够长,重新设置下,设 ...
- LINUX系统自动化部署shell脚本
#!/bin/shsudo /etc/init.d/tomcatstopwaitsudo rm -rf /opt/tomcat7/work/*waitsudo rm -rf /opt/tomcat7/ ...
- 通过shell脚本实现代码自动化部署
通过shell脚本实现代码自动化部署 一.传统部署方式及优缺点 1.传统部署方式 (1)纯手工scp (2)纯手工登录git pull.svn update (3)纯手工xftp往上拉 (4)开发给打 ...
- Linux下的Jenkins+Tomcat+Maven+Gitlab+Shell环境的搭建使用(jenkins自动化部署)
jenkins自动化部署 目标:jenkins上点构建(也可以自动检查代码变化自动构建)>>>项目部署完成. 一.安装jenkins 1.下载jenkins 这里我选择的是war包安 ...
- shell脚本自动化部署服务
shell脚本自动化部署 !/bin/bash #export PATH=$PATH:/export/maven/bin run_flag_dir="/data0/shell/deploy_ ...
- Linux下的Jenkins+Tomcat+Maven+Git+Shell环境的搭建使用(jenkins自动化部署)【转】
jenkins自动化部署 目标:jenkins上点构建(也可以自动检查代码变化自动构建)>>>项目部署完成. 一.安装jenkins 1.下载jenkins 这里我选择的是war包安 ...
- 运维与自动化系列③自动化部署基础与shell脚本实现
自动化部署基础与shell脚本实现 关于自动化的基础知识: 1.1:当前代码部署的实现方式: 运维纯手工scp到web服务器纯手工登录git服务器执行git pull或svn服务器执行svn upda ...
随机推荐
- Dubbo源码阅读顺序
转载: https://blog.csdn.net/heroqiang/article/details/85340958 Dubbo源码解析之配置解析篇,主要内容是<dubbo:service/ ...
- Android 开发 创建WiFi、WiFi热点 ---开发集合
WIFI 权限 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> < ...
- leetcode3
public class Solution { public int LengthOfLongestSubstring(string s) { var dic = new Dictionary< ...
- Kubelet bootstrap 流程
首先,什么是kubelet bootstrap?在安装 k8s worker node 时,基本上 worker 的初始状态仅仅是安装了 docker 和 kubelet,worker 需要一种机制跟 ...
- Hibernate 再接触 事务隔离机制
事务:要么都要完成,一个不完成就要回滚. ACID 原子性 一致性 独立性 持久性 第一类丢失更新 第一类丢失更新 脏读(读了另外一个事务没有提交的数据) 不可重复读(在同一个事务里,对数据库里的值前 ...
- HTML 元素大小
1.元素的偏移量 元素的可见大小是由其高度.宽度决定,包括所有的内边距.滚动条和边框大小(不包括外边距). offsetHeight :元素在垂直方向上占用的空间大小,以像素计算.包括元素的高度,水平 ...
- python动态模块导入
首先创建一个模块目录lib,然后在目录内创建一个模块为:aa.py 官方推荐: import importlib aa = importlib.import_module('lib.aa') c = ...
- 整合Spring框架和MyBatis框架
------------------------siwuxie095 整合 Spring 框架和 MyBatis 框架 ...
- [Java核心技术]第四章-对象与类(4.1-4.6总结)
4.1面向对象程序设计概述 OOP(面向对象编程Object Oriented Programming) OOP中数据第一位,算法第二位. 类 封装:关键在于不能让其他方法直接访问类的实例域,程序仅通 ...
- [leetcode]366. Find Leaves of Binary Tree捡树叶
Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves ...