netcore使用 jenkins + supervisor 实现standalone下多副本自动化发布
上一篇我们用jenkins做了一个简单的自动化发布,在shell中采用的是 BUILD_ID=dontKillMe nohup dotnet xxx.dll & 这种简单的后台承载,如果你的业务
量相对比较小,可以用这个方法玩一玩,但存在二个问题:1. 无法对进程进行批量或者可视化管理。 2. 单机模式下的多副本部署比较麻烦,比如你在一台机
器上开启多个同样的程序来提高队列的处理能力,解决这两个问题你可以使用netcore官方推荐的supervisor 进程管理工具。
一: supervisor
具体这玩意是干嘛的,我就不说了,大家自己看官网:http://www.supervisord.org/ 接下来快速部署一下。
1. pip
pip是python的一个包管理器,类似于nuget,如果你的centos上没有安装,那么请执行下面命令。
yum -y install epel-release
yum -y install python-pip
2. supervisor
因为supervisor是python写的,所以直接通过pip进行安装即可。
[root@k8s-node1 ~]# pip install supervisor
Collecting supervisor
Downloading https://files.pythonhosted.org/packages/ba/65/92575a8757ed576beaee59251f64a3287bde82bdc03964b89df9e1d29e1b/supervisor-3.3.5.tar.gz (421kB)
% |████████████████████████████████| 430kB 47kB/s
Collecting meld3>=0.6. (from supervisor)
Downloading https://files.pythonhosted.org/packages/b6/ae/e6d731e4b9661642c1b20591d8054855bb5b8281cbfa18f561c2edd783f7/meld3-1.0.2-py2.py3-none-any.whl
Installing collected packages: meld3, supervisor
Running setup.py install for supervisor ... done
Successfully installed meld3-1.0. supervisor-3.3.
You are using pip version 10.0., however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@k8s-node1 ~]# pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
% |████████████████████████████████| .3MB 49kB/s
Installing collected packages: pip
Found existing installation: pip 10.0.
Uninstalling pip-10.0.:
Successfully uninstalled pip-10.0.
Successfully installed pip-18.1
3. supervisord
这个就是supervisor的server端,启动之前生成一个默认的配置文件,放在 /data/supervisor/目录下。
[root@k8s-node1 supervisor]# pwd
/data/supervisor
[root@k8s-node1 supervisor]# echo_supervisord_conf > ./supervisord.conf
[root@k8s-node1 supervisor]# ls
supervisord.conf
关于配置文件的详细配置,你可以参考官方的:http://www.supervisord.org/configuration.html ,
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
; - Shell expansion ("~" or "$HOME") is not supported. Environment
; variables can be expanded using this syntax: "%(ENV_HOME)s".
; - Quotes around values are not supported, except in the case of
; the environment= options as shown below.
; - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
; - Command will be truncated if it looks like a config file comment, e.g.
; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ". [unix_http_server]
file=/tmp/supervisor.sock ; the path to the socket file
;chmod= ; socket file mode (default )
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; default is no username (open server)
;password= ; default is no password (open server) ;[inet_http_server] ; inet (TCP) server disabled by default
;port=127.0.0.1: ; ip_address:port specifier, *:port for all iface
;username=user ; default is no username (open server)
;password= ; default is no password (open server) [supervisord]
logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB
logfile_backups= ; # of main logfile backups; means none, default
loglevel=info ; log level; default info; others: debug,warn,trace
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false ; start in foreground if true; default false
minfds= ; min. avail startup file descriptors; default
minprocs= ; min. avail process descriptors;default
;umask= ; process file creation umask; default
;user=chrism ; default is current user, required if root
;identifier=supervisor ; supervisord identifier, default is 'supervisor'
;directory=/tmp ; default is not to cd during start
;nocleanup=true ; don't clean up tempfiles at start; default false
;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP
;environment=KEY="value" ; key value pairs to add to environment
;strip_ansi=false ; strip ansi escape codes in logs; def. false ; The rpcinterface:supervisor section must remain in the config file for
; RPC (supervisorctl/web interface) to work. Additional interfaces may be
; added by defining them in separate [rpcinterface:x] sections. [rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface ; The supervisorctl section configures how supervisorctl will connect to
; supervisord. configure it match the settings in either the unix_http_server
; or inet_http_server section. [supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris ; should be same as in [*_http_server] if set
;password= ; should be same as in [*_http_server] if set
;prompt=mysupervisor ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history ; use readline history if available ; The sample program section below shows all possible program subsection values.
; Create one or more 'real' program: sections to be able to control them under
; supervisor. ;[program:theprogramname]
;command=/bin/cat ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs= ; number of processes copies to start (def )
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask= ; umask for process (default None)
;priority= ; the relative start priority (default )
;autostart=true ; start at supervisord start (default: true)
;startsecs= ; # of secs prog must stay up to be running (def. )
;startretries= ; max # of serial start failures when starting (default )
;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
;exitcodes=, ; 'expected' exit codes used with autorestart (default ,)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs= ; max num secs to wait b4 SIGKILL (default )
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=true ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups= ; # of stdout logfile backups ( means none, default )
;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default )
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups= ; # of stderr logfile backups ( means none, default )
;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default )
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A="",B="" ; process environment additions (def no adds)
;serverurl=AUTO ; override serverurl computation (childutils) ; The sample eventlistener section below shows all possible eventlistener
; subsection values. Create one or more 'real' eventlistener: sections to be
; able to handle event notifications sent by supervisord. ;[eventlistener:theeventlistenername]
;command=/bin/eventlistener ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs= ; number of processes copies to start (def )
;events=EVENT ; event notif. types to subscribe to (req'd)
;buffer_size= ; event buffer queue size (default )
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask= ; umask for process (default None)
;priority=- ; the relative start priority (default -)
;autostart=true ; start at supervisord start (default: true)
;startsecs= ; # of secs prog must stay up to be running (def. )
;startretries= ; max # of serial start failures when starting (default )
;autorestart=unexpected ; autorestart if exited after running (def: unexpected)
;exitcodes=, ; 'expected' exit codes used with autorestart (default ,)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs= ; max num secs to wait b4 SIGKILL (default )
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups= ; # of stdout logfile backups ( means none, default )
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups= ; # of stderr logfile backups ( means none, default )
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A="",B="" ; process environment additions
;serverurl=AUTO ; override serverurl computation (childutils) ; The sample group section below shows all possible group values. Create one
; or more 'real' group: sections to create "heterogeneous" process groups. ;[group:thegroupname]
;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions
;priority= ; the relative start priority (default ) ; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves. ;[include]
;files = relative/directory/*.ini
上面的文件主要改两个地方:
《1》 开启supervisor的可视化界面
;[inet_http_server] ; inet (TCP) server disabled by default
;port=127.0.0.1: ; ip_address:port specifier, *:port for all iface
;username=user ; default is no username (open server)
;password= ; default is no password (open server)
改成:
[inet_http_server] ; inet (TCP) server disabled by default
port=0.0.0.0: ; ip_address:port specifier, *:port for all iface
;username=user ; default is no username (open server)
;password= ; default is no password (open server)
《2》 下面这个语法表示可以加载指定目录的所有ini文件,这个口子就方便我们给每个应用程序配一个xx.ini文件,这样当你update的时候,supervisor会
自动 将conf目录下*.ini文件和supervisor.conf进行合并。
;[include]
;files = relative/directory/*.ini
改成
[include]
files = ./conf/*.ini
最后启动一下,更多的你可以通过help命令查看。
[root@k8s-node1 supervisor]# supervisord -c ./supervisord.conf
4. supervisorctl
supervisotctl 是一个客户端工具,通过9001端口与server进行交互,可处理如下18个命令。
[root@k8s-master supervisord]# supervisorctl help default commands (type help <topic>):
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version
接下来可以在conf目录下生成一个 consoleapp3.ini 文件,程序名为:consoleapp3。
[root@k8s-master conf]# tail consoleapp3.ini
[program:consoleapp3]
command=/usr/bin/dotnet /data/supervisord/ConsoleApp3/ConsoleApp3.dll
autostart=true
autorestart=true
stdout_logfile=/data/supervisord/ConsoleApp3/.log
执行以下update命令让supervisor重新加载配置文件。
[root@k8s-master supervisord]# supervisorctl update
回到文章开头的问题,如果生成多个副本,你可以采用group模式,比如下面这样的 mytest.ini 文件放置到conf目录下。
[group:mytest]
programs=mytest1,mytest2,mytest3 [program:mytest1]
command=/usr/bin/dotnet /data/supervisord/mytest/ConsoleApp1.dll
autostart=true
autorestart=true
stdout_logfile=/data/supervisord/mytest/.log [program:mytest2]
command=/usr/bin/dotnet /data/supervisord/mytest/ConsoleApp1.dll
autostart=true
autorestart=true
stdout_logfile=/data/supervisord/mytest/.log [program:mytest3]
command=/usr/bin/dotnet /data/supervisord/mytest/ConsoleApp1.dll
autostart=true
autorestart=true
stdout_logfile=/data/supervisord/mytest/.log
然后通过 supervisorctl update 让supervisor重新加载配置文件,然后可观察可视化界面。
[root@k8s-master conf]# supervisorctl update
mytest: added process group
有了这个基础之后,和jenkins集成就很简单了,因为9001端口被占用,就重新指定了一个19001端口,把应用程序的*.ini文件放在解决方案里,这样自动化的
时候就可以找到*.ini文件,然后copy到supervisor的conf目录下,因为是强制copy,所以用管道模式 yes | .....
《1》 普通模式
supervisorctl -s http://localhost:19001 stop memsql-test \
&& cd ./MemSql.NetCore/MemSql.Test \
&& yes | cp ./doc/memsql-test.ini /data/supervisor/conf/ \
&& dotnet publish -o /data/output/MemSql.Test -c Release \
&& supervisorctl -s http://localhost:19001 update \
&& supervisorctl -s http://localhost:19001 start memsql-test
《2》 组模式
supervisorctl -s http://localhost:19001 stop memsql-automationdeploy:* \
&& cd ./MemSql.NetCore/MemSql.AutomationDeploy \
&& yes | cp ./doc/memsql-automationdeploy.ini /data/supervisor/conf/ \
&& dotnet publish -o /data/output/MemSql.AutomationDeploy -c Release \
&& supervisorctl -s http://localhost:19001 update \
&& supervisorctl -s http://localhost:19001 start memsql-automationdeploy:*
好了,本篇就说到这里,如果有人问多机器怎么玩,下篇再说ansible~
netcore使用 jenkins + supervisor 实现standalone下多副本自动化发布的更多相关文章
- .NetCore 利用Jenkins在 Windows平台下打包发布Angular项目
准备环境 安装Jenkins 首先装node,版本根据实际环境而定(node安装包中包含了npm) 安装一般都配置好了环境变量,检查下如果没有就配置下 Jenkins中安装NPM插件 GIt获取代码 ...
- jenkins + supervisor + ansible 实现netcore程序的多机一键部署
上一篇我们简单的说到了使用jenkins+supervisor实现了一个单机版的多副本部署,但是在更多的场景下还是需要netcore程序的多机一键部署,那么多 机器间如何分发呢? 肯定不能使用scp这 ...
- .NetCore基于Jenkins和Gogs的自动化部署方案
准备工作 Jenkins和gogs的安装配置可以看前两篇:Jenkins安装.配置与说明 和 gogs安装与说明(docker) 此外,因为还要安装.net core的SDK和Git工具: 安装.n ...
- netcore编程之后面对不习惯的xshell黑屏部署,是时候使用jenkins自动化发布工具了
在很久之前net还只能在windows上部署的时候,或许很多创业公司的朋友发布项目还都是人肉部署,反正windows都是可视化的界面,拖拖拉拉,开开关关还不 是特别麻烦...现如今你的项目需要在li ...
- Linux CentOS7下svn+tomcat9.0+maven3.3+jenkins实现web项目自动构建与远程发布
CentOS7下svn+tomcat9.0+maven3.3+jenkins实现web项目自动构建与远程发布 by:授客 QQ:1033553122 目录 一. 实践环境. 1 二. 安装 ...
- .netcore下的微服务、容器、运维、自动化发布
原文:.netcore下的微服务.容器.运维.自动化发布 微服务 1.1 基本概念 1.1.1 什么是微服务? 微服务架构是SOA思想某一种具体实现.是一种将单应用程序作为一套小型 ...
- jenkins部署到Tomcat下
一.首选要下载与安装jdk,因为需要在Java环境下面运行,安装好jdk后配置java环境变量(jdk环境变量的配置网上很多) 我本人安装的是jdk1.8 二.安装好jdk后,需要下载tomcat,这 ...
- Jenkins下构建UI自动化之初体验
一.缘 起 笔者之前一直在Windows环境下编写UI自动化测试脚本,近日在看<京东系统质量保障技术实战>一书中,萌生出在jenkins下构建UI自动化测试的想法 二.思 路 首先,在Li ...
- Jenkins持续集成(下)-Jenkins部署Asp.Net网站自动发布
环境:Windows 2008 R2.Jenkins2.235.1.Visual Studio 2017: 概要 前面写过一篇文章,<自动发布-asp.net自动发布.IIS站点自动发布(集成S ...
随机推荐
- SDE与shapefile之间的数据导入与导出
一.SDE要素导出到shapefile中. 1.创建一个新的shapefile文件. private bool CreateShapefile(string filepath, string name ...
- JavaScript常用的事件模型
一.事件绑定模型 DOM0事件模型 1.内联模型(行内绑定):将函数名直接作为HTML标签中事件属性的属性值 <button id="btn" onclick="f ...
- Angular使用总结 ---以密码确认为例实现模版驱动表单的自定义校验
上一篇 总结了模版驱动表单的基本用法,示例中的校验使用的是原生HTML5的校验方式,本文补上自定义校验的部分. HTML5原生的表单校验属性(必填,长度限制,取值间隔,正则表达式等等)可以满足普通的校 ...
- 集成学习之Boosting —— AdaBoost原理
集成学习大致可分为两大类:Bagging和Boosting.Bagging一般使用强学习器,其个体学习器之间不存在强依赖关系,容易并行.Boosting则使用弱分类器,其个体学习器之间存在强依赖关系, ...
- Spring Security Oauth2系列(一)
前言: 关于oauth2,其实是一个规范,本文重点讲解spring对他进行的实现,如果你还不清楚授权服务器,资源服务器,认证授权等基础概念,可以移步理解OAuth 2.0 - 阮一峰,这是一篇对于oa ...
- SSH概念及常用操作汇总
工作有一段时间了,经常用SSH登录远程机器,但对原理一直不是很了解,所以查阅了一些资料,写个小结. 一. SSH是什么? SSH的全称是Secure Shell, 是一种“用来在不安全的网络上安全地运 ...
- centos6.9 升级内核版本
想在centos6.9上安装docket,不过因为内核版本是2.6的故而想升级到最新的内核版本 晚上有编译升级的比较麻烦,不过有助于理解内核升级,我使用的直接升级到最新版方法 1. 导入public ...
- FPGA学习笔记(二)——FPGA学习路线及开发流程
###### [该随笔部分内容转载自小梅哥] ######### 一.FPGA学习路线 工具使用 -> 语法学习 -> 逻辑设计 -> IP使用 ->接口设计 -& ...
- monkey操作
1.monkey命令格式 直接adb shell进入后输入monkey [options] <eventcount> 或者每次输入adb shell monkey [options] &l ...
- css中的单冒号和双冒号
最近突然被别人问起css单冒号和双冒号有什么区别,答曰:"不知道". 虽然还在填坑中,但作为一个跨过了初级的FEer,感觉着实汗颜,刚好今天下午在搜别的问题的时候,突然看到一个对比 ...