CentOS_6.5 install git SERVER + Client

Source: Internet
Author: User
Tags git hooks
Provides various official and user-released code examples. For code reference, you are welcome to learn about CentOS_6.5 64-bit system and install the git SERVER + client.
==================== Install the git server =====================================

CentOS install Git server Centos 6.4 + Git 1.8.2.2 + gitosis ##

1. view the Linux Server version

Cat/etc/redhat-release # view the system version

CentOS release 6.4 (Final)

Ifconfig # view the Server IP Address
Eth0
Link encap: Ethernet HWaddr 00: 23: 8B: FA: 78: 92
Inet addr: 192.168.100.202 Bcast: 192.168.100.255 Mask: 255.255.255.0
Inet6 addr: fe80: 223: 8bff: fefa: 7892/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 543645 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 157155 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX bytes: 383527379 (365.7 MiB) TX bytes: 13270106 (12.6 MiB)
Interrupt: 16

Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopback running mtu: 16436 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 0 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 0 (0.0 B) TX bytes: 0 (0.0 B)


2. Install git on the server and perform some operations

-Execute commands
Sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

-Download The git-1.8.2.2.tar.gz file at the same time, and then 'mmv 'to the'/usr/local/src' directory. [Git-1.8.2.2.tar.gz installation package] [1]


Cd/usr/local/src
Sudo tar-zvxf git-1.8.2.2.tar.gz
Cd git-1.8.2.2

Sudo make prefix =/usr/local/git all
Sudo make prefix =/usr/local/git install


-Added a soft connection.

Sudo ln-s/usr/local/git/bin/*/usr/bin/

Git -- version # If the version number is displayed, it indicates success'



3. Install gitosis on the server

Sudo yum install python-setuptools

Cd/usr/local/src

Git clone git: // github.com/res0nat0r/gitosis.git

Cd gitosis

Python setup. py install

# Display Finished processing dependencies for gitosis = 0.2 indicates that the request is successful.


======================= The above is another person's column ========================== =



Here we use a server as the git server and client. When operating git, you need to switch to the git user
==================== Git server configuration ==================================

Server: Install git tool [root]/home
Yum install-y python-setuptools git-core
Git clone git: // github.com/res0nat0r/gitosis.git
Cd gitosis
Python setup. py install

This prompt indicates that the installation is successful:
Using/usr/lib/python2.6/site-packages
Finished processing dependencies for gitosis = 0.2


Server: Create a git user and manage git: [root]/home
Useradd-m git
Su-git


Server: use client ssh to generate git management [root switch git]/home
Ssh-keygen-t rsa
Scp ~ /. Ssh/id_rsa.pub root @ server address:/tmp/
Generate ssh:
Ssh-keygen-t rsa-C "devil@meila.com"


Client: Use the client ssh to generate git management [git]/home
Gitosis-init <~ /. Ssh/id_rsa.pub

In this case, the gitosis and repositories directories are generated under/home/git, and the latter is the directory for storing public libraries. Make sure that/home/git/repositories/gitosis-admin.git/hooks/post-update has the execution permission (755 ).



Client: below you need to clone the gitosis-admin.git project on the Development machine, which is used to manage all git projects and users. /Home/git/data (manually created if no directory exists)
Git clone git@112.124.14.126: gitosis-admin.git // because it is the same machine, you can use localhost


Client: why can the clone command be used to clone the project directly? This is because the public key generated by the client is used during gitosis-init initialization. Under the gitosis-admin project, there is a gitosis. conf file and a keydir directory. Gitosis. conf is used to configure git projects and users. keydir stores users' public keys. The public keys here have strict naming requirements. If the user name is. pub, it must end with the suffix. pub. The format of gitosis. conf is as follows:
[Gitosis]

[Group gitosis-admin]
Writable = gitosis-admin
Members = username # There is a username. pub public key file under the corresponding keydir


Client: Now you can add new projects in this format.
[Gitosis]

[Group gitosis-admin]
Writable = gitosis-admin
Members = username # There is a username. pub public key file under the corresponding keydir

[Group XXX]
Writable = XXX
Members = user1 user2... # Separate multiple users with spaces

Assume that a new XXX project is added here:
Use the ssh-keygen command of the new user to generate the public key and private key, upload the public key to the keydir directory, rename it user1.pub, and update the gigosis-admin project.


Client: update the project to run the following command in the gitosis-admin project cloned on the CentOS machine:
Git add.
Git commit-a-m "add newuser"
Git push

After that, the server is ready to accept the new project. At this time, the server does not generate a new-project.git project, will be automatically generated after the PC push.



Client: Create a new project directory and add
Mkdir XXX
Cd XXX
Git init
Touch hello.txt // an empty file can be submitted successfully.
Git add hello.txt
Git commit-am 'add new Project'
Git remote add origin git@192.168.1.115: XXX. git
Git push origin master
Git push origin master // execute twice


After completing the preceding steps, check whether the XXX/. git/config file exists. If no commands are added or executed
[Branch "master"]
Remote = origin
Merge = refs/heads/master

Command: (therefore, configure the following through git config)
Git config branch. master. remote origin
Git config branch. master. merge refs/heads/master



Personal Computer: Clone Project
Git clone git@192.168.1.115: XXX. git



After code is submitted on the PC, the server synchronously updates: (add Automatic Updates)
File Location: home/git/repositories/ecshop. git/hooks/post-receive
# Automatically update submitted code to Warehouse start
Cd/home/git/data/ecshop/# ecshop is the location of the Server Client Management Project
Unset GIT_DIR # After cd is fixed, it is still in the hoot directory.
Git pull origin master
# Automatically update the submitted code to the warehouse end

Note:
After the hook script executes cd, it is still in the hooks folder when it continues to execute git statement pulling, rather than the cd file path.
The above mainly involves the addition of unset GIT_DIR. The git hooks contains some environment variables by default, which will lead to a default environment path no matter which statement is executed after the git command, in this case, unset the default GIT environment variable.


========================================= FAQs ==================

First make sure that/home/git/repositories/gitosis-admin.git/hooks/post-update is executable and the property is 0755
1. Enter the password for git operations

Cause
Public Key not found
Solution
Upload id_pub.rsa to keydir and change it to 'gitosis account. pub', for example, miao. pub. Extension. pub cannot be omitted
2. ERROR: gitosis. serve. main: Repository read access denied

Cause
Members in gitosis. conf is inconsistent with the username in keydir. For example, members = foo @ bar in gitosis, but the public secret name in keydir is foo. pub.
Solution
Make the keydir name consistent with the name specified by members in gitosis.
Change members = foo or password name to foo@bar.pub

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.