When I was a new employee, I found that the company was still using the backward production tool SVN. Since I had used SVN and Git heavily, I knew the difference between the two tools, and I was going further and further in using Git. Therefore, I strongly suggested to my superior that I should promote Git and his private warehouse gitLab in the company. I finally convinced him by amway’s concept of “sharpness of knife does not mislead in cutting wood workers”. The following are the detailed notes I took while installing and recording, in order to share them with my colleagues after installing, so that they can be understood directly and reduce the learning cost of the team.

The advantages of git

  1. Git is distributed. SVN can be used locally without git distribution. You can store all kinds of historical traces without worrying about contaminating the server and submitting codes and viewing logs without connecting to the server.
  2. GIT branches are different from SVN branches. A branch in SVN is actually a copy of the repository, while a GIT repository is a snapshot. Therefore, GIT switching and merging branches are faster.
  3. Git has a powerful code repository management system – GitLab can be very convenient to manage permissions, code review, create and manage projects

GitLab introduction

GitLab: GitLab is an online code repository hosting software based on Git implementation, you can use GitLab to build a system similar to Github, generally used in enterprises, schools and other internal networks to build Git private server. What it does: Gitlab is a code management platform that provides code hosting, submission review, and issue tracking. It is very important for software engineering quality management. Versions: GitLab is divided into community edition (CE) and Enterprise Edition (EE). Configuration: It is recommended that the CPU has two cores and the memory is greater than 2 GB.

Gitlab’s service composition:

Nginx: static Web server. Gitlab-shell: Used to process Git commands and modify the Authorized Keys list. (Ruby) Gitlab-Workhorse: lightweight reverse proxy server. (go)

GitLab Workhorse is an agile reverse proxy. It handles large HTTP requests such as file uploaders, file downloads, Git push/pull, and Git package downloads. Other requests are reverse-proxy to the GitLab Rails application, that is, to unicorn on the back end.

Logrotate: log file management tool. Postgresql: indicates a database. Redis: cache database. Sidekiq: Used to perform queue tasks (asynchronously) in the background. Unicorn: An HTTP server for Rack Applications, GitLab Rails applications are hosted on this server. (Ruby Web Server, written mainly in Ruby)

GitLab installation

1. Source code installation

2. Yum to install

The official source address: about.gitlab.com/downloads/#… Tsinghua university image source: mirror.tuna.tsinghua.edu.cn/help/gitlab…

/etc/yum. Repos. D /gitlab_gitlab-ce. Repo

    [gitlab-ce]
    name=Gitlab CE Repository
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
    gpgcheck=0
    enabled=1

Copy the code

Install dependencies

    sudo yum install curl openssh-server openssh-clients postfix cronie
    sudo service postfix start
    sudo chkconfig postfix on
    # firewall # firewall # firewall # firewall # firewall
    sudo lokkit -s http -s ssh

Copy the code

To perform

    sudo yum makecache
    sudo yum install gitlab-ce
    sudo gitlab-ctl reconfigure  #Configure and start GitLab

Copy the code

Configuration of the domain name: vim/var/opt/gitlab/nginx/conf/gitlab – HTTP. Conf

    If the server is already occupied by a server, then you can change this to another port
    listen *:8888;
    server_name gitlab.test.domain.com;

    set $http_host_with_default "gitlab.test.domain.com:8888";

Copy the code

Note: Since the gitlab configuration /etc/gitlab/gitlab.rb regenerates the custom nginx configuration, as long as the gitlab configuration is properly configured, there is no need for custom nginx.

Change the password

    gitlab-rails console production
    user = User.where(id:1).first
    user.password='123456'
    user.save!

Copy the code

GitLab backup and restore

The backup

    You can write this command to crontab for scheduled backup
    /usr/bin/gitlab-rake gitlab:backup:create

Copy the code

Backup data is stored in /var/opt/gitlab/backups. You can change the default value of gitlab_rails[‘backup_path’].

restore

    # stop unicorn and Sidekiq to ensure that there are no new connections to the database
    sudo gitlab-ctl stop unicorn
    sudo gitlab-ctl stop sidekiq

    1476900742 is the timestamp of the backup file
    cd /var/opt/gitlab/backups
    gitlab-rake gitlab:backup:restore BACKUP=1476900742
    cd -

    Launch Unicorn and Sidekiq
    sudo gitlab-ctl start unicorn
    sudo gitlab-ctl start sidekiq

Copy the code

GitLab configuration file modified

    vim /etc/gitlab/gitlab.rb

Copy the code

Gitlab Basic configuration:

    This configuration is automatically compiled into the nginx configuration, so 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, change 8080 to another (for example, 9090).
    unicorn['port'] = 8080

Copy the code

Gitlab sends 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'= "[email protected]" gitlab_rails'smtp_password'] = "smtp password"  
    gitlab_rails['smtp_authentication'] = "plain" gitlab_rails['smtp_enable_starttls_auto']= true gitlab_rails['gitlab_email_from']= '[email protected]' Gitlab_rails [' gitlab_email_reply_to] = '[email protected]'Copy the code

SSH port pits modified by the server (SSH port configuration needs to be modified)

    # modified SSH port, gitlab SSH address of the project, will add agreement at front head and port number "ssh://[email protected]: 55725 / huangdc/test. The git"
    gitlab_rails['gitlab_shell_ssh_port'] = 55725

Copy the code

Configuration to take effect

    # Make the configuration take effect
    gitlab-ctl reconfigure
    # Restart GitLab
    gitlab-ctl restart

Copy the code

GitLab common command

    gitlab-ctl start    Start all GitLab components;
    gitlab-ctl stop        # Stop all GitLab components
    gitlab-ctl restart        Restart all GitLab components;
    gitlab-ctl status        # check service status;
    vim /etc/gitlab/gitlab.rb        Alter gitlab config file;
    gitlab-ctl reconfigure        Recompile gitlab configuration;
    gitlab-rake gitlab:check SANITIZE=true --trace    # check gitlab;
    gitlab-ctl tail        # check log;
    gitlab-ctl tail nginx/gitlab_access.log

Copy the code

Note: Reconfigure will restore the configuration of the gitlab nginx component, resulting in no custom ports, domain names, etc.

Commonly used directory

Log address: /var/log/gitlab/   Print logs of each serviceService address: /var/opt/gitlab/The home directory of each service

Copy the code

Check out the GitLab version

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

New project

After logging in to GitLab as root, click “New Project” to create a project, such as “kuaijiFirstProject”. A git file has been generated on your hard drive:

    /var/opt/gitlab/git-data/repositories/root/kuaijiFirstProject.git

Copy the code

localization

Gitlab.com/xhang/gitla…

The use of gitlab

    ssh -T -p 55725 [email protected]

Copy the code

Note: Git clone is the Private Key of the root account. If you use sudo git clone, you can use the Private Key of the root account.

1. Login

The administrator will open accounts and set permissions for users.

2. The user generates an SSH key on the client

Refer to the article: www.jianshu.com/p/142b3dc8a…

    ssh-keygen -t rsa -C "[email protected]"

Copy the code

3. Copy the contents of the public key to the “SSH Keys” in 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. Test the SSH connection

Ssh-t [email protected]
ssh -T -p 55725 [email protected]  Change the port number of the test code

Copy the code

If the connection is successful, the following message appears:

    Welcome to GitLab, huangdc!

Copy the code

Note: In fact, the remote server user used to execute this SSH command is git. This user is generated when gitlab is installed. All SSH clients using gitlab server are using git as the user. The user “huangDC” here is created through GitLab for permission management and also for identifying the developer of the submitted code, not to be confused with SSH users.

How to use multiple SSH public keys (using multiple repositories on your own computer)

Since each repository requires an SSH connection, and the SSH command defaults to using the private key in the.ssh directory to connect to the repository, we can redefine the private key in the.ssh/config directory for different repository domains.

Examples are as follows:

Edit the file: vim /Users/ David /.ssh/config

    Host            gitlab.domain.com    
    IdentityFile    /Users/david/.ssh/id_rsa    

Copy the code

Initializes the project from the command line environment

  1. Create an empty repository on gitLab and get the repository address as follows:
    ssh://[email protected]:55725/huangdc/test.git

Copy the code
  1. Initialize the repository locally, commit code, and push to the remote Master branch.
    git clone ssh://[email protected]:55725/huangdc/test.git  
    cd test  
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master

Copy the code

Migrate old projects from the command line environment

  1. Create an empty repository on gitLab and get the repository address as follows:
    # Note: Old projects with existing code can only be pushed to an empty remote repository
    ssh://[email protected]:55725/dev/memberApi.git     

Copy the code
  1. Initializes the project locally, associates the remote repository, and pushes to the remote repository
 cd /Users/david/work_www/memberApi
 git init
 git remote add origin ssh://[email protected]:55725/dev/memberApi.git
 git push -u origin master

Copy the code

SourceTree installation and opening

  1. Download link: www.sourcetreeapp.com/
  2. Once you have SourceTree open, you need to log into the Atlassian account to activate SourceTree. You can log in directly with your Google account.
  3. There are also some Settings that need to be set up once you log in, so skip them in the easiest way

1. Permissions

chmod -R 755 /var/log/gitlab // Add permissionsCopy the code

2. The port is occupied

Vim /etc/gitlab/gitlab.rb // Edit the configuration file external_url'* * * * *, * * * * *'// Change the portCopy the code

3. Insufficient memory Installation of GitLab requires at least 4G memory

www.jianshu.com/p/b04356e01…