jenkins自动化搭建-tengine
jenkins的部署请参考以前的文章 Linux下用tomcat部署jenkins 部署jenkins的机器当做推送机对远程部署的机器进行免密,请参考以前的文章 Linux下实现免密登录 编写shell自动化搭建-tengine脚本,脚本内容如下 tengine_create_remote_sync.sh
#!/bin/bash
sourcePath=$1
tengineIp=$2
tenginePort=$3
remoteToolsPath=$4
remoteInstallPath=$5
remoteLocationConf=$6
remoteUpstreamConf=$7
shellFileName=tengine_cluster_auto_config.sh
shellPath=/root/tools/shell/tengine/remote/remote_create_and_cluster_config/$shellFileName
function remote_sync(){
ssh root@$tengineIp "rm -rf $remoteToolsPath && mkdir -p $remoteToolsPath"
scp $sourcePath root@$tengineIp:$remoteToolsPath
ssh root@$tengineIp "cd $remoteToolsPath && tar -zxvf *.tar.gz && rm -rf *.tar.gz && mv * tengine"
scp $shellPath root@$tengineIp:$remoteToolsPath
ssh root@$tengineIp "chmod 755 $remoteToolsPath/$shellFileName"
ssh root@$tengineIp "sh $remoteToolsPath/$shellFileName $remoteToolsPath/tengine $tengineIp $tenginePort $remoteInstallPath $remoteLocationConf $remoteUpstreamConf"
}
remote_sync
tengine_cluster_auto_config.sh
#!/bin/bash
source /etc/profile
tengineToolsPath=$1
tengineMasterIp=$2
tenginePort=$3
tengineInstallPath=$4
tengineLocationConf=$5
tengineUpstreamConf=$6
function tengine_server_install()
{
rm -rf $tengineInstallPath && cd $tengineToolsPath
./configure --prefix=$tengineInstallPath && make && make install
}
function tengine_server_config()
{
threadNum=$(awk '($1 == "processor"){print $3}' /proc/cpuinfo | wc -l)
sed -i 's/worker_processes 1/worker_processes '$threadNum'/' $tengineInstallPath/conf/nginx.conf
sed -i '/^events/a use epoll;' $tengineInstallPath/conf/nginx.conf
sed -i '/#log_format/s/#//g' $tengineInstallPath/conf/nginx.conf
sed -i '/$body_bytes_sent/s/#//g' $tengineInstallPath/conf/nginx.conf
sed -i '/$http_user_agent/s/#//g' $tengineInstallPath/conf/nginx.conf
sed -i '/logs\/access.log/s/#//g' $tengineInstallPath/conf/nginx.conf
sed -i 's/listen 80/listen '$tenginePort'/' $tengineInstallPath/conf/nginx.conf
sed -i '/#charset koi8-r/a '$tengineLocationConf'' $tengineInstallPath/conf/nginx.conf
sed -i '/#gzip on/a '$tengineUpstreamConf'' $tengineInstallPath/conf/nginx.conf
sed -i '/#charset koi8-r/a location \/status{\nstub_status on;\naccess_log off;\n}\n' $tengineInstallPath/conf/nginx.conf
sed -i '/#charset koi8-r/a location \/upstream{\ncheck_status;\naccess_log off;\n}\n' $tengineInstallPath/conf/nginx.conf
}
function tengine_server_start(){
pidCount=$(lsof -i:$tenginePort | grep -v COMMAND | wc -l)
if [ $pidCount -gt 1 ];then
lsof -i:$tenginePort | grep -v COMMAND | awk '{print $2}'| xargs kill -9 > /dev/null 2>&1
fi
$tengineInstallPath/sbin/nginx
}
function tengine_server_monitor(){
localIp=$(ifconfig -a | grep inet | grep -v 127.0.0.1 | grep -v inet6 | awk '{print $2}')
keyNum=$(curl $localIp:$tenginePort | grep 'Thank you for using tengine' | wc -l)
if [ $keyNum -eq 1 ];then
echo "tengine启动成功,访问地址http://$localIp:$tenginePort"
else
echo "tengine启动失败"
fi
}
tengine_server_install
tengine_server_config
tengine_server_start
tengine_server_monitor
将脚本放在指定目录/root/tools/shell/tengine/remote/jenkins下 将tengine-2.1.2.tar.gz安装包放在指定目录/root/tools/tengine下 tengine-2.1.2.tar.gz安装包下载 链接:https://pan.baidu.com/s/1z7zSvrUukzrQSDygtb3BaQ 提取码:tip4 jenkins新建任务步骤如下
time sh /root/tools/shell/tengine/remote/jenkins/tengine_create_remote_sync.sh $sourcePath $tengineIp $tenginePort $remoteToolsPath $remoteInstallPath $remoteLocationConf $remoteUpstreamConf
保存后就算完成jenkins的配置了 执行构建任务 如有控制台中文乱码的话,请参考以前的文章 解决jenkins控制台中文乱码问题
|