Git server Construction

Source: Internet
Author: User
Tags exit in
Reprinted: Ubuntu computer (Virtual Machine), which has an independent IP address in the company's LAN, and ensures that everyone in the team can ping;
Software requirements: Install git and OpenSSH on Git-core, gitosis, OpenSSH-server, and openssh-client:

A @ Ubuntu :~ $

Sudo apt-Get install Git-core

A @ Ubuntu :~ $

Sudo apt-Get install OpenSSH-Server

A @ Ubuntu :~ $

Sudo apt-Get install OpenSSH-client adds the user git, which serves as the administrator of all code repositories and user permissions:

A @ Ubuntu :~ $

Sudo useradd-M git sets the password for git:

A @ Ubuntu :~ $

Sudo passwd Git creates a git repository storage point. I put it under/home/prj_git, and grant users other than git no permission to this directory:

A @ Ubuntu :~ $

Sudo mkdir/home/prj_git

A @ Ubuntu :~ $

Sudo chown git: git/home/prj_git

A @ Ubuntu :~ $

Sudo chmod 700/home/prj_git initializes git users on the server. This step is actually to prepare for installing gitosis. Of course, if you use git on any machine, you must initialize it for the first time, git has never had the "well-known and non-existent" set:

A @ Ubuntu :~ $

Git config -- global user. Name "ly44770"

A @ Ubuntu :~ $

Git config -- global user. Email"
Ly44770@163.com

"Install the python setup tool, which is also prepared for gitosis:

A @ Ubuntu :~ $

Sudo apt-Get install Python-setuptools to get the gitosis package:

A @ Ubuntu :~ $

CD/tmp

A @ Ubuntu:/tmp $

Git clone git: // eagain.net/gitosis.git

A @ Ubuntu:/tmp $

CD gitosis

A @ Ubuntu:/tmp/gitosis $

Switch sudo Python setup. py install to the GIT User:
---------------------------

A @ Ubuntu:/tmp/gitosis $

Su git by default, gitosis will put the GIT repository in the GIT user's home, so we make a link to/home/prj_git
$ Ln-S/home/prj_git/home/git/repositories return to the default user again
$ Exit if you will act as the GIT server administrator, generate an SSH public key on your computer (another PC:

A @ Ubuntu :~ $

Ssh-keygen-T RSA
Copy the public key to/tmp on the server and grant the read permission to others:

A @ Ubuntu :~ $

SCP. Ssh/id_rsa.pub
Git@192.168.1.39:/tmp.


Git@192.168.1.39's

Password:
Id_rsa.pub 100% 390 0.4kb/s 00: 00a @ Ubuntu:/tmp/gitosis $

Sudo chmod A + R/tmp/id_rsa.pub to run gitosis:

A @ Ubuntu:/tmp/gitosis $

Sudo-H-u git gitosis-init </tmp/id_rsa.pub
Initialized empty git repository in/home/prj_git/gitosis-admin.git/
Reinitialized existing git repository in/home/prj_git/gitosis-admin.git/gitosis the interesting thing is that it manages the configuration file through a git repository where it is placed in/home/prj_git/gitosis-admin.git. We need to add executable permissions to a file:

A @ Ubuntu:/home/git $

Sudo passwd Root

A @ Ubuntu:/home/git $

Su

Root @ Ubuntu:/home/git

# Cd Repositories

Root @ Ubuntu:/home/git/Repositories

# Cd gitosis-admin.git/

Root @ Ubuntu:/home/git/repositories/gitosis-admin.git

# Sudo chmod 755/home/prj_git/gitosis-admin.git/hooks/post-Update

Root @ Ubuntu:/home/git/repositories/gitosis-admin.git

# Exit: Create an empty project warehouse on the server for testing. I created a warehouse named "teamwork.
Switch to git User:

A @ Ubuntu:/home/git $

Su-Git
$ CD/home/prj_git
$ Mkdir teamwork. Git
$ CD teamwork. Git
$ Git init -- bare
$ Exit in your own computer, clone the gitosis-admin.git repository so that you can modify the configuration as an administrator.
In your computer:

A @ Ubuntu :~ /Work $

Git clone
Git@192.168.1.39: gitosis-admin.git


Initialized empty git repository in/home/A/work/gitosis-admin/. Git/
Remote: counting objects: 5, done.
Remote: compressing objects: 100% (4/4), done.
Remote: Total 5 (delta 0), reused 5 (delta 0)
Refreshing objects: 100% (5/5), done. A @ Ubuntu :~ /Work $

CD gitosis-admin/Add a new user for testing:

A @ Ubuntu :~ /Work/gitosis-ADMIN $

Sudo useradd-M B

A @ Ubuntu :~ /Work/gitosis-ADMIN $

Sudo passwd B now obtains all the SSH public key files of all your team members and names them by name, such as B. Pub and LZ. Pub. All of them are copied to keydir:

A @ Ubuntu :~ /Work/gitosis-ADMIN $

Su Root

Root @ Ubuntu:/home/A/work/gitosis-Admin

# Cp/home/B/. Ssh/id_rsa.pub./keydir/B. Pub

A @ Ubuntu :~ /Work/gitosis-ADMIN $

CP/tmp/LZ. Pub./keydir/

Root @ Ubuntu:/home/A/work/gitosis-Admin

# Exit to modify the gitosis. conf file. My configuration is roughly as follows:
[Gitosis] [group gitosis-admin]
Writable = gitosis-Admin
Members =
A @ Ubuntu
[Group team]
Writable = teamwork
Members =
A @ Ubuntu

B [Group team_ro]
Readonly = teamwork
The configuration file members = LZ expresses the following meanings: member A of the gitosis-Admin group has the permission to read and write 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:

A @ Ubuntu :~ /Work/gitosis-ADMIN $

Git add.

A @ Ubuntu :~ /Work/gitosis-ADMIN $

Git commit-am "add teamweok prj and users"

A @ Ubuntu :~ /Work/gitosis-ADMIN $

Git push origin master is ready. 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. A @ Ubuntu :~ /Work $

Mkdir teamwork-Ori

A @ Ubuntu :~ /Work $

CD teamwork-Ori/

A @ Ubuntu :~ /Work/teamwork-Ori $

Git inita @ Ubuntu :~ /Work/teamwork-Ori $

Echo "/* add something */"> helloa @ Ubuntu :~ /Work/teamwork-Ori $

Git add.

A @ Ubuntu :~ /Work/teamwork-Ori $

Git commit-am "initial version" A @ Ubuntu :~ /Work/teamwork-Ori $

Git remote add Origin
Git@192.168.1.39: Teamwork. Git


A @ Ubuntu :~ /Work/teamwork-Ori $

Git push origin master has a version of teamwork so far. Other members of the team only need to clone the team work warehouse and can play it freely.

A @ Ubuntu :~ /Work/teamwork-Ori $

Su B
$ CD/home/B
$ Git clone
Git@192.168.1.39: Teamwork. Git
$ CD teamwork
$ Vim hello
$ Git add.
$ Git commit-am "B add" $ git push origin master
$ Exit in addition: If you have a ready-made git repository and want to put it on gitserver for use by the Team (for example, you clone an official kernel repository and want to use it internally as the basic repository ), what should I 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 over to the gitserver administrator to copy it to/home/prj_git/. You also need to 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.gitgenerate baredatabase
Git clone -- bare ALSA-lib alsa-lib.git
Git clone -- bare ALSA-utils alsa-utils.git4. Move the bare Library to the GIT Server Directory CP alsa-lib.git/home/prj_git5. Note that you change the owner to get the submit permission. Chown-r git alsa-lib.git and then O, huh. Configure Web Access: Apache Common commands:
A2dissite gitserver disabled
A2ensite gitserver enabling
/Etc/init. d/apache2 restart 1. APT-Get install apache22. manually install gitweb
Git clone git: // git.kernel.org/pub/scm/git/git.git
CD git
Make gitweb_projectroot = "/home/prj_git" prefix =/usr gitweb/gitweb. cgi
CD gitweb
CP-AV git */home/prj_git/3.vim/etc/apache2/sites-available/gitserver
<Virtualhost 172.20.146.39: 80>
Servername 172.20.146.39
DocumentRoot/home/prj_git
ScriptAlias/cgi-bin // home/prj_git
<Directory/home/prj_git>
Options execcgi + followsymlinks + symlinksifownermatch
AllowOverride all
Order allow, deny
Allow from all
Addhandler CGI-script CGI
Directoryindex gitweb. cgi
</Directory>
</Virtualhost> 4. grant permissions. Important: chgrp-r www-data/home/prj_git
Chmod A + R prj_git
Chmod A + x prj_gitmv hooks/post-update.sample hooks/post-update5.a2ensite gitserver
6./etc/init. d/apache2 restart anonymous access method:
Git clone
Http://192.168.1.1/alsa-lib.git


Git clone
Http://192.168.1.1/alsa-utils.git


Git access method:
Git clone
Git@192.168.1.1: alsa-lib.git


Web browsing:

Http: // 192.168.1.1
Problems:
1. Windows file names are case-insensitive, but Linux supports them. In this way, problems may occur when downloading the android source code. About 15 files have this problem.
2. The description file of the library is in the description file of the. Git folder. Edit the file and the description will be displayed on the gitweb page.
3. The post-update under the gitosis library Hooks is not renamed by the post-update.sample, they are different. Post-update allows you to update the working directory, which must be consistent with the database. Configuration files without it will not be updated.
4. (1) git @ Hello:/home/git $ git add.
Error: readlink ("external/OpenSSL/apps/md4.c"): no such file or directory
Error: Unable to index file external/OpenSSL/apps/md4.c
Fatal: adding files failed (2) root @/external/OpenSSL # git init
Initialized empty git repository in/external/OpenSSL/. Git/

Root @/external/OpenSSL

# Git add.
Error: readlink ("apps/md4.c"): no such file or directory
Error: Unable to index file apps/md4.c
Fatal: adding files failed
(3)
Root@android-2.1 _ R2 $

Rm-RF. Repo

Root@android-2.1 _ r2

$

Find.-Name ". Git" | xargs Rm-RF

Root@android-2.1 _ r2

$

Find.-Name ". Git"

Root@android-2.1 _ r2

$

Git init
Initialized empty git repository in android-2.1_r2-hopen/. Git/

Root@android-2.1 _ r2

$

Git add.
Error: readlink ("external/OpenSSL/apps/md4.c"): no such file or directory
Error: Unable to index file external/OpenSSL/apps/md4.c
Fatal: adding files failed
Cause of error: the NTFS file system does not support symlink. (4) use of group members in the Members variable in gitosis configuration # You can use groups just to avoid listing users multiple times. Note
# No writable = or readonly = lines. [Group Public-Group]
Members = a B c d Xiaoming # That is, @ public-group [Group prj1]
Writable = prj/build
Members = Lihua @ public-group

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.