Heim  >  Fragen und Antworten  >  Hauptteil

linux - Kann Git Post-Receive Hook Git Pull auf mehreren Servern ausführen?

Umweltbeschreibung

  1. bei 服务器A/home/work/目录下创建了仓库/home/work/my-project.git

  2. wird/home/work/my-project.git克隆到网站根目录/home/www/

  3. Konfiguriertgit post-receive hook

#!/bin/bash

cd /home/www
env -i git pull

Hier entlang jedes Mal git push的时候,都可以把代码更新到服务器A/home/wwwunter dem Verzeichnis

Problembeschreibung

Was ist, wenn ich operiere? 服务器B也克隆了/home/work/my-project.git到目录/home/www/下。有没有什么办法每次执行git push的时候,同时到服务器A服务器B执行git pull

Mein aktueller Ansatz ist

effektiv, aber es gibt auch einen Zeitunterschied. 服务器B上加一个crontab定时任务,每分钟到/home/www/目录下执行一下git pull,这样虽然也可以达到自动git push

Haben Sie bessere Vorgehensweisen?

巴扎黑巴扎黑2713 Tage vor556

Antworte allen(1)Ich werde antworten

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:24:18

    如果服务器A能通过ssh访问服务器B, 可以在git post-receive hook中添加一行

    rsync -az -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" /home/www/ <服务器B的IP>:/home/www/

    每次git push之后,服务器A将/home/work/my-project.git克隆到网站根目录/home/www/的同时,会通过rsync
    将/home/www/同步到服务器B的/home/www/

    Antwort
    0
  • StornierenAntwort