The server uses the GIT protocol.

Source: Internet
Author: User
1. Preface

Recently, I have encountered some trouble in building a version library that supports git on the server (mainly because I am not familiar with the Linux system). I will take notes here for reference by myself and others.

My environment is shown in the following table. I clone the version library from another machine to verify: git clone git: // 192.168.1.101/path/to/repos/mygit. Git mygit

Linux Server System

IP address

Version LIBRARY PATH

Debian

192.168.1.101

/Path/to/repos/mygit. Git

2. Git protocol Overview

The GIT protocol is a common protocol that provides read-only services for git version libraries (anonymous READING). The disadvantage of this protocol is that it cannot provide identity authentication, because write operations are not authorized to control, therefore, you generally do not need to provide write operations.

For public and non-authorized read-only access, the GIT protocol is much more efficient than the HTTP protocol in terms of performance and speed. Therefore, for read-only version libraries, we often use the GIT protocol, HTTP protocol is not required.

3. Git protocol deployment 3.1. Deployment principles

In principle, git
The Protocol configuration is simple. Basically, you only need to run the git-DAEMON service software in the form of a daemon, that is, to run the following parameters in the form of a daemon (What are the parameters? I will talk about them later ):

Git daemon -- inetd -- verbose -- export-all/path/to/Repos

There are many ways to run the process in the form of a daemon. I have used two methods before and after implementation: inetd and xinetd. In fact, xinetd is an upgraded version of inetd (you can just use xinetd, I tried to use inetd only with a learning attitude.) You can go to the xinetd official website to see how it is introduced: http://www.xinetd.org/. the detailed sections about inetd and xinetdare discussed in this article.

3.2. Deploy inetd

What exactly is inetd? Ask "du Niang" or "google" first. You should first have a simple understanding. You can also refer to the man inetd help document (especially after learning, it will be more effective ).

3.2.1. Installation

Sudo aptitude install netkit-inetd

Yes, but the installation is incorrect. You are prompted to specify a software installation item, one of which is OpenBSD-inetd. Continue searching: netkit-inetd has been replaced by OpenBSD-inetd. So install OpenBSD-inetd:

Sudo aptitude install OpenBSD-inetd

Note: Different Linux systems may have different situations.

 

After the installation is successful, run the following command to see if inetd is running:

PS ax | grep inetd

First, let's take a look at the parameters supported by OpenBSD-inetd. Input/etc/init. d/OpenBSD-inetd-help to see help:

#/Etc/init. d/OpenBSD-inetd -- Help

Usage:/etc/init. d/OpenBSD-inetd {START | stop | reload | force-Reload | restart | status}

Common commands:

/Etc/init. d/OpenBSD-inetd start

Start inetd

/Etc/init. d/OpenBSD-inetd stop

Stop inetd

/Etc/init. d/OpenBSD-inetd restart

Restart inetd

/Etc/init. d/OpenBSD-inetd reload

Modified the configuration file inetd. conf. You can use this command to make the configuration take effect immediately.

3.2.2. modify the configuration file

Note: You can use man inetd. conf to view detailed parameter descriptions.

Add the following settings to the configuration file/etc/inetd. conf:

Git stream tcp Nowait nobody/usr/lib/Git-core/git daemon -- inetd -- verbose -- export-all/path/to/Repos

Note:

◇ In the configuration file, the above is only one line

◇/Usr/lib/Git-core/git is the location of my git program, and git daemon is followed by the parameters for running git.

◇ By default, Git-daemon only provides services for version libraries that contain the git-Daemon-export-OK file. After -- export-all is used, the GIT access service is provided to the version library regardless of whether the version Library has the git-Daemon-export-OK identification file.

◇/Path/to/repos is the directory for storing git version libraries on Linux servers.

◇ Git daemon has many parameters. Only simple usage is listed here. If you are interested, you can use git daemon-help or man inetd. conf to help you study it slowly.

3.2.3. Make the configuration take effect immediately

After modifying the configuration file, you can use/etc/init. d/OpenBSD-inetd restart or/etc/init. d/OpenBSD-inetd reload to make the configuration take effect immediately. I will introduce another method here.

When Git-daemon is running, inetd reads its configuration file. The default value is/etc/inetd. conf. If the configuration file is modified, a sighup signal is sent to the inetd process. After receiving the sighup pending signal, inetd reads the configuration file again. Follow these steps to send a sighup signal to the inetd process:

◇ Locate the process Number of the inetd process

PS ax | grep inetd

230 ?? SS 0: 00. 01 inetd

20392 std s +. 01 grep inetd

As shown above, the process number here is '123 '.

◇ Send a sighup Signal

Sudo kill-sighup 230

 

Now, you can clone the version library through the GIT protocol.

3.3. Deploy xinetd

Since xinetd is an alternative version of inetd, we recommend that you use xinetd. Why should I give you an alternative? Visit http://www.xinetd.org /.
Xinetd.

3.3.1. Installation

Sudo aptitude install xinetd

You can also download the latest source code from the official website for installation. After the installation is successful, you can search for the xinetd file and find two executable files:/etc/init. d/xinetd and/usr/sbin/xinetd. The others are folders or do not have executable permissions. (Note: Different Linux systems may have different paths ).

# Find/-name xinetd-exec LS-IDL {}\;

665609-rwxr-XR-x 1 Root 2063 March 27 2008/etc/init. d/xinetd

665608-RW-r -- 1 Root 316 March 27 2008/etc/default/xinetd

263351-rwxr-XR-x 1 Root 133908 2008/usr/sbin/xinetd

269429 drwxr-XR-x 3 Root 4096 October 24 11:01/usr/share/doc/xinetd

3281001-RW-r -- 1 Root October 24 11:01/var/lib/update-rc.d/xinetd

I didn't figure out which path to start xinetd at one time. It seems that both of them can start the xinetd service. Later I discovered that/usr/sbin/xinetd is the real execution program, and/etc/init. the D/xinetd file is a shell script (also called/usr/sbin/xinetd ).

If you want to view the parameters supported by the/usr/sbin/xinetd program, you can view the help information in manxinetd. You can view the parameters supported by the/etc/init. d/xinetd script in/etc/init. d/xinetd-help. Is it a bit messy? Don't confuse it. You can open the/etc/init. d/xinetd script file and check the content in it.

Run the following command to check whether xinetd is running:

PS ax | grep xinetd

Run the following command to start xinetd:

/Etc/init. d/xinetd start

Start xinetd

/Etc/init. d/xinetd stop

Stop xinetd

/Etc/init. d/xinetd restart

Restart xinetd

In addition, if you want to view the log information in the xinetd running process (If your configuration file is wrong, you can find the error from the log, which is helpful for troubleshooting), you can use the following command, /xinetdlog.txt is the log file.

/Usr/sbin/xinetd-filelog/xinetdlog.txt

3.3.2. modify the configuration file

Note: You can use man xinetd. conf to view detailed parameter descriptions.

After the installation is successful, you can see/etc/xinetd. conf configuration file, which is different from inetd. You cannot directly modify it here. You need to modify it in/etc/xinetd. d/create a git-daemon file in the directory. The file content is as follows:

# Default: Off

# Description: The GIT server offers access to git Repositories

Service git

{

Disable = No

Type = unlisted

Port = 9418

Socket_type = stream

Wait = No

User = nobody

Server =/usr/local/bin/git

Server_args = daemon -- inetd -- verbose -- export-all/path/to/Repos

Log_on_failure + = userid

}

3.3.3. Make the configuration take effect immediately

Add/modify the configuration file in the/etc/xinetd. d/directory, and restart xinetd to apply the file:

/Etc/rc. d/init. d/xinetd restart

4. Provide a brief URL

The above URL is GIT: // 192.168.1.101/path/to/repos/mygit. git: If the path of the version library is deep, is there any way to provide a shorter URL address during user access? Can be git
Daemon uses the -- Base-path parameter to establish the version library root directory ing. For example, the inetd. conf configuration file is written as follows:

Git stream tcp Nowait nobody/usr/lib/Git-core/git daemon -- inetd -- verbose -- export-all -- Base-Path =/path/to/repos/path/ /Repos

You can use git: // 192.168.1.101/mygit. Git to access the version library.

5. Others

The default port of the GIT protocol is 9418. You can verify it by using the following command. Of course, you do not need the default port.

# Grep 9418/etc/services

Git 9418/tcp # git pack Transfer Service

Git 9418/udp # git pack Transfer Service

 

 

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.