https://www.jianshu.com/p/b04356e014fa
Preface
New companies find that they are also using outdated production tools, svn, and because they have used SVN and git so heavily, they know the difference between them and are on their way to git.
So I was persuaded to follow my supervisor's strong recommendation that I promote git and his private warehouse gitlab, Amway's idea of "sharpening the knife and cutting the wood properly" several times.
Here are the detailed notes I have taken while installing and recording, so that they can be shared with colleagues directly after installation to reduce the team's learning costs.
Advantages of git
- git is distributed, svn is not
git is available locally, allowing you to save any kind of historical traces without worrying about polluting your server or even submitting code and viewing log s without having to connect to it. - The branches of GIT and SVN are different
Branches are actually copies in the version Library in SVN, and a git repository is a snapshot, so git switching, merging branches, and so on, is faster. - git has a powerful code warehouse management system - gitlab
It's easy to manage permissions, code review, create and manage project s
Introduction to GitLab
GitLab: is a Git-based online code repository hosting software that you can use gitlab to build your own Github-like system, which is generally used to build git private services on internal networks such as businesses and schools.
Functionality: Gitlab is a code management platform that provides code hosting, submission auditing, and problem tracking. It is very important for software engineering quality management.
Version: GitLab is divided into Community Edition (CE) and Enterprise Edition (EE).
Configuration: Recommended CPU2 core with more than 2G of memory.
The service composition of Gitlab:
Nginx: Static web server.
gitlab-shell: Used to process Git commands and modify authorized keys lists. (Ruby)
gitlab-workhorse: Lightweight reverse proxy server. (go)
GitLab Workhorse is an agile reverse proxy. It handles some large HTTP requests, such as file upload, file download, Git push/pull, and Git package download. Other requests are proxied back to the GitLab Rails application, that is, to the back-end unicorn.
logrotate: A log file management tool.
postgresql: database.
redis: Cache the database.
sidekiq: Used to perform queue tasks in the background (asynchronous execution). (Ruby)
unicorn: An HTTP server for Rack applications, GitLab Rails applications are hosted on this server. (Ruby Web Server, mainly written in Ruby)
GitLab Installation
1. Source Installation
2.yum Installation
Official source address: https://about.gitlab.com/downloads/#centos6
Tsinghua University Mirror Source: https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce
New/etc/yum.repos.d/gitlab_gitlab-ce.repo for:
[gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1
Installation Dependency
sudo yum install curl openssh-server openssh-clients postfix cronie sudo service postfix start sudo chkconfig postfix on #This sentence is used as a firewall to avoid user access via ssh and http. sudo lokkit -s http -s ssh
Re-execution
sudo yum makecache sudo yum install gitlab-ce sudo gitlab-ctl reconfigure #Configure and start GitLab
Configure domain name: vim/var/opt/gitlab/nginx/conf/gitlab-http.conf
# Ports accessed by external networks, if the server already has 80 servers occupied, you can change to other ports here listen *:8888; server_name gitlab.test.domain.com; set $http_host_with_default "gitlab.test.domain.com:8888";
Supplementary Note: As this custom nginx configuration is regenerated when gitlab configuration/etc/gitlab/gitlab.rb is compiled, the nginx above does not need to be customized as long as the gitlab configuration is well configured.
Change Password
gitlab-rails console production user = User.where(id:1).first user.password='123456' user.save!
GitLab Backup and Recovery
backups
# This command can be written to crontab for periodic backup /usr/bin/gitlab-rake gitlab:backup:create
The backed up data is stored in/var/opt/gitlab/backups, with the user customizing the parameter gitlab_rails['backup_path'], change the default value.
recovery
# Stop unicorn s and sidekiq s, and make sure there are no new connections to the database and no write data sudo gitlab-ctl stop unicorn sudo gitlab-ctl stop sidekiq # Enter the backup directory for recovery, 1476900742 is the timestamp of the backup file cd /var/opt/gitlab/backups gitlab-rake gitlab:backup:restore BACKUP=1476900742 cd - # Start unicorn s and sidekiq sudo gitlab-ctl start unicorn sudo gitlab-ctl start sidekiq
GitLab Profile Modification
vim /etc/gitlab/gitlab.rb
Basic gitlab configuration:
#External access url (compiled, automatically compiled to nginx configuration, nginx does not need to be configured) external_url 'http://gitlab.test.domain.com:8888' #The default value is 8080. If the port is occupied, you can modify 8080 to something else (for example, 9090) unicorn['port'] = 8080
gitlab send mail configuration
gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.exmail.qq.com" gitlab_rails['smtp_port'] = 25 gitlab_rails['smtp_user_name'] = "huangdc@domain.com" gitlab_rails['smtp_password'] = "smtp password" gitlab_rails['smtp_authentication']= "plain" gitlab_rails['smtp_enable_starttls_auto']= true gitlab_rails['gitlab_email_from']= 'huangdc@domain.com' gitlab_rails['gitlab_email_reply_to']= 'noreply@domain.com'
Server modified pit of ssh port (need to modify configuration ssh port)
#The SSH port has been modified, and the SSH address of the item in gitlab is preceded by the protocol header and port number. ssh://git@gitlab.domain.com:55725/huangdc/test.git" gitlab_rails['gitlab_shell_ssh_port'] = 55725
Configuration takes effect
#Make Configuration Effective gitlab-ctl reconfigure #Restart GitLab gitlab-ctl restart
Common GitLab Commands
gitlab-ctl start # Start all gitlab components; gitlab-ctl stop # Stop all gitlab components; gitlab-ctl restart # Restart all gitlab components; gitlab-ctl status # View service status; vim /etc/gitlab/gitlab.rb # Modify gitlab configuration file; gitlab-ctl reconfigure # Recompile gitlab configuration; gitlab-rake gitlab:check SANITIZE=true --trace # Check gitlab; gitlab-ctl tail # View logs; gitlab-ctl tail nginx/gitlab_access.log
Note: Executing the reconfigure command will restore the configuration of the nginx component of gitlab, resulting in the loss of custom modified ports, domain names, and so on.
Common Catalogs
Log address:/var/log/gitlab/ # Print logs for each service Service Address:/var/opt/gitlab/ # Home directory for each service
View gitlab version
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
New Project
After logging in to the gitlab meeting with the root user, click on "new project" to create a project, such as a project named "kuaijiFirstProject".
You will then find that a git file has been generated on your hard disk:
/var/opt/gitlab/git-data/repositories/root/kuaijiFirstProject.git
Sinicization
https://gitlab.com/xhang/gitlab.git
Use of gitlab
ssh -T -p 55725 git@gitlab.domain.com
Note: <fornt style="color:red">The above ssh command test passed does not necessarily mean git clone code can be executed. The git clone code needs write permission for the account under which the command is executed. If the normal user uses sudo git clone, the Private Key of the root account git will use. </fornt>
1. Log on
Administrators open accounts and set permissions for users.
2. User generates ssh key on client
Reference article: http://www.jianshu.com/p/142b3dc8ae15
ssh-keygen -t rsa -C "huangdc@domain.com"
3. copy the contents of the public key to "SSH Keys" in the gitlab user settings
Windows: clip < ~/.ssh/id_rsa.pub
Mac: pbcopy < ~/.ssh/id_rsa.pub
GNU/Linux (requires xclip): xclip -sel clip < ~/.ssh/id_rsa.pub
4. Testing ssh connections
#Standard test code: ssh-T git@gitlab.com ssh -T -p 55725 git@gitlab.domain.com #Modified test code for port number
If the connection is successful, the following information appears:
Welcome to GitLab, huangdc!
Note: This ssh command is actually executed using the remote server user git, which was generated when gitlab was installed. All ssh clients using the gitlab server use git. User "huangdc" here Created through gitlab, it is used for gitlab's rights management, as well as for identifying developer information for submitting code, and should not be confused with ssh users.
How to use multiple SSH public keys (your own computer uses multiple code repositories)
The principle is that since each warehouse requires an ssh connection, and the ssh command defaults to using the private key under the.ssh directory to connect to the code warehouse, we can redefine its private key for different warehouse domain names in the.ssh/config directory.
Examples are as follows:
Edit file: vim/Users/david/.ssh/config
Host gitlab.domain.com IdentityFile /Users/david/.ssh/id_rsa
Initialize project in command line environment
- First create an empty code repository on gitlab and get the repository address as follows:
ssh://git@gitlab.domain.com:55725/huangdc/test.git
- Initialize warehouse locally, submit code, push to remote master branch.
git clone ssh://git@gitlab.domain.com:55725/huangdc/test.git cd test touch README.md git add README.md git commit -m "add README" git push -u origin master
Migrating old projects in a command line environment
- First create an empty code repository on gitlab and get the repository address as follows:
#Note: Old projects with existing code can only be pushed to an empty remote code repository ssh://git@gitlab.domain.com:55725/dev/memberApi.git
- Local Initialization Project, Associated Remote Warehouse, Push to Remote Warehouse
cd /Users/david/work_www/memberApi git init git remote add origin ssh://git@gitlab.domain.com:55725/dev/memberApi.git git push -u origin master
Installation and Opening of SourceTree
- Official download link: https://www.sourcetreeapp.com/
- After opening SourceTree, you need to log in to your Atlassian account to activate SourceTree. You can use your Google account to sign in directly.
- You also need some settings after login to skip in the easiest way.
Git Flow
http://flc.ren/2015/12/381.html
Remarks
This article will focus on how to install and use GitLab, and later share an article on branching model strategies.