git 服务器搭建 (git smart http)

服务器 UBUNTU 11.04 (写了一下操作步骤, 理论网上找吧, 我也说不清楚, 呵)


(FIXME: 服务器上操作)


1. 更新当前系统

rdserver@server249:~/Desktop$ sudo apt-get update

rdserver@server249:~/Desktop$ sudo apt-get upgrade

2. 安装 OpenSSH

检查本机上是否已经运行ssh服务
rdserver@server249:~/Desktop$ ps -e | grep ssh


如果没有, 则安装
rdserver@server249:~/Desktop$ sudo apt-get install openssh-server openssh-client


3. 安装 git 

rdserver@server249:~/Desktop$ sudo apt-get install git-core

4. 建立空仓库

rdserver@server249:/home$ sudo mkdir /home/repo
rdserver@server249:/home$ sudo mkdir /home/repo/cold.git
rdserver@server249:/home$ cd /home/repo/cold.git/
rdserver@server249:/home/repo/cold.git$ sudo git init --bare

5. 更改仓库顶层目录权限,适用与 http协议操作
 
rdserver@server249:/home$ sudo chown -R www-data:www-data /home/repo/

6. 安装gitweb


rdserver@server249:~/Desktop$ sudo apt-get install gitweb


rdserver@server249:/$ sudo vi /etc/apache2/sites-available/default


{[



        ServerAdmin webmaster@localhost


        DocumentRoot /var/www
       
                Options FollowSymLinks
                AllowOverride None
       

       
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
       



        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
       
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all

       

       # Git configuration
        SetEnv GIT_PROJECT_ROOT /home/repo
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

        # This pattern matches git operations and passes them to http-backend
        ScriptAliasMatch \
                "(?x)^/git/(.*/(HEAD | \
                        info/refs | \
                        objects/(info/[^/]+ | \
                                [0-9a-f]{2}/[0-9a-f]{38} | \
                                pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                                git-(upload|receive)-pack))$" \
        /usr/lib/git-core/git-http-backend/$1

        # Anything not matched above goes to displayable gitweb interface
        ScriptAlias /git /usr/share/gitweb/gitweb.cgi/

        # Git repository # Read-Only
       
                #Write access
                AuthType Basic
                AuthName "git repository"
                AuthUserFile /etc/apache2/gitAuth/Authfile
                Require valid-user
       


        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

        Alias /doc/ "/usr/share/doc/"
       
                Options Indexes MultiViews FollowSymLinks
                AllowOverride None
                Order deny,allow
                Deny from all
                Allow from 127.0.0.0/255.0.0.0 ::1/128
       




]}


rdserver@server249:/$ sudo vi /etc/gitweb.conf

{[

# path to git projects (.git)
$projectroot = "/home/repo";

# 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
$stylesheet = "/gitweb/gitweb.css";

# logo to use
$logo = "/gitweb/git-logo.png";

# the 'favicon'
$favicon = "/gitweb/git-favicon.png";

]}


(FIXME: 客户端上操作)
8. zhang@zhang:~/Desktop/xxx$ git clone http://192.168.0.249/git/cold.git 
Cloning into cold...
warning: You appear to have cloned an empty repository.


(FIXME: 服务器上操作)
9. 建立私有目录, 具有读写权限 

rdserver@server249:/home/repo$ sudo mkdir private

10. 在 private 目录下建立仓库链接,提供用户读写访问

rdserver@server249:/home/repo/private$ sudo ln -s ../cold.git/ cold.git

11. rdserver@server249:/home$ sudo vi /etc/apache2/sites-available/default

    rdserver@server249:/home$ sudo service apache2 restart (修改了default后,都需要重启apache)


        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
       
                Options FollowSymLinks
                AllowOverride None
       

       
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
       


        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
       
                AllowOverride None
                #Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Options +ExecCGI -Includes
                Order allow,deny
                Allow from all
       


       # Git configuration
        SetEnv GIT_PROJECT_ROOT /home/repo
        SetEnv GIT_HTTP_EXPORT_ALL
        SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER

        # This pattern matches git operations and passes them to http-backend
        ScriptAliasMatch \
                "(?x)^/git/(.*/(HEAD | \
                        info/refs | \
                        objects/(info/[^/]+ | \
                                [0-9a-f]{2}/[0-9a-f]{38} | \
                                pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                                git-(upload|receive)-pack))$" \
        /usr/lib/git-core/git-http-backend/$1

        # Anything not matched above goes to displayable gitweb interface
        ScriptAlias /git/ /usr/share/gitweb/gitweb.cgi/

        # Git repository #Read-Only and Read-Write
       
                #Write access
                AuthType Basic
                AuthName "git repository"
                AuthUserFile /etc/apache2/gitAuth/Authfile
                Require valid-user
       

       
                AuthType Basic
                AuthName "git repository"
                AuthUserFile /etc/apache2/gitAuth/Authfile
                Require valid-user
       


        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

        Alias /doc/ "/usr/share/doc/"
       
                Options Indexes MultiViews FollowSymLinks
                AllowOverride None
                Order deny,allow
                Deny from all
                Allow from 127.0.0.0/255.0.0.0 ::1/128
   



{ //鉴权文件 /etc/apache2/gitAuth/Authfile

rdserver@server249:/etc/apache2/gitAuth$ sudo htpasswd -cmb Authfile zhang 123
Adding password for user zhang

rdserver@server249:/etc/apache2/gitAuth$ sudo htpasswd -mb Authfile dala 123
Adding password for user dala

}


(FIXME: 客户端上操作)
12. 下载具有读写权限的仓库

zhang@zhang:~/Desktop/xxx$ git clone http://192.168.0.249/git/private/cold.git
Cloning into cold...
Username: 
Password: 
warning: You appear to have cloned an empty repository.

13. 向空仓库中添加文件 

zhang@zhang:~/Desktop/xxx$ cd cold/
zhang@zhang:~/Desktop/xxx/cold$ echo "Hello World" > ReadMe (添加文件ReadMe)

zhang@zhang:~/Desktop/xxx/cold$ git add .
zhang@zhang:~/Desktop/xxx/cold$ git commit -m "add file 'ReadMe'"
zhang@zhang:~/Desktop/xxx/cold$ git push origin master

14. 测试只读下载

zhang@zhang:~/Desktop/xxx$ git clone http://192.168.0.249/git/cold.git
Cloning into cold...
remote: Counting objects: 3, done.

remote: Total 3 (delta 0), reused 0 (delta 0)


15. 完, 哈


你可能感兴趣的:(杂项)