jenkins自动化搭建-tengine

本文介绍如何使用Jenkins自动化脚本tengine_create_remote_sync.sh部署Tengine,包括文件同步、远程安装、配置和启动,以及解决中文乱码问题。通过SSH免密登录,简化了远程操作流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

jenkins自动化搭建-tengine

jenkins的部署请参考以前的文章
Linux下用tomcat部署jenkins
部署jenkins的机器当做推送机对远程部署的机器进行免密,请参考以前的文章
Linux下实现免密登录
编写shell自动化搭建-tengine脚本,脚本内容如下
tengine_create_remote_sync.sh

#!/bin/bash

#init param(sync tar.gz)
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(){

	#remote create targetPath
	ssh root@$tengineIp "rm -rf $remoteToolsPath && mkdir -p $remoteToolsPath"

	#sync tar.gz to remote linux
	scp $sourcePath root@$tengineIp:$remoteToolsPath
	ssh root@$tengineIp "cd $remoteToolsPath && tar -zxvf *.tar.gz && rm -rf *.tar.gz && mv * tengine"  

	#sync shell to remote linux for exec
	scp $shellPath root@$tengineIp:$remoteToolsPath

	#exec remote shell
	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

#init param
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()
{
	#config worker_processes
	threadNum=$(awk '($1 == "processor"){print $3}' /proc/cpuinfo | wc -l)
        sed -i 's/worker_processes  1/worker_processes  '$threadNum'/'  $tengineInstallPath/conf/nginx.conf

	#config events
        sed -i '/^events/a use epoll;' $tengineInstallPath/conf/nginx.conf
	
	#config log
  	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

        #config server
        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

	#config monitor
	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控制台中文乱码问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gem丶超超

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值