Install apache2 by configuring the GIT server on Ubuntu

Source: Internet
Author: User

 

Configure the GIT server on Ubuntu

Over the past few days, I have been tossing over the GIT version management server. I feel a little too large, and I don't have enough permissions. The encrypted file does not match the user name ......

However, this afternoon has always been an effective task. I will record the errors I have encountered over the past few days and give them a reference!

Today, I modified the log again, mainly to solve the gitweb display problem, and the new member cannot clone the GIT repository!

1 Requirement

Hardware requirements: A Ubuntu or Debian computer (Virtual Machine) can be accessed through the network.

Software requirements: Git-core, gitosis, OpenSSH-server, OpenSSH-Client

2. install and configure the GIT Server

Install git and OpenSSH:

A @ server :~ $ Sudo apt-Get install Git-core openssh-server openssh-Client

The newly added git user will act as the administrator of all code repositories and user permissions:

A @ server :~ $ Sudo useradd-M git

A @ server :~ $ Sudo passwd git

Create a git repository storage point:

A @ server :~ $ Sudo mkdir/home/Repo

So that users except git do not have any permissions on this directory:

A @ server :~ $ Sudo chown git: git/home/Repo

A @ server :~ $ Sudo chmod 755/home/repo Note: Set the repo attribute of the GIT repository to 755. Otherwise, the project cannot be found in gitweb.

3. install and configure gitosis

Initialize the GIT user on the server. This step is actually in preparation for installing gitosis. To use git on any machine, you must initialize it for the first time:

A @ server :~ $ Git config-global user. name "myname"

A @ server :~ $ Git config-global user. Email "myname @ server"

Install the python setup tool to prepare for gitosis:

A @ server :~ $ Sudo apt-Get install Python-setuptools

Get the gitosis package:

A @ server :~ $ CD/tmp

A @ server:/tmp $ git clone git: // eagain.net/gitosis.git

A @ server:/tmp $ CD gitosis

A @ server:/tmp/gitosis $ sudo Python setup. py install

Switch to the GIT User:

A @ server:/tmp/gitosis $ su git

By default, gitosis stores the GIT repository in the home of the GIT user, so we do a link to/home/repo.

$ Ln-S/home/repo/home/git/Repositories

Return to default user again

$ Exit

If you will be the administrator of the GIT server, generate an SSH public key on your computer (another PC:

USR @ pC1 :~ $ Ssh-keygen-T RSA

Copy the public key to/tmp on the server:

USR @ pC1 :~ $ SCP. Ssh/id_rsa.pub git @ <Server>:/tmp

Go back to the GIT Server

A @ server:/tmp/gitosis $ sudo chmod A + R/tmp/id_rsa.pub

Run gitosis:

A @ server:/tmp/gitosis $ Sudo-H-u git gitosis-init </tmp/id_rsa.pub

Initialized empty git repository in/home/repo/gitosis-admin.git/

Reinitialized existing git repository in/home/repo/gitosis-admin.git/

The interesting thing about gitosis is that it manages the configuration file through a git repository and stores it in/home/repo/gitosis-Admin. Git. We need to add executable permissions to a file:

A @ server:/home/git $ sudo passwd Root

A @ server:/home/git $ su

Root @ server:/home/git # cd Repositories

Root @ server:/home/git/repositories # gitosis-admin.git/CD/

Root @ server:/home/git/repositories/gitosis-admin.git # sudo chmod 755/home/repo/gitosis-admin.git/hooks/post-Update

Root @ server:/home/git/repositories/gitosis-admin.git # exit

4. Create a new test project warehouse on the server

We create an empty project warehouse on the server, called "teamwork ".

Switch to git User:

A @ server:/home/git $ su-Git

$ CD/home/Repo

$ Mkdir teamwork. Git

$ CD teamwork. Git

$ Git init--bare Note: This is run on the server to initialize a root-level git repository.

$ Exit

However, as of now, this is only an empty warehouse, which cannot be cloned. To clone a database, you must first release an initialized version to the repository.

Therefore, we must first modify gitosis-Admin.

5. Manage gitosis configuration files

As mentioned above, the gitosis configuration is also implemented through git. In your own development machine, clone the gitosis-admin.git warehouse, you can modify the configuration as administrator.

In your computer:

USR @ pC1 :~ /Work $ git clone git @: gitosis-admin.git

USR @ pC1 :~ /Work $ CD gitosis-admin/

The keydir directory under this directory is used to store the SSH public keys of all users who need to access the GIT server:

Each user generates their own SSH public key file according to the method mentioned above, takes all the SSH Public Key Files and names them by name, such as B. pub, LZ. pub and so on, all copies to the keydir:

USR @ pC1 :~ /Work/gitosis-ADMIN $ su Root

Root @ pC1:/home/A/work/gitosis-Admin # cp/path/to/. Ssh/id_rsa.pub./keydir/B. Pub

Root @ pC1:/home/A/work/gitosis-Admin # exit

Modify the gitosis. conf file. My configuration is roughly as follows:

[Gitosis]

[Group gitosis-admin]

Writable = gitosis-Admin

Members = A @ server USR @ pC1

[Group Hello]

Writable = teamwork

Members = A @ server B

[Group hello_ro]

Readonly = teamwork

Members = LZ

This configuration file expresses the following meanings: Members of the gitosis-Admin group have a and USR, which have read and write permissions on the gitosis-Admin warehouse;

The team group has two members, A and B. This group has read and write permissions on the teamwork warehouse;

The team_ro group has an LZ member and has read-only permissions on the teamwork warehouse.

Of course, the modifications to these configuration files are only made locally. You must push them to the remote gitserver to make the changes take effect.

Add new files, submit and push them to the GIT Server:

USR @ pC1 :~ /Work/gitosis-ADMIN $ git add.

USR @ pC1 :~ /Work/gitosis-ADMIN $ git commit-am "add teamweok prj and users"

USR @ pC1 :~ /Work/gitosis-ADMIN $ git push origin master

6. initialize the test project.

Now the server has been built up, and there is an empty project teamwork on the server. What about next? Of course it is a test. empty warehouse cannot be cloned, so a person with write permission needs to initialize a version. Let me do it. The following is done on the client.

USR @ pC1 :~ /Work $ mkdir teamwork-Ori

USR @ pC1 :~ /Work $ CD teamwork-Ori/

USR @ pC1 :~ /Work/teamwork-Ori $ git init Note: This is executed on the client PC, In order to initialize a local version Library

USR @ pC1 :~ /Work/teamwork-Ori $ echo "/* add something */"> hello

USR @ pC1 :~ /Work/teamwork-Ori $ git add.

USR @ pC1 :~ /Work/teamwork-Ori $ git commit-am "initial version"

USR @ pC1 :~ /Work/teamwork-Ori $ git remote add origin git @ <Server>: Teamwork. Git

USR @ pC1 :~ /Work/teamwork-Ori $ git push origin master

So far, teamwork already has a version. Other team members only need to clone the teamwork warehouse first, and they can play with it at will.

USR @ pC1 :~ /Work/teamwork-Ori $ su B

$ CD/home/B

$ Git clone git @ <Server>: Teamwork. Git

$ CD teamwork

$ Vim hello

$ Git add.

$ Git commit-am "B add"

$ Git push origin master

$ Exit

7. Add an existing git Project

In addition, if you have a ready-made git repository and want to put it on the gitserver for use by the Team (for example, you clone an official kernel repository and want to use it as the basic repository internally), what should you do.

First, you need to get a pure Repository from your work warehouse. For example, your work directory is ~ /Kernel: You want to export the pure repository to your USB flash drive and copy it to gitserver.

$ Git clone-bare ~ /Kernel/Media/udisk

Then, take the USB flash drive and hand it to the gitserver administrator to copy it to/home/repo/and configure the gitosis configuration file. For example, download the Alsa Library:

Git clone git: // android.git.kernel.org/platform/external/alsa-lib.git

Git clone git: // android.git.kernel.org/platform/external/alsa-utils.git

Generate the bare Library

Git clone-bare ALSA-lib alsa-lib.git

Git clone-bare ALSA-utils alsa-utils.git

Move the bare Library to the GIT Server Directory

CP alsa-lib.git/home/Repo

Change the owner to obtain the submission permission.

Chown-r GitHub alsa-lib.git

Then it's O, huh, huh.

8. Create gitweb

Sudo apt-Get install gitweb

If apache2 is not installed, run

Sudo apt-Get install apache2

8.1 configure gitweb

By default, no CSS is loaded. Connect the static files used by gitweb to DocumentRoot:

CD/var/www/

Sudo ln-S/usr/share/gitweb /*.

8.2 modify configuration

Sudo VI/etc/gitweb. conf

Change $ projectroot to the GIT repository storage directory (for example,/home/git/repositories) and refresh the browser.

If no project is found, you need to change the $ projectroot/*. Git attribute to 755 so that Apache users have the permission to read. You can only change the git that you want others to access through the Web. Http: // localhost/cgi-bin/gitweb. cgi

8.3 Modify/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 'favicons'

$ Favicon = "/gitweb/ static/git-favicon.png ";

# Git-diff-tree (1) options to use for generated Patches

# @ Diff_opts = ("-M ");

@ Diff_opts = ();

8.4 configure apache2

The default web directory in Ubuntu is/var/WWW, and the default CGI directory is/usr/lib/cgi-bin/. After gitweb is installed, gitweb. CGI is automatically placed in this directory.

If your cgi path is not the default/usr/lib/cgi-bin/, you need to install gitweb in/usr/lib/cgi-bin. copy CGI to the original configured cgi-bin path, and in the Apache configuration file/etc/apache2/Apache. add the following content to the end of 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>

8.5 restart Apache

Sudo/etc/init. d/apache2 restart

Access http: // localhost/cgi-bin/gitweb. cgi

NOTE: If other new members cannot clone a git repository, the following error message appears:

Error: gitosis. Serve. Main: Repository read access denied

The reason is that the key name of the current member is inconsistent with that of members in gitosis. conf! For example, the key used is lxq_rsa.pub, and the name used in a group in gitosis. conf is lxq @ ubuntu.

You only need to rename lxq_rsa.pub to the lxq@ubuntu.pub and re-push to the server!

Finally I offered a git learning site, Chinese Oh ^_^ http://progit.org/book/zh/index.html

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.