git2consul+consul+gitlab连接

时间:2024-04-01 17:18:35

前提:安装好了gitlab和部署好了consul集群。使用git2consul连接持续检测gitlab仓库变化。
提交相关配置到gitlab中->git2consul连接gitlab,得到变化的配置 -> git2consul将变化的配置同步到consul中->后端服务器从consul中的key/value中得到变化的配置
1、git2consul安装

yum install epel-release -y
yum install -y nodejs
yum install npm -y
npm install git2consul
mkdir -pv /etc/git2consul/
cd /etc/git2consul/
vim  config.json
cat config.json  #配置文件指定了git2consul需要监控的git仓库地址、分支、
#前提:安装好了gitlab并且创建了项目
{
  "version": "1.0",
  "repos" : [{
    "name" : "git", # conul中的key/value中的文件名
    "url" : "http://root:12345@192.168.50.156/root/class-test-yin.git",  #这个root是在gitlab中可以改变的
    "include_branch_name": false,
    "branches" : ["main"],#哪个分支
    "hooks": [{
      "type" : "polling",
      "interval" : "1"
    }]
  }]
}

cat  /etc/systemd/system/git2consul.service
[Unit]
Description=git2consul
After=network.target
[Service]
Type=simple
#User=git2consul
#Group=git2consul
#WorkingDirectory=/app/git2consul
ExecStart=/usr/local/bin/git2consul --endpoint 192.168.70.64 --port 8500 --config-file /etc/git2consul/config.json
TimeoutStopSec=59
[Install]
WantedBy=multi-user.target

启动git2consul后,不需要手动的去consul中添加key/value,会自动的导入

2、后端服务器相关配置

[root@first-1 class-assistant-linux-production]# cat appsettings.Production.json 
{
  "ConsulForConfig": {
    "Host": "http://192.168.70.64:8500",
    "Prefix": "git/class-assistant/common"  #指定consul图形界面中配置文件的位置
  }
}

3、supervisor使用

[root@first-1 supervisord.d]# cat classAssistant.ini 
[program:core-class-assistant-linux-production]
command=/bin/bash -c "dotnet ClassAssistant.Apis.dll --urls http://*:260 --virtualPath=/class-assistant"
directory=/opt/class-assistant-linux-production
stderr_logfile=/var/log/classAssistant-production.error.log
stdout_logfile=/var/log/classAssistant-production.stdout.log
environment=DOTNET_ENVIRONMENT=Production,DISPLAY=:1
user=root
stopsignal=INT
autostart=true
autorestart=true
startsecs=3
yum install supervisor -y
vim /etc/supervisord.d/classAssistant.ini 
systemctl start supervisor
supervisorctl status

4、dotnet安装

rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
yum install dotnet-sdk-6.0 -y
yum install aspnetcore-runtime-6.0  -y
yum install dotnet-runtime-6.0  -y