日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2023/12/4 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 netcore使用 jenkins + supervisor 实现standalone下多副本自动化发布 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

前面的文章聊過用 jenkins 做了一個簡單的自動化發(fā)布,在shell中采用的是 BUILD_ID=dontKillMe nohup dotnet xxx.dll & ?這種簡單的后臺承載,如果你的業(yè)務(wù)量相對比較小,可以用這個方法玩一玩,但存在二個問題:1. 無法對進程進行批量或者可視化管理。2. 單機模式下的多副本部署比較麻煩,比如你在一臺機器上開啟多個同樣的程序來提高隊列的處理能力,解決這兩個問題你可以使用netcore官方推薦的 supervisor 進程管理工具。

一:supervisor

具體這玩意是干嘛的,我就不說了,大家自己看官網(wǎng):http://www.supervisord.org/ ?接下來快速部署一下。

1. ?pip

pip是python的一個包管理器,類似于nuget,如果你的centos上沒有安裝,那么請執(zhí)行下面命令。

yum?-y?install?epel-release yum?-y?install?python-pip

2. supervisor

因為supervisor是python寫的,所以直接通過pip進行安裝即可。

[root@k8s-node1?~]#?pip?install?supervisor Collecting?supervisorDownloading?https://files.pythonhosted.org/packages/ba/65/92575a8757ed576beaee59251f64a3287bde82bdc03964b89df9e1d29e1b/supervisor-3.3.5.tar.gz?(421kB)100%?|████████████████████████████████|?430kB?47kB/s Collecting?meld3>=0.6.5?(from?supervisor)Downloading?https://files.pythonhosted.org/packages/b6/ae/e6d731e4b9661642c1b20591d8054855bb5b8281cbfa18f561c2edd783f7/meld3-1.0.2-py2.py3-none-any.whl Installing?collected?packages:?meld3,?supervisorRunning?setup.py?install?for?supervisor?...?done Successfully?installed?meld3-1.0.2?supervisor-3.3.5 You?are?using?pip?version?10.0.1,?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?pipDownloading?https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl?(1.3MB)100%?|████████████████████████████████|?1.3MB?49kB/s Installing?collected?packages:?pipFound?existing?installation:?pip?10.0.1Uninstalling?pip-10.0.1:Successfully?uninstalled?pip-10.0.1 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

關(guān)于配置文件的詳細配置,你可以參考官方的:http://www.supervisord.org/configuration.html ,

[unix_http_server] file=/tmp/supervisor.sock[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; The rpcinterface:supervisor p 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] ps.[rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface; The supervisorctl p configures how supervisorctl will connect to ; supervisord. configure it match the settings in either the unix_http_server ; or inet_http_server p.[supervisorctl] serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket

上面的文件主要改兩個地方:

  • 開啟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)
  • 下面這個語法表示可以加載指定目錄的所有ini文件,這個口子就方便我們給每個應(yīng)用程序配一個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?helpdefault?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/1.log

執(zhí)行以下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/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重新加載配置文件,然后可觀察可視化界面。

[root@k8s-master?conf]#?supervisorctl?update? mytest:?added?process?group

有了這個基礎(chǔ)之后,和jenkins集成就很簡單了,因為9001端口被占用,就重新指定了一個19001端口,把應(yīng)用程序的*.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~

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的netcore使用 jenkins + supervisor 实现standalone下多副本自动化发布的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。