git server

来源:互联网 发布:php开源论坛源码 编辑:程序博客网 时间:2024/05/21 17:11
凡  12:21:54
sudo apt-get install openssh-server openssh-client
凡  12:23:47
http://wiki.ubuntu.org.cn/index.php?title=Git%E6%9C%8D%E5%8A%A1%E5%99%A8Gitosis%E5%AE%89%E8%A3%85%E8%AE%BE%E7%BD%AE&variant=zh-hans
凡  16:19:13
http://blog.csdn.net/wirror800/article/details/5189564
凡  16:23:26
    1  ls
    2  ls -a
    3  cd .ssh
    4  cd /home
    5  ls
    6  ssh-keygen -t rsa
    7  ls -a
    8  cd ~
    9  ls -a
   10  sudo apt-get install git-core
   11  sudo useradd -m git
   12  sudo passwd git
   13  sudo mkdir /home/git/repositories
   14  sudo chown git:git /home/git/repositories
   15  sudo chmod 777 /home/git/repositories
   16  git config --global user.name "enlink"
   17  git config --global user.email "enlink@enlink"
   18  sudo apt-get install python-setuptools
   19  cd /tmp
   20  ls
   21  git clone https://github.com/res0nat0r/gitosis.git
   22  cd gitosis/
   23  sudo python setup.py install
   24  cp ~/.ssh/id_rsa.pub /tmp
   25  sudo -H -u git gitosis-init < /tmp/id_rsa.pub
   26  sudo chmod 777 /home/git/repositories/gitosis-admin.git/hooks/post-update
   27  cd ~
   28  cd.ssh
   29  cd .ssh
   30  ls
   31  cat authorized_keys
   32  sudo cat authorized_keys
   33  cd ~
   34  git clone git@192.168.0.107:gitosis-admin.git
   35  cd gitosis-admin/
   36  ls
   37  cd /tmp
   38  ls
   39  sudo -H -u git gitosis-init < /tmp/cyt.pub
   40  sudo chmod 777 /home/git/repositories/gitosis-admin.git/hooks/post-update
   41  cd /home/git
   42  ls
   43  cd re
   44  cd repositories/
   45  ls
   46  cd gitosis-admin.git/
   47  ls
   48  sudo chmod 777 gitosis-admin.git
   49  cd gitosis-admin.git/
   50  ls
   51  cd hook
   52  ls
   53  cd hooks
   54  ls
   55  sudo vi post-update
   56  cd ..
   57  ls
   58  sudo vi gitosis.conf 
   59  cd ~
   60  ls
   61  cd gitosis-admin/
   62  ls
   63  sudo vi gitosis.conf 
   64  cp /tmp/cyt.pub keydir/cyt.pub
   65  cd keydir
   66  ls
   67  cd ..
   68  git add .
   69  git commit -m "add new file and users"
   70  git push origin master
凡  16:28:17
http://wiki.ubuntu.org.cn/index.php?title=Git%E6%9C%8D%E5%8A%A1%E5%99%A8Gitosis%E5%AE%89%E8%A3%85%E8%AE%BE%E7%BD%AE&variant=zh-hans
凡  16:28:59
1、安装 openssh服务器

sudo apt-get install openssh-server openssh-client
2、创建个人公钥和私钥

在默认用户的主目录路径下,运行以下命令,按照提示创建公钥和私钥

ssh-keygen -t rsa
默认生成2048位,如果需要提高安全级别,也可以通过下面的命令创建公钥和私钥

ssh-keygen -t rsa -b 4096
默认情况下,公钥和私钥会保存在~/.ssh目录下,如下所示:

id_rsa  id_rsa.pub  known_hosts
3、安装 git服务器

sudo apt-get install git-core
4、配置 git服务器

创建git服务器管理用户

sudo useradd -m git
sudo passwd git
创建git仓库存储目录

sudo mkdir /home/git/repositories
设置git仓库权限

sudo chown git:git /home/git/repositories
sudo chmod 755 /home/git/repositories
初始化全局设置

git config --global user.name "myname"
git config --global user.email "myname@server"
5、安装python的setup tool

sudo apt-get install python-setuptools
6、获取并安装gitosis

cd /tmp
git clone https://github.com/res0nat0r/gitosis.git
cd gitosis
sudo python setup.py install
7、配置gitosis

cp ~/.ssh/id_rsa.pub /tmp
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
8、管理gitosis配置

cd ~
git clone git@hostname:用户名/gitosis-admin.git
cd gitosis-admin/
各个用户按照前面提到的办法生成各自的ssh公钥文件后,服务器管理员把所有人的 ssh公钥文件都拿来,拷贝到keydir目录下。

修改gitosis.conf文件,如下所示

[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = a@server1
[group developers]
writable = helloworld
members = a@server1 b@server2
[group test] 
readonly = helloworld
members = c@server3
这个配置文件表达了如下含义:gitosis-admin组成员有a,该组对gitosis-admin仓库有读写权限; developers组有a,b两个成员,该组对helloworld仓库有读写权限; test组有c一个成员,对helloworld仓库有只读权限。 当然目前这些配置文件的修改只是在你的本地,你必须推送到gitserver上才能真正生效。 加入新文件、提交并push到git服务器:

git add .
git commit -am "add helloworld project and users"
git remote add origin ssh://git@hostname/helloworld.git
git push origin master
凡  16:29:20
9、安装apache2

sudo apt-get install apache2
10、安装gitweb

sudo apt-get install gitweb
11、配置 gitweb

默认没有 css 加载,把 gitweb 要用的静态文件连接到 DocumentRoot 下:

cd /var/www/
sudo ln -s /usr/share/gitweb/* .
修改配置:

sudo vi /etc/gitweb.conf
将 $projectroot 改为git仓库存储目录(例如:/home/git/repositories),保存后刷新浏览器。


如果没有找到项目,你需要将$projectroot/*.git 的属性改为755,让apache用户有可读权限。可以只改你需要让别人通过web访问的那个git。 http://localhost/cgi-bin/gitweb.cgi


修改/etc/gitweb.conf 内容:

# path to git projects (<project>.git)
#$projectroot = "/var/cache/git";
$projectroot = "/home/git/repositories";
# directory to use for temp files
$git_temp = "/tmp";
# target of the home link on top of all pages
$home_link = $my_uri || "/";
# html text to include at home page
$home_text = "indextext.html";
# file with project list; by default, simply scan the projectroot dir.
$projects_list = $projectroot;
# stylesheet to use
@stylesheets = ("/gitweb/static/gitweb.css");
# javascript code for gitweb
$javascript = "gitweb/static/gitweb.js";
# logo to use
$logo = "/gitweb/static/git-logo.png";
# the 'favicon'
$favicon = "/gitweb/static/git-favicon.png";
# git-diff-tree(1) options to use for generated patches
#@diff_opts = ("-M");
@diff_opts = ();
12、配置apache2

ubuntu中默认的web目录是/var/www,默认的cgi目录是 /usr/lib/cgi-bin/,安装完成gitweb后,gitweb的gitweb.cgi会自动放置到该目录下。

如果你的cgi路径不是默认的/usr/lib/cgi-bin/,需要将gitweb安装在/usr/lib/cgi-bin中的gitweb.cgi复制到原来配置的cgi-bin路径,并在apache的配置文件/etc/apache2/apache.conf末尾加上以下内容:

SetEnv  GITWEB_CONFIG   /etc/gitweb.conf 
<Directory "/srv/www/cgi-bin/gitweb">           
     Options FollowSymlinks ExecCGI          
     Allow from all                          
     AllowOverride all                       
     Order allow,deny                        
     <Files gitweb.cgi> 
          SetHandler cgi-script 
     </Files>                    
     RewriteEngine on 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteRule ^.* /gitweb.cgi/$0 [L,PT] 
</Directory>
重新启动apache:sudo /etc/init.d/apache2 restart,访问http://localhost/cgi-bin/gitweb.cgi 
凡  17:50:59
chown -vR git *

原创粉丝点击