netcore使用 jenkins + supervisor 实现standalone下多副本自动化发布

原文: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上没有安装,那么请执行下面命令。

1 yum -y install epel-release
2 yum -y install python-pip

2. supervisor

因为supervisor是python写的,所以直接通过pip进行安装即可。

 1 [[email protected] ~]# pip install supervisor
 2 Collecting supervisor
 3   Downloading https://files.pythonhosted.org/packages/ba/65/92575a8757ed576beaee59251f64a3287bde82bdc03964b89df9e1d29e1b/supervisor-3.3.5.tar.gz (421kB)
 4     100% |████████████████████████████████| 430kB 47kB/s
 5 Collecting meld3>=0.6.5 (from supervisor)
 6   Downloading https://files.pythonhosted.org/packages/b6/ae/e6d731e4b9661642c1b20591d8054855bb5b8281cbfa18f561c2edd783f7/meld3-1.0.2-py2.py3-none-any.whl
 7 Installing collected packages: meld3, supervisor
 8   Running setup.py install for supervisor ... done
 9 Successfully installed meld3-1.0.2 supervisor-3.3.5
10 You are using pip version 10.0.1, however version 18.1 is available.
11 You should consider upgrading via the ‘pip install --upgrade pip‘ command.
12 [[email protected] ~]# pip install --upgrade pip
13 Collecting pip
14   Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
15     100% |████████████████████████████████| 1.3MB 49kB/s
16 Installing collected packages: pip
17   Found existing installation: pip 10.0.1
18     Uninstalling pip-10.0.1:
19       Successfully uninstalled pip-10.0.1
20 Successfully installed pip-18.1

3. supervisord

这个就是supervisor的server端,启动之前生成一个默认的配置文件,放在 /data/supervisor/目录下。

1 [[email protected] supervisor]# pwd
2 /data/supervisor
3 [[email protected] supervisor]# echo_supervisord_conf > ./supervisord.conf
4 [[email protected] supervisor]# ls
5 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=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; 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=10           ; # of main logfile backups; 0 means none, default 10
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=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200
;umask=022                   ; process file creation umask; default 022
;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=123                ; 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=1                    ; number of processes copies to start (def 1)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=999                  ; the relative start priority (default 999)
;autostart=true                ; start at supervisord start (default: true)
;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
;startretries=3                ; max # of serial start failures when starting (default 3)
;autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
;exitcodes=0,2                 ; ‘expected‘ exit codes used with autorestart (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;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=10     ; # of stdout logfile backups (0 means none, default 10)
;stdout_capture_maxbytes=1MB   ; number of bytes in ‘capturemode‘ (default 0)
;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=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_capture_maxbytes=1MB   ; number of bytes in ‘capturemode‘ (default 0)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A="1",B="2"       ; 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=1                    ; number of processes copies to start (def 1)
;events=EVENT                  ; event notif. types to subscribe to (req‘d)
;buffer_size=10                ; event buffer queue size (default 10)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=-1                   ; the relative start priority (default -1)
;autostart=true                ; start at supervisord start (default: true)
;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
;startretries=3                ; max # of serial start failures when starting (default 3)
;autorestart=unexpected        ; autorestart if exited after running (def: unexpected)
;exitcodes=0,2                 ; ‘expected‘ exit codes used with autorestart (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;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=10     ; # of stdout logfile backups (0 means none, default 10)
;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=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A="1",B="2"       ; 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=999                  ; the relative start priority (default 999)

; 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:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

改成:

[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0:9001          ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; 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命令查看。

[[email protected] supervisor]# supervisord -c ./supervisord.conf

4. supervisorctl

supervisotctl 是一个客户端工具,通过9001端口与server进行交互,可处理如下18个命令。

[[email protected]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。

[[email protected] conf]# tail consoleapp3.ini
[program:consoleapp3]
command=/usr/bin/dotnet /data/supervisord/ConsoleApp3/ConsoleApp3.dll
autostart=true
autorestart=true
stdout_logfile=/data/supervisord/ConsoleApp3/1.log

执行以下update命令让supervisor重新加载配置文件。

[[email protected] 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/4.log

[program:mytest2]
command=/usr/bin/dotnet /data/supervisord/mytest/ConsoleApp1.dll
autostart=true
autorestart=true
stdout_logfile=/data/supervisord/mytest/5.log

[program:mytest3]
command=/usr/bin/dotnet /data/supervisord/mytest/ConsoleApp1.dll
autostart=true
autorestart=true
stdout_logfile=/data/supervisord/mytest/6.log

然后通过 supervisorctl update 让supervisor重新加载配置文件,然后可观察可视化界面。

[[email protected]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~

原文地址:https://www.cnblogs.com/lonelyxmas/p/10308865.html

时间: 2024-10-08 17:03:52

netcore使用 jenkins + supervisor 实现standalone下多副本自动化发布的相关文章

使用jenkins + supervisor 实现standalone下多副本自动发布

上一篇我们用jenkins做了一个简单的自动化发布,在shell中采用的是 BUILD_ID=dontKillMe nohup dotnet xxx.dll &  这种简单的后台承载,如果你的业务 量相对比较小,可以用这个方法玩一玩,但存在二个问题:1. 无法对进程进行批量或者可视化管理. 2. 单机模式下的多副本部署比较麻烦,比如你在一台机 器上开启多个同样的程序来提高队列的处理能力,解决这两个问题你可以使用netcore官方推荐的supervisor 进程管理工具. 一: superviso

netcore + docker + jenkins 持续集成日志

要实现的目标 : 提交代码到github的master分支后, 触发webhook, jenkins从github上重新拉取代码=>编译=>打包成docker镜像=>重新发布 机器: centos 7.4 1. 安装git,jenkins,docker-ce git可以直接yum 安装 : yum install git -y 也可以安装新版本 参考文章:  https://linuxize.com/post/how-to-install-git-on-centos-7/ jenkins

Jenkins环境搭建部署实现代码自动化发布

一.jenkins代码自动部署 1.配置免密钥通信 实现自动化部署首先要解决的是免密码传输,配置jenkins至测试服务器之间免密钥ssh登录 测试免密钥ssh登录 在测试服务器上编写一个测试脚本,检测是否可以执行成功,正式环境可以写一个自动化部署的脚本 2.jenkins新建部署代码项目 在构建这里选择执行shell命令 点击立即构建 控制台输出日志:成功 这样就实现了使用jenkins代码的自动化部署 实际情况中我们通常使用版本控制系统管理代码,svn 或者 git 二.gitlab利用we

边缘化搭建 DotNet Core 2.1 自动化发布和部署(下)

写在前面 本篇文章是上一篇边缘化搭建 DotNet Core 2.1 自动化发布和部署(上)的后续操作,本文主要讲解如何开启Docker Remote API,开启Remote API后的权限安全问题.配置Jenkins构建项目,并在云服务器上构建成功.废话不多说,我们一起来动手操作吧. 先决条件 1.一台Debain 9系统 x86 服务器 硬件环境:1核2G 40G硬盘. 2. x86服务器成功安装并运行Docker环境(本文不阐述安装过程,读者可查阅参考文献) 2.根据上一篇边缘化搭建 D

从0到1体验Jenkins+Docker+Git+Registry实现CI自动化发布

一.前言 Jenkins是一款开源 CI&CD 软件,用于自动化各种任务,包括构建.测试和部署软件.Jenkins 支持各种运行方式,可通过系统包.Docker 或者通过一个独立的 Java 程序.Jenkins是一个广泛用于持续构建的可视化Web工具,持续构建就是将项目自动化编译.打包.部署.通过规范化来完成,简单,繁琐,浪费时间的重复工作. Jenkins名言:构建伟大,无所不能! Jenkins用户手册传送门:https://jenkins.io/zh/doc/ 二.发布流程 工作详细流程

Linux下C/C++版本发布自动脚本

软件发布有软件版本管理原则,这里结合Linux下C/C++项目发布方式,简单介绍一下如何自动的集成动态版本管理脚本. 软件版本发布关键点 从软件版本管理原则我们需要注意的是以下几个关键点: ==>主版本(VER_MAJOR):项目(产品)负责人维护 ==>次版本(VER_MINOR):技术(版本)接口人维护 ==>版本号(VER_REVISION):代码库自动升级更新 ==>编译日期(BUILD_DATE):编译机器的系统日期 ==>编译时间(BUILD_TIME):编译机器

基于Gitlab+Jenkins的代码自动化发布

这里所讲的自动化发布是指代码从提交到仓库,到发布到目标服务器的整个过程. 主要涉及到两个工具Gitlab,Jenkins,要完成自动化还需要rsync,qqbot,log,ant.shell脚本,python等. Gitlab:我们主要用它来做代码的仓库 Jenkins:用来执行任务的持续集成,构建等.一.大体的自动化思路: 开发人员push代码到gitlab,触发webhook,调用jenkins job. jenkins job 执行拉取代码,编译,调用loadblance,下架部分服务器更

生产环境下GeoServer如何优化--发布大数据量的影像(大于2g的tiff格式影像)

生产环境下GeoServer如何优化--发布大数据量的影像(大于2g的TIFF格式影像) 前言 Geoserver可以高效的处理数据量小于2GB的TIFF影像,一旦影像的大小超过了2GB,就需要考虑用影像金字塔来替代. 影像金字塔创建多重镶嵌的影像,每个都在不同层级,使得每个切片都存储为一个分离的文件.虽然看起来会增加切片合成的成本,但是却可以加快图像处理速度, 每个预览都是平铺的,因此可以高效的访问子集. 创建金字塔过程 1.准备geotiff格式的影像,下载开源应用程序FWTools 2.打

ansible+Jenkins+supervisor(Jenkins守护进程)

安装的插件 ansible ,ansible+windows ,SDK,gradle 3.0,groovy,svn,git,ant,maven,java-1.8.0-openjdk 本博客所有的脚本都是基于centos7 及windows server 2008 R2 编写 所有的自动化部署工具都是基于 ansible #!/bin/bash if [ $( rpm -qi epel-release | wc -l ) -gt 1 ]; then echo "epel-release insta