Build a git server on centos

Source: Internet
Author: User
Tags install perl
0. Define three hosts in the example here: localhost is a centos host and git server; Ubuntu is the workstation of the GIT server administrator; Linux is the workstation of Jason, a git user. Localhost indicates that two accounts, test and git, appear on the GIT server. test is an existing account used to build the GIT server, and git is a proprietary account created for the GIT server. Ubuntu is the workstation of the GIT server administrator. The Administrator's account on his workstation is user. Linux is Jason's workstation. Git server: [test @ localhost] [git @ localhost] git administrator: [user @ Ubuntu] git User: [Jason @ Linux] the SSH logon command between hosts and the process of copying the public key using SCP are omitted. Observe the user and host name prompts before the command. 1. Install git
[test@localhost ~]$ sudo yum install git

Check if git is correctly installed

[test@localhost ~]$ git --versiongit version 1.7.1
2. Create a private user for the GIT server and name the user git.
[test@localhost ~]$ sudo useradd git -d /home/git
Finally switch to the GIT user
[test@localhost ~]$ su - git
3. Install gitolite as a git service management tool. It authenticates users through the public key and can use the configuration file for fine-grained repo authorization management. Because it adopts SSH Public Key Authentication, ssh must be installed first.
[test@localhost ~]$ sudo yum install ssh[test@localhost ~]$ sudo service sshd start[test@localhost ~]$ sudo chkconfig sshd on


Then install gitolite. The GIT server administrator needs to prepare his own key pair. Therefore, assume that the Administrator is on his workstation (another Linux host, only to get the Administrator's key, not necessarily on another Linux host, he needs to create his own key pair (for convenience, do not enter passphrase ):

[user@ubuntu ~]$  ssh-keygen -f ~/.ssh/admin

The command is in ~ /. Create the key pairs admin and Admin. pub in the SSH directory. Now return to the GIT server host and copy the created admin. Pub to the Home Directory of the GIT user, that is,/home/git/, and chown is the GIT account. In addition, ensure that no file exists before installation ~ /. Ssh/authorized_keys or the file is empty. Install gitolite:

[git@localhost ~]$ git clone git://github.com/sitaramc/gitolite[git@localhost ~]$ mkdir -p ~/bin[git@localhost ~]$ gitolite/install -to ~/bin[git@localhost ~]$ gitolite setup -pk admin.pub

If an error occurs when executing the third command:

Can't locate time/hires. pm IN @ INC (@ INC contains: /home/git/gitolite/src/lib/usr/local/lib/perl5/usr/local/share/perl5/usr/lib/perl5/vendor_perl/usr/share/perl5 /vendor_perl/usr/lib/perl5/usr/share/perl5 .) at/home/git/gitolite/src/lib/gitolite/Common. PM
Line 76.
Begin failed -- Compilation aborted at/home/git/gitolite/src/lib/gitolite/common. PM line 76.
Compilation failed in require at gitolite/install line 15.
Begin failed -- Compilation aborted at gitolite/install line 15.

The time: hires software is missing from Perl. After installing the software package, run the preceding command again:

[test@localhost ~]$ sudo yum install perl-Time-HiRes

4. now, assume that there is a member named Jason in the team, who puts his public key Jason. the pub sends an email to the administrator asking him to create a repo named Foo. He asks him to modify the repo only by himself. Others cannot modify but can view the repo. First, the administrator needs to obtain the gitolite management Repo On his workstation. the_git_host is the GIT server address just set up by the Administrator:
[user@ubuntu ~]$  git clone git@the_git_host:gitolite-admin

Note: If you are required to enter a password when executing this command, it indicates that some of the preceding configurations are incorrect and you need to verify the password again before proceeding. After cloning, you need to pay attention to two subdirectories: conf and keydir under the./gitolite-Admin directory. Conf is the permission configuration folder of gitolite, and keydir is used to place the public keys of all users. Therefore, you can now put Jason's public key Jason. Pub into the folder keydir. Edit the conf/gitolite. conf file and add a new repo at the end of the file:

repo foo            RW+         =   jason            R           =   @all
Submit the changes to add the user and its database:
[user@ubuntu ~]$  git add conf[user@ubuntu ~]$  git add keydir[user@ubuntu ~]$  git commit -m 'added foo, gave access to jason'[user@ubuntu ~]$   git push
5. Run git version management.
[jason@linux ~]$   git clone git@the_git_host:foo


After the command is executed, create an empty database Foo. Now Jason can perform version management and submit it as needed. If you want to query all repo that you have the permission to access, you can use the following command to query:

[jason@linux ~]$ ssh git@the_git_host  info
Note: from step 1, you need to enter a password to log on to the GIT server using SSH or git anywhere. It indicates that the GIT server is configured incorrectly and you need to reinstall gitolite, clear the previous files before re-installation:
[git@localhost ~]$ ls -a | grep gitolite | xargs rm -fr[git@localhost ~]$ rm -fr ~/repositories ~/bin  ~/projects.list ~/.ssh/authorized_keys

6. Configure gitweb. If you want to access the GIT repository on the web page, you can use gitweb.

[test@localhost ~]$ sudo yum install gitweb

Open the/etc/gitweb. conf file, add the projectroot variable according to the annotation format, and point to the GIT Library:

our  $projectroot = "/home/git/repositories";our @git_base_url_list = qw(git://git.the_git_host                            ssh://git.the_git_host/var/lib/git);

Finally, edit the Apache server configuration file/etc/httpd/CONF/httpd. conf and add the following at the end of the article:

<VirtualHost *:80>    ServerName the_git_host    DocumentRoot /var/www/git    <Directory /var/www/git>        Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch        AllowOverride All        order allow,deny        Allow from all        AddHandler cgi-script cgi        DirectoryIndex gitweb.cgi    </Directory></VirtualHost>

Finally, modify the permissions of the GIT database. Otherwise, the 404 no projects found error will occur. Finally, restart the Apache server:

[test@localhost ~]$ sudo chmod 775 /home/git/repositories[test@localhost ~]$ sudo chmod 775 /home/git[test@localhost ~]$ sudo apachectl restart

Finally, enter http: // the_git_host in the browser to view the GIT library. I tested it on the local machine and used http: // localhost.

NOTE: If 404 no project found is still displayed after completing the preceding operations, SELinux may be troublesome. Try to change the SELinux status to permissive and then refresh the page:

[test@localhost ~]$ sudo setenforce 0
7. References 1. gitolite2.gitweb

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.