阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

搭建无限制权限的简单Git服务器使用git-daemon脚本

157次阅读
没有评论

共计 5531 个字符,预计需要花费 14 分钟才能阅读完成。

如果想要用 Ubuntu 架设无限制权限(即不适用 gitosis)的简单 git 服务器,实现 git 库下载 clone,push 等简单的基本功能,可以直接使用 git-daemon 脚本(非常不安全,建议项目代码的 git 管理不要使用!)

本地安装完 sudo apt-get install git git-core 之后没有安装 git-daemon-run 或者 git-daemon-sysvinit 时,可以执行如下操作:

sudo vi /etc/init.d/git-daemon

=============CP 下面的代码复制过去, 修改下 base-path 和 user=============

#! /bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

NAME=git-daemon
PIDFILE=/var/run/$NAME.pid
DESC=”the git daemon”
DAEMON=/usr/lib/git-core/git-daemon
DAEMON_OPTS=”–base-path=/home/dongwuming/git –enable=receive-pack –export-all –verbose –syslog –detach –pid-file=$PIDFILE –user=dongwuming –group=nogroup”

test -x $DAEMON || exit 0

[-r /etc/default/git-daemon] && . /etc/default/git-daemon

. /lib/lsb/init-functions

start_git() {
  start-stop-daemon –start –quiet –pidfile $PIDFILE \
    –startas $DAEMON — $DAEMON_OPTS
}

stop_git() {
  start-stop-daemon –stop –quiet –pidfile $PIDFILE
  rm -f $PIDFILE
}

status_git() {
  start-stop-daemon –stop –test –quiet –pidfile $PIDFILE >/dev/null 2>&1
}

case “$1” in
  start)
  log_begin_msg “Starting $DESC”
  start_git
  log_end_msg 0
  ;;
  stop)
  log_begin_msg “Stopping $DESC”
  stop_git
  log_end_msg 0
  ;;
  status)
  log_begin_msg “Testing $DESC: “
  if status_git
  then
    log_success_msg “Running”
    exit 0
  else
    log_failure_msg “Not running”
    exit 1
  fi
  ;;
  restart|force-reload)
  log_begin_msg “Restarting $DESC”
  stop_git
  sleep 1
  start_git
  log_end_msg 0

  ;;
  *)
  echo “Usage: $0 {start|stop|restart|force-reload|status}” >&2
  exit 1
  ;;
esac

exit 0

=============:wq! 保存退出 =============

sudo chmod 777  /etc/init.d/git-daemon

sudo /etc/init.d/git-daemon stop
sudo /etc/init.d/git-daemon start

ps -ef | grep git-daemon
1000      6100    1  0 17:01 ?        00:00:00 /usr/lib/git-core/git-daemon –base-path=/home/dongwuming/git –enable=receive-pack –export-all –verbose –syslog –detach –pid-file=/var/run/git-daemon.pid –user=dongwuming –group=nogroup
1000      6243 17377  0 17:29 pts/2    00:00:00 grep –color=auto git-daemon

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2013-11/92233p2.htm

Git 的详细介绍 :请点这里
Git 的下载地址 :请点这里

推荐阅读

Fedora 通过 Http Proxy 下载 Git http://www.linuxidc.com/Linux/2009-12/23170.htm

在 Ubuntu Server 上安装 Git http://www.linuxidc.com/Linux/2009-06/20421.htm

服务器端 Git 仓库的创建(Ubuntu)http://www.linuxidc.com/Linux/2011-02/32542.htm

Linux 下 Git 简单使用教程(以 Android 为例)http://www.linuxidc.com/Linux/2010-11/29883.htm

Git 权威指南 PDF 高清中文版 http://www.linuxidc.com/Linux/2013-10/91053.htm

OK 用另外一台局域网的机器

git clone git://192.168.xx.xx/your-bare-or-mirror-git-repositories【建库的时候一定要是一个 bare 赤裸的或者 mirror 镜像的 git 库】

cd your-bare-or-mirror-git-repositories

vi test

just a test!

git add.;git commit -m “just a test”

git push origin HEAD:master

Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git://192.168.50.125/test
  6ca6f70..9b97ad9  master -> master

OK 了

git-daemon 中控制用户可以 PUSH 的权限的参数为:

–enable=receive-pack

========================Ubuntu sudo apt-gt install git-daemon========================

直接下载 git-daemon 来管理 git

$apt-get install git git-core git-daemon-run

 

 配置 git-daemon-run

$vi /etc/sv/git-daemon/run

====================

#!/bin/sh
exec 2>&1
echo ‘git-daemon starting.’
exec chpst -m64000000 /

git-daemon –verbose –base-path=/var/cache/git /var/cache/git –enable=receive-pack –export-all –verbose –syslog –detach【根据个人需求修改配置】

启动 git-daemon

$sudo sv stop git-daemon

$sudo sv start git-daemon

更多 Ubuntu 相关信息见 Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

如果想要用 Ubuntu 架设无限制权限(即不适用 gitosis)的简单 git 服务器,实现 git 库下载 clone,push 等简单的基本功能,可以直接使用 git-daemon 脚本(非常不安全,建议项目代码的 git 管理不要使用!)

本地安装完 sudo apt-get install git git-core 之后没有安装 git-daemon-run 或者 git-daemon-sysvinit 时,可以执行如下操作:

sudo vi /etc/init.d/git-daemon

=============CP 下面的代码复制过去, 修改下 base-path 和 user=============

#! /bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

NAME=git-daemon
PIDFILE=/var/run/$NAME.pid
DESC=”the git daemon”
DAEMON=/usr/lib/git-core/git-daemon
DAEMON_OPTS=”–base-path=/home/dongwuming/git –enable=receive-pack –export-all –verbose –syslog –detach –pid-file=$PIDFILE –user=dongwuming –group=nogroup”

test -x $DAEMON || exit 0

[-r /etc/default/git-daemon] && . /etc/default/git-daemon

. /lib/lsb/init-functions

start_git() {
  start-stop-daemon –start –quiet –pidfile $PIDFILE \
    –startas $DAEMON — $DAEMON_OPTS
}

stop_git() {
  start-stop-daemon –stop –quiet –pidfile $PIDFILE
  rm -f $PIDFILE
}

status_git() {
  start-stop-daemon –stop –test –quiet –pidfile $PIDFILE >/dev/null 2>&1
}

case “$1” in
  start)
  log_begin_msg “Starting $DESC”
  start_git
  log_end_msg 0
  ;;
  stop)
  log_begin_msg “Stopping $DESC”
  stop_git
  log_end_msg 0
  ;;
  status)
  log_begin_msg “Testing $DESC: “
  if status_git
  then
    log_success_msg “Running”
    exit 0
  else
    log_failure_msg “Not running”
    exit 1
  fi
  ;;
  restart|force-reload)
  log_begin_msg “Restarting $DESC”
  stop_git
  sleep 1
  start_git
  log_end_msg 0

  ;;
  *)
  echo “Usage: $0 {start|stop|restart|force-reload|status}” >&2
  exit 1
  ;;
esac

exit 0

=============:wq! 保存退出 =============

sudo chmod 777  /etc/init.d/git-daemon

sudo /etc/init.d/git-daemon stop
sudo /etc/init.d/git-daemon start

ps -ef | grep git-daemon
1000      6100    1  0 17:01 ?        00:00:00 /usr/lib/git-core/git-daemon –base-path=/home/dongwuming/git –enable=receive-pack –export-all –verbose –syslog –detach –pid-file=/var/run/git-daemon.pid –user=dongwuming –group=nogroup
1000      6243 17377  0 17:29 pts/2    00:00:00 grep –color=auto git-daemon

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2013-11/92233p2.htm

Git 的详细介绍 :请点这里
Git 的下载地址 :请点这里

推荐阅读

Fedora 通过 Http Proxy 下载 Git http://www.linuxidc.com/Linux/2009-12/23170.htm

在 Ubuntu Server 上安装 Git http://www.linuxidc.com/Linux/2009-06/20421.htm

服务器端 Git 仓库的创建(Ubuntu)http://www.linuxidc.com/Linux/2011-02/32542.htm

Linux 下 Git 简单使用教程(以 Android 为例)http://www.linuxidc.com/Linux/2010-11/29883.htm

Git 权威指南 PDF 高清中文版 http://www.linuxidc.com/Linux/2013-10/91053.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计5531字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中