Ubuntu10.04搭建Git服务器和GitWeb

安装Git服务器:

 

Ubuntu服务器端:

 

第一步: 安装必备软件模块

ivan@ubuntu:~$ sudo apt-get install git-core openssh-server openssl-client python-setuptools

 

第二步:添加git用户用于管理所有代码仓库和用户权限

ivan@ubuntu:~$ sudo useradd -m git

设置git用户密码:

ivan@ubuntu:~$ sudo passwd git

 

第三步: 安装gitosis

ivan@ubuntu:~$ git clone git://eagain.net/gitosis.git

ivan@ubuntu:~$ cd gitosis

ivan@ubuntu:~$python setup.py install

 

第四步: 切换到git用户并创建git仓库目录

ivan@ubuntu:~$ su git
Password:
$ cd ../git
$ ls
examples.desktop
$ pwd
/home/git
$ mkdir sample.git
$ cd sample.git
$ git --bare init
Initialized empty Git repository in /home/git/sample.git/

Git客服端,初始化sample.git仓库:

Administrator@ivan ~
$ mkdir sample

Administrator@ivan ~
$ cd sample

Administrator@ivan ~/sample
$ git init
Initialized empty Git repository in /home/Administrator/sample/.git/

Administrator@ivan ~/sample
$ touch readme

Administrator@ivan ~/sample
$ git add .

Administrator@ivan ~/sample
$ git commit -m "First Commit"
[master (root-commit) d5ba460] First Commit
 Committer: Ivan.Chen <Administrator@ivan.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email [email protected]

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name <[email protected]>'

 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 readme

Administrator@ivan ~/sample
$ git remote add origin [email protected]:sample.git

Administrator@ivan ~/sample
$ git push origin master
The authenticity of host '192.168.1.202 (192.168.1.202)' can't be established.
RSA key fingerprint is 17:b8:f6:c0:15:b2:7e:6a:12:36:1f:5c:cc:a1:5e:04.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.202' (RSA) to the list of known hosts.
[email protected]'s password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 220 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:sample.git
 * [new branch]      master -> master

 

安装GitWeb

第一步: 安装必备软件模块

ivan@ubuntu:~$ sudo apt-get install gitweb apache2

 

第二步:修改gitweb.conf文件中$projectroot值

ivan@ubuntu:~$ sudo vim /etc/gitweb.conf

 

# path to git projects (<project>.git)
$projectroot = "/home/git";

 

第三步:修改git仓库文件夹的权限

ivan@ubuntu:~$ sudo chmod 777 -R /home/git

 

到目前为止gitweb搭建完毕,即可通过浏览器访问http://192.168.1.202:8001/cgi-bin/gitweb.cgi。192.168.1.202是gitweb服务器的IP地址,端口是8001,这里一般默认是80端口,你可以通过修改一下文件

第一步:

ivan@ubuntu:~$ sudo vim /etc/apache2/sites-available/gitserver

 

<VirtualHost *:8001>
        ServerName localhost

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

        <Directory /usr/lib/cgi-bin/>
                Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
                AllowOverride All
                order allow,deny
                Allow from all
                AddHandler cgi-script cgi .pl .py
                DirectoryIndex gitweb.cgi
        </Directory>
</VirtualHost>

 

第二步:修改apache配置文件

ivan@ubuntu:~$ sudo vim /etc/apache2/ports.conf

 

NameVirtualHost *:80
Listen 80

NameVirtualHost *:8001
Listen 8001

重启apache server

ivan@ubuntu:~$ sudo /etc/init.d/apache2 restart

* Restarting web server apache2

... waiting                                                             [ OK ]

你可能感兴趣的:(Ubuntu10.04搭建Git服务器和GitWeb)