Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【demo演示】一键发布Linux服务部署(netcore web项目) #38

Open
yuzd opened this issue Nov 21, 2020 · 0 comments
Open

【demo演示】一键发布Linux服务部署(netcore web项目) #38

yuzd opened this issue Nov 21, 2020 · 0 comments
Labels
good first issue Good for newcomers

Comments

@yuzd
Copy link
Owner

yuzd commented Nov 21, 2020

AntDeploy 是我开发一款开源一键发布插件

  • 将本地vs中的代码,一键打包,部署到任意的远程服务器
  • 部署方式支持 windows服务,linux服务,docker容器,iis
  • 支持增量发布(只更新有修改的)
  • 支持一键回滚(出了问题快速恢复)
  • 支持查看发布历史记录

AntDeploy的代码托管地址(感恩star)

https://github.com/yuzd/AntDeploy

本章介绍如何使用AntDeploy一键部署到远程linux服务器作为服务运行

  • linux服务器为aws的 ecs: 系统为ubuntu18.04.4 (x64)
  • 服务器上无安装dotnet环境(因为AntDeploy用的是独立部署)

第一步 安装Linux端Agent

请在qq群(488312978)文件里面获取

image

把文件上传你的linux服务器

解压后有3个文件
image

  • AntAgent.service 是安装为服务的描述文件
  • AntDeployAgentLinuxService 执行文件
  • AntDeployAgentLinuxService.config 配置参数

按照下面更改AntAgent.service中的
WorkingDirectory 和 ExecStart

[Unit]
Description=AntAgent

[Service]
Type=notify

## WorkingDirectory是上面的AntDeployAgentLinuxService所在目录
WorkingDirectory=/home/ubuntu/download
## ExecStart是AntDeployAgentLinuxService执行文件的完整路径
ExecStart=/home/ubuntu/download/AntDeployAgentLinuxService
SyslogIdentifier=AntAgent
Restart=always        
RestartSec=5

[Install]
WantedBy=multi-user.target

赋予这个可执行文件权限

chmod +x AntDeployAgentLinuxService

image

修改agent配置文件AntDeployAgentLinuxService.config


<configuration>
  <appSettings>

    <!-- 访问agent的Token,保护你服务器安全的 -->
    <add key="Token" value="aaaa"/>
    
    <!-- agent对外提供服务的端口号,在云服务器里面得开放端口不然访问不进来 -->
    <add key="Port" value="8091"/>

    <!--下面的一般保持默认即可 -->
    <!--是否启用备份  true代表备份 false 代表不备份  不填=true  -->
    <add key="NeedBackUp" value="" />

    <!--配置Mac白名单地址列表 多个用半角逗号隔开-->
    <add key="MacWhiteList" value="" />

    <!--配置发布历史最多保留个数(默认10),解释:每次发布就是一个发布历史,回滚的时候是选择这个发布历史进行操作的-->
    <add key="OldPulishLimit" value="10" />

    <!--每个项目的发布版本历史记录会保底留存10个(上面配置的),对于超过的会走日期比对(当前服务器时间-版本批次日期)>10(下面配置) 的发布文件夹会被删除,防止磁盘占用过大 10代表10天 不填默认10-->
    <add key="ClearOldPublishFolderOverDays" value="10" />
    
    <!--发布使用目录 为空代表当前目录 ->
    <add key="DeployDir" value=""/>
  </appSettings>
</configuration>

执行下面命令把AntAgent安装为linux服务运行

sudo cp AntAgent.service /etc/systemd/system/AntAgent.service

sudo systemctl daemon-reload

sudo systemctl enable AntAgent

sudo systemctl start AntAgent


安装成功后使用命令:sudo systemctl status AntAgent
查看是否成功运行

image

好了,以上服务器上agent安装完毕

如果agent已经启动了 再修改agent的配置文件,那你可以用命令

sudo systemctl restart AntAgent 

重新运行agent

为了更方便的在linux服务器上安装agent我写了一个快速安装的脚本(只需要敲一行命令即可安装为agent为服务):

curl https://mysharelist.com/installAgent.sh|sudo sh

image

第二步 安装AntDeploy插件

image

如果下载很慢可以插件市场官网下载下来双击安装:
https://marketplace.visualstudio.com/items?itemName=nainaigu.AntDeployVsix

打开你要发布的工程

工程文件右键可以召唤AntDeploy
如果没有 看下是不是被禁用了
image

第一次发布需要配置服务器的agent信息

  1. 新增一个环境
  2. 在环境下添加Token服务器(就是上面agent的服务器Ip:端口号)

image

进入Linux服务发布

  1. 选择刚刚添加的环境
  2. 录入要发布的服务名称
  3. 点击发布
    image

agent做了什么日志里面详细记录了

image

@yuzd yuzd added the good first issue Good for newcomers label Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant