1、将sinovo添加到管理组

进入root

[root@git-server ~]vim /etc/sudoers

添加 sinovo  ALL=(ALL)       ALL

image.png

2、先安装git

   [sinovo@git-server ~]$ sudo yum install git-core

3、创建个人秘钥

    [sinovo@git-server ~]ssh-keygen -t rsa

4、安装python的setup tool 

[sinovo@git-server ~]$ sudo yum install python-setuptools

5、获取并安装gitosis

[sinovo@git-server ~]$ git clone git://github.com/res0nat0r/gitosis.git

[sinovo@git-server ~]$ cd gitosis

[sinovo@git-server gitosis]$ sudo python setup.py install

6、配置 git服务器

   创建git服务器管理用户

    [sinovo@git-server ~]$ sudo useradd -m git

    [sinovo@git-server ~]$ sudo passwd git

7、gitosis默认所有git工程都放在/home/git/repositories/下。为防止gitosis崩溃的影响,将/home/gitpot作为所有git工程的根目录,今后删除git用户时不会波及这些工程。

[sinovo@git-server ~]$ sudo mkdir /home/gitpot

[sinovo@git-server ~]$ sudo chown git.git -R /home/gitpot/

[sinovo@git-server ~]$ ls /home/ -l

将git gitopt sinovo权限改为755


8、初始化全局设置然后以git身份,建立/home/git/repositories为指向/home/gitpot的超级链接

[sinovo@git-server ~]$ su git

[git@git-server ~]$ git config --global user.name "gitadmin"

[git@git-server ~]$ git config --global user.email "gitadmin@sinovo-tech.com"

[git@git-server ~]$ ln -s /home/gitpot ./repositories

[git@git-server ~]$ ls -al

[git@git-server ~]$ exit

exit

[sinovo@git-server ~]$

9、配置gitosis

[sinovo@git-server ~]$ cp ~/.ssh/id_rsa.pub /tmp/gitadmin@133.pub

[sinovo@git-server ~]$ cat /tmp/gitadmin@133.pub

[sinovo@git-server ~]$ cd /tmp

[sinovo@git-server tmp]$ sudo -H -u git gitosis-init < /tmp/gitadmin\@133.pub

[sinovo@git-server tmp]$ cd

[sinovo@git-server ~]$  git clone git@localhost:gitosis-admin.git

[sinovo@git-server ~]$ cd gitosis-admin

[sinovo@git-server gitosis-admin]$ ll -al

[sinovo@git-server gitosis-admin]$ cat gitosis.conf


将客户端的key上传至服务器端,并生成为用户可以

[sinovo@git-server gitosis-admin]$ cat pdf@242.pub

[sinovo@git-server gitosis-admin]$ cp pdf\@242.pub keydir/pdf@pdf-client.pub

[sinovo@git-server gitosis-admin]$ vi gitosis.conf

image.png

[sinovo@git-server gitosis-admin]$ rm -rf pdf@242.pub

[sinovo@git-server gitosis-admin]$ git status

[sinovo@git-server gitosis-admin]$ git add gitosis.conf

[sinovo@git-server gitosis-admin]$ git add keydir/pdf\@pdf-client.pub

[sinovo@git-server gitosis-admin]$ git config --global user.name gitadmin

[sinovo@git-server gitosis-admin]$ git config --global user.email gitadmin@sinovo-tech.com

[sinovo@git-server gitosis-admin]$ git commit -m "Add test-git project."

[sinovo@git-server gitosis-admin]$ git log

[sinovo@git-server gitosis-admin]$ git remote -v

[sinovo@git-server gitosis-admin]$ git branch -a

[sinovo@git-server gitosis-admin]$ git log

[sinovo@git-server gitosis-admin]$ git push origin master

[sinovo@git-server ~]$ su git

密码:

[git@git-server sinovo]$ cd

[git@git-server ~]$ ls

gitosis  repositories

[git@git-server ~]$ ls repositories/

gitosis-admin.git

[git@git-server ~]$ cd repositories/

[git@git-server repositories]$ mkdir test-git.git

[git@git-server repositories]$ cd test-git.git/

[git@git-server test-git.git]$ git init --bare

Initialized empty Git repository in /home/gitpot/test-git.git/

下一步客户端与服务器创建分支操作请参考ubunut安装步骤





安装apache

[sinovo@git-server ~]$ sudo yum install -y httpd

配置apache

在文件尾部添加 ServerName localhost:80

[sinovo@git-server ~]$ sudo vim /etc/httpd/conf/httpd.conf

配置防火墙允许80端口访问

在文件内添加-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

[sinovo@git-server ~]$ sudo vim /etc/sysconfig/iptables

重启防火墙及apache

[sinovo@git-server ~]$ sudo service iptables restart

[sinovo@git-server ~]$ sudo service httpd restart


gitweb安装

    注意:redhat的iso源是没有gitweb安装包,但是centos的源中有,在上一篇文章中给出了如何让redhat使用centos的源,那么,只需采用如下命令即可安装。

  1. [sinovo@git-server ~]$ sudo yum install gitweb


2. gitweb配置

  gitweb默认安装到了/var/www/git下,其配置文件在/etc/gitweb.conf下,另外,httpd的配置文件/etc/httpd/conf.d/git.conf。

(1)修改/etc/gitweb.conf

  1. 将projectroot修改为/home/gitpot

  2. [sinovo@git-server ~]$ sudo vim /etc/gitweb.conf

    image.png


(2)修改/etc/httpd/conf.d/httpd.conf

     [sinovo@git-server ~]$ sudo vim /etc/httpd/conf/httpd.conf   

  1. <VirtualHost *:80>

  2.     ServerName gitserver

  3.     DocumentRoot /var/www/html

  4.     <Directory /var/www/html/gitweb >

  5.         Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch

  6.         AllowOverride All

  7.         order allow,deny

  8.         Allow from all

  9.         AddHandler cgi-script cgi

  10.         DirectoryIndex gitweb.cgi

  11.     </Directory>

  12. </VirtualHost>

    image.png

  (3)[sinovo@git-server ~]$ sudo ln -s /var/www/git  /var/www/html/gitweb

    

(4)重启httpd

  1. [sinovo@git-server ~]$ sudo /etc/init.d/httpd restart


如果web显示404请按以下操作

关闭RELinux服务


查看SELinux状态:

[sinovo@git-server ~]$ /usr/sbin/sestatus -v

1、/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态

SELinux status:                 enabled

2、getenforce                 ##也可以用这个命令检查

[sinovo@git-server ~]$ getenforce

关闭SELinux:

1、临时关闭(不用重启机器):

setenforce 0                  ##设置SELinux 成为permissive模式

                              ##setenforce 1 设置SELinux 成为enforcing模式

[sinovo@git-server ~]$ sudo setenforce 0

2、修改配置文件需要重启机器:

修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

重启机器即可