|
Linux set up under their own Git server, get a long time and finally get, or the next record it, or something next time forgot.
Process:
server
Construction git directory
git user, git group as a warehouse management
ssh authorization (remote access without a password)
hook (post-receive) code to automatically deploy Web Directory
Web Directory
Ready to take on the line of code
Client
Setting up development directory
ssh connection key generation
git operations. . .
Began to implement it!
First git source compiler
https://www.kernel.org/pub/software/scm/git/
Download the latest version git (.gz) to / usr / local
installation
tar -zxf git-2.2.1.tar.gz
cd git.2.2.1
make prefix = / usr / local / git all
make prefix = / usr / local / git install
Source compiler is not as easy yum install git-all, but versions can update point, I used the Ali CentOS6.5, corresponding only to the git version 1.7.2
Git does not own equipment in the system PATH environment by modifying / etc / profile method manually paste
vim / etc / profile
# Find PATH = / usr / local / php / bin: $ PATH line to modify
PATH = / usr / local / php / bin: / usr / local / git / bin: $ PATH
# Save and exit shell reconnect it goes into effect
git repository
groupadd git
useradd git -g git
cd / home / git
mkdir repo.git # Name Custom
cd repo.git
git init --bare # generation bare warehouse, storage version information in addition to the code
chown -R git: git /home/git/repo.git
One thing to note here, online promising security reasons, only connect to git git-shell to enable users of ssh, source installation required as follows
# Modify / etc / passwd
vim / etc / passwd
# Find git user settings such as:
git: x: 502: 503 :: / home / newbmiao: / bin / bash # last path to an executable file
git: x: 502: 503 :: / home / git: / usr / local / git / bin / git-shell # bin directory in the installation package
# To enable the needed source reported git-shell command interaction
cp /usr/local/git-2.2.1/contrib/git-shell-commands / home / git /
# After git account so that users can only use the git ssh connection commands
Free connection ssh password authentication
su git # switch git status
cd / home / git /
ssh-keygen -C 'your@email.com' -t rsa # generate rsa key for you, you can directly enter all the way, the default action
Client generates close to way above.
After generating a key will appear
.ssh
id_rsa
id_rsa.pub # public service side need to verify the connection with the identity of the contents inside
On the client, open id_rsa.pub copy the contents inside
vim /home/git/.ssh/authorized_keys
# Paste client-generated public key, save and exit
# To start sshd and then git-daemon
/etc/init.d/git-daemon restart
# Top git-daemon in the installation directory / usr / local / git / libexec / git-core / git-daemon, copied directly past trip
/etc/init.d/sshd start
Such server side git repository on setting up the
Client git development
The client (the author is a window of git bash) git operations submitted try
# Enter an empty working directory
initialize git git init #
vim test
# Save and exit edit some content
git add test # added to git cache
git commit -m 'init test' # submit modifications
# Add a remote git repository
git remote add origin git @ your_host_name: /home/git/repo.git
git push origin master # This will sync to the server
Other people want to synchronize
# Clone and push:
git clone git @ your_host_name: /home/git/repo.git
cd repo
vim README
git commit -am 'fix for the README file'
git push origin master
Code synchronization (HOOK)
It used to make the top git version control center
But also we want to modify the server after receiving the update automatically synchronized code to your site directory, easy to test development
Can be achieved as follows
# Assumes that the website directory / www / web under
cd /home/git/repo.git/hooks
vim post-receive # Create a hook
# Write the following content
GIT_WORK_TREE = / www / web git checkout -f
# Save and exit
chown git: git post-receive
chmod + x post-receive
So, next time to commit changes, the code will be automatically synchronized to the specified directory
But at the beginning I still can not solve a problem encountered is that ssh public key to the server, and also start git-daemon sshd, the client git clone actually have a password, and after entering the password prompt Permission denied, please try again .
But behind the bizarre it might be permissions change, do not know why, particularly tight connection process ssh how Free. |
|
|
|