PW build Git
A, Git server set up ways
GIT is a distributed version control system, since it is distributed so will certainly involve telecommunications, then what is the use of GIT protocol for remote communication?
Git supports four communication protocols:
- Local (local agreement)
- ssh
- http(Dumb、Smart)
- git
1, Local (local agreement)
Based access to the local file system or a shared (NFS) file system.
Advantages: simple, direct use existing file permissions and network access, small team project to build a small version of such a management system is very easy thing.
Cons: This protocol flaw is itself a shared file system limitations, only in the local area, and the speed is slow.
Match the scene: small teams, small projects makeshift version of the service.
Local protocol used:
# 从本地 f/git/atals 目录克隆项目 git clone /f/git/atals/ # 即使是 bare仓库也可以正常下载 git clone /f/git/atals.git # 基于file 协议克隆本地项目 git clone file:///f/git/atals/
If at the beginning of the URL explicitly specify file: //, then Git behavior will be slightly different. If you only specify the path, Git tries to use hard links (hard link) or directly copy the files needed. If you specify file: //, Git will trigger a process usually used for network transmission of data, is transmitted by the packaged file, save more hard disk space.
2, ssh protocol
Support use git ssh protocol for communication, which is the vast majority of linux, uninx systems support, so take advantage of the agreement to set up GIT version of the service is very convenient.
Advantages: First, SSH is relatively simple to set up, followed by access SSH is safe, very efficient additional SSH protocol, will try to compress the data prior to transmission.
Cons: permission system is not flexible, you must provide the operating system password for the account, even if it is only necessary to read version.
Match the scene: small teams, small projects, temporary project
Based on ssh protocol
Here git service must be installed on a linux system before you can use git ssh protocol to communicate with the service.
#创建一个祼项目 git --bare init lin.git #本地基于远程克隆仓库 git clone [email protected]:/data/git-repository/lin.git cd lin/ #添加文件 echo "this is luban" >> README.MF # 本地添加、提交、并推送至远程 git add -A; git commit -am 'first commit'; git push;
Possible errors:
git-upload-pack: command not found
The reason is that under the ssh protocol can only access the directory under / usr / bin, the solution is as follows
ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
3、http(Dumb、Smart)
Git http protocol is to communicate interactively according lazy WEB container (apache, nginx) and cgi components, and use WEB container itself permission system for authorization verification. In front Git 1.6.6 only supports http Dumb (dumb) protocol, which can only be downloaded can not be submitted, usually used in conjunction with the ssh protocol, ssh account assignment submission, http dumb provides read-only account. After 1.6.6 git provided git-http-backend CGI for implementing the receiving remote push function.
Pros: to solve the local authority and ssh verify a single issue, can provide anonymous services based on http url, so you can go into the public network. The local and ssh is difficult to do this, this will be like to achieve a similar site github.
Cons: erection of complex configuration needs to be deployed WEB server, https certificates and the like.
Scene: a large team, the need for precise control authority, the need to deploy the service to the public to go online.
http Dumb configuration and use
Create a server version of the warehouse
cd /data/git-repository git --bare init lin.git cd lin.git/hooks/mv // 版本更新钩子,当有版本提交的时候会执行更新 post-update.sample post-update ./post-update nginx 静态访问配置 server { listen 80; server_name git.lin.com; location / { root /data/git-repository; } } #重命名钩子 mv hooks/post-update.sample hooks/post-update
Local cloning remote service
git clone http://git.lin.com/lin.git
Note: HTTP protocol is based on CGI Smart with GIT git-http-backend script to use, configure more complex, generally not to do so now, instead of using gitlab, web management gogs like were in place, this is not in the demo .
4, git protocol
Git Git protocol is included in a special daemon; it listens on a specific port (9418), similar to the SSH service, but access without any authorization.
Pros: At present, Git Git protocol network transport protocol is used in the fastest. If your project has a great amount of access, or your project is very large and does not require user authorization to write, set up any Git daemon to provide services is a good choice. It uses the same SSH data transfer mechanism, but without the encryption and authentication overhead.
Drawback: Git protocol drawback is the lack of authorization mechanisms. And 9418 is a non-standard port, the general firewall will not open.
Use GIT protocol
cd lin.git/ # 创建一个空文件,表示开放该项目 touch git-daemon-export-ok # 后台启动守护进程 $nohub git daemon --reuseaddr --base-path=/data/git-repository/ /data/git-repository/ & #本地克隆远程项目 git clone git://192.168.0.147:9418/lin.git
Second, based on gogs build private GIT Services
Introduction and gogs
gogs Basic Configuration
Backup and Recovery Timing gogs
1, gogs Introduction and Installation
Gogs is an open source, lightweight Git web service, which is characterized by simple and easy to run full-speed, international overtaken quite good. Its main functions are as follows:
Http and two protocols provide ssh access service Source
Providing a WEB interface to view source code for modification
Provide a more complete rights management features, including organizations, teams and individuals warehouse permission
The project provides a simple function viki
It provides work order management and milestone management.
Download and install:
Official website: https: //gogs.io
Download: https: //gogs.io/docs/installation choose to download and install linx amd64
Documentation: https: //gogs.io/docs/installation/install_from_binary
installation:
After unzipping the directory:
run
#前台运行 ./gogs web #后台运行 $nohup ./gogs web &
Default Port: 3000
First visit http: // <host>: 3000 will enter the initialization page, make the boot configuration.
Alternatively or other mysql sqlite data. Where the election is sqllite
2, gogs Basic Configuration
Mail configuration instructions:
Mail configuration is used to register e-mail confirmation, and retrieve the password authentication when sending e-mail. Configured in two steps:
First: Create an account opened smtp mail service, usually with company administrator mailbox. I use the QQ mailbox here.
Second: disposed gogs_home / custom / conf / app.ini file.
ENABLED = to true express mail service
host for the smtp server addresses (smtp service requires the corresponding mailbox open and must be in the form of access ssl)
from the sender's name and address
user sends account
passwd will have the corresponding authorization code when opened smtp account
After the restart can be directly tested
Admin Login == "Control Panel ==" Application Configuration Management == "Mail Configuration ==" send test message
3, gogs regular backup and recovery
Backup and recovery:
#查看备份相关参数
./gogs backup -h
#默认备份,备份在当前目录
./gogs backup
#参数化备份 --target 输出目录 --database-only 只备份 db
./gogs backup --target=./backupes --database-only --exclude-repos
#恢复。执行该命令前要先删除 custom.bak
./gogs restore --from=gogs-backup-20180411062712.zip
#自动备份脚本
#!/bin/sh -e
gogs_home="/home/apps/svr/gogs/"
backup_dir="$gogs_home/backups"
cd `dirname $0`
# 执行备份命令
./gogs backup --target=$backup_dir
echo 'backup sucess'
day=7
#查找并删除 7天前的备份
find $backup_dir -name '*.zip' -mtime +7 -type f |xargs rm -f;
echo 'delete expire back data!'
#添加定时任务 每天4:00执行备份
# 打开任务编辑器
crontab -e
# 输入如下命令 00 04 * * * 每天凌晨4点执行 do-backup.sh 并输出日志至 #backup.log
00 04 * * * /home/apps/svr/gogs/do-backup.sh >> /home/apps/svr/gogs/backup.log 2>&1
4, configure the client public key and add
Git configuration;
#Git安装完之后,需做最后一步配置。打开git bash,分别执行以下两句命令
git config --global user.name “用户名”
git config --global user.email “邮箱”
#git 自动记住用户和密码操作
git config --global credential.helper store
SSH public key to create:
- Open git bash
- Execution command generating public and private keys: the ssh-keygen -t rsa and press Enter 3
- Command to view the public key: cat ~ / .ssh / id_rsa.pub
- Copy the content to the service id_rsa.pub ~ / .ssh / authorized_keys in