Installation and use of GitLab

Emerging issues:

提示: gitlab-ctl command not found

gitlab-ce of installing (and perhaps the installation failed),

So there is no gitlab-ctl command

In this case reinstall yum install gitlab-ce

Will prompt a warning, what a bunch of NOKEY,

And prompts the location of the downloaded rpm package is located

At this time, the manual mounting rpm normal instruction, the package will have a few minutes to more than 600 M

sudo rpm -i gitlab-7.9.1_omnibus.1-1.el7.x86_64.rpm

 

 

Original:   Shoubashoujiao installation and use of your GitLab

Foreword

New recruits company, found that companies are still using outdated production tools svn, due to the heavy use svn and git too, know the difference between these two tools, on the way to use git further and further away.
So, I strongly recommend a higher level with the company and pursue his private git repository gitlab, repeatedly Amway philosophy "Preparation may quicken the workers", I was finally convinced.
The following is a detailed side installation and side notes I recorded, to share directly to colleagues will be able to understand and reduce the cost of learning team after a view installed.

The advantage of git

  1. git is distributed, svn not
    git distributed locally can be used, you can easily save all kinds of traces of history, do not worry about pollution servers, Rom server can submit code to view the log.
  2. GIT SVN branch and a branch of different
    branches in SVN repository is actually a copy, but a git repository is a snapshot, so git switch, merging branches and other operations more quickly.
  3. git has a powerful code warehouse management system - gitlab
    can easily manage permissions, the code review, create, manage project

GitLab Introduction

GitLab: is a software-based online code repository hosted Git achieve, you can use gitlab built himself a similar Github same system, generally used in businesses, schools and other internal network build git PW.
Function: Gitlab is to provide a code hosting, management platforms commit code review and issue tracking. Very important for the quality of software engineering management.
Version: GitLab into Community Edition (CE) and Enterprise Edition (EE).
Configuration: It is recommended CPU2 core, memory, 2G or more.

Gitlab service components:

Nginx: static web server.
gitlab-shell: Git commands for processing and modifying the list of authorized keys. (Ruby)
gitlab-Workhorse: lightweight reverse proxy server. (Go)

GitLab Workhorse is a quick reverse proxy. It will deal with a number of large HTTP requests, such as file upload, file download, Git push / pull and Git package download. Other requests to the reverse proxy GitLab Rails application, i.e., the rear end of the reverse proxy to unicorn.

logrotate: log file management tools.
postgresql: database.
redis: Cache database.
sidekiq: queue for execution tasks in the background (asynchronous execution). (Ruby)
Unicorn: An HTTP Server for Rack Applications, gitlab Rails applications are hosted on this server above. (Ruby Web Server, mainly written in Ruby)

GitLab installation

1. Source Installation

2.yum installation

The official source address: https://about.gitlab.com/downloads/#centos6
mirror source Tsinghua University: https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce

New /etc/yum.repos.d/gitlab_gitlab-ce.repo, says:

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

Installation depends

    sudo yum install curl openssh-server openssh-clients postfix cronie
    sudo service postfix start
    sudo chkconfig postfix on
    #这句是用来做防火墙的,避免用户通过ssh方式和http来访问。
    sudo lokkit -s http -s ssh

Then perform

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

Configuring Domain Name: vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

    # 外网访问的端口,如果服务器已经有服务器占用了80,那么这里可以改成其它
    listen *:8888;
    server_name gitlab.test.domain.com;
    
    set $http_host_with_default "gitlab.test.domain.com:8888";

Additional information: Since when configuring /etc/gitlab/gitlab.rb compiled gitlab will regenerate the custom nginx configuration, so long as gitlab configuration with well, above nginx actually do not need to customize.

change Password

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

GitLab backup and recovery

Backup

    # 可以将此命令写入crontab,以实现定时备份
    /usr/bin/gitlab-rake gitlab:backup:create
    

The backup data is stored in / var / opt / gitlab / backups, user custom parameter gitlab_rails [ 'backup_path'], change the default value.

restore

    # 停止unicorn和sidekiq,保证数据库没有新的连接,不会有写数据情况
    sudo gitlab-ctl stop unicorn
    sudo gitlab-ctl stop sidekiq
    
    # 进入备份目录进行恢复,1476900742为备份文件的时间戳
    cd /var/opt/gitlab/backups
    gitlab-rake gitlab:backup:restore BACKUP=1476900742
    cd -
    
    # 启动unicorn和sidekiq
    sudo gitlab-ctl start unicorn
    sudo gitlab-ctl start sidekiq

GitLab modify configuration files

    vim /etc/gitlab/gitlab.rb

gitlab Basic configuration:

    #外部访问url(经过编译后,自动将这个配置编译到nginx配置,nginx就无需配置了)
    external_url 'http://gitlab.test.domain.com:8888'
    #默认值就是8080。如果端口被占用,可将8080修改为其它(例如: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'] = “[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]'  

Ssh server pit modified port (need to modify the configuration ssh port)

    #修改过ssh端口,gitlab中项目的的ssh地址,会在前面加上协议头和端口号“ssh://git@gitlab.domain.com:55725/huangdc/test.git”
    gitlab_rails['gitlab_shell_ssh_port'] = 55725

Configuration takes effect

    #使配置生效
    gitlab-ctl reconfigure
    #重新启动GitLab 
    gitlab-ctl restart

GitLab commonly used commands

    gitlab-ctl start    # 启动所有 gitlab 组件;
    gitlab-ctl stop        # 停止所有 gitlab 组件;
    gitlab-ctl restart        # 重启所有 gitlab 组件;
    gitlab-ctl status        # 查看服务状态;
    vim /etc/gitlab/gitlab.rb        # 修改gitlab配置文件;
    gitlab-ctl reconfigure        # 重新编译gitlab的配置;
    gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
    gitlab-ctl tail        # 查看日志;
    gitlab-ctl tail nginx/gitlab_access.log

Note: perform configuration command will restore reconfigure gitlab of nginx components, leading to port custom modifications and domain name are all gone.

Common catalog

    日志地址:/var/log/gitlab/   # 对应各服务的打印日志 
    服务地址:/var/opt/gitlab/   # 对应各服务的主目录 

View gitlab version

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

New Project

After using the root user to log into gitlab will, click on "new project" to create a project, such as project named "kuaijiFirstProject".
Then you find that the hard disk has generated a file git:

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

Chinese localization

https://gitlab.com/xhang/gitlab.git

gitlab use

    ssh -T -p 55725 git@gitlab.domain.com

Note: <fornt style = "color: red"> ssh command over this test is passed, does not necessarily mean you can git clone the code, the code needs to execute the command git clone accounts have write access, if it is ordinary users to use sudo git clone git it Private Key root account will be used. </ Fornt>

1. Log

Administrator for the user to open an account and set permissions.

2. User generated ssh key 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 gitlab user settings inside the "SSH Keys"

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 ssh connection

#标准测试代码:ssh -T git@gitlab.com
ssh -T -p 55725 [email protected]  #修改过端口号的测试代码

If the connection is successful, the following message appears:

    Welcome to GitLab, huangdc!

Description: In fact, the implementation of this ssh command, the user of the remote servers using git, the user is generated at the time of installation gitlab all use gitlab server ssh client, are using git this user. Here the user "huangdc" was created by gitlab, rights management for gitlab is also used for identification code information submitted by the developer, not to be confused with the user's ssh.

How to use multiple SSH public keys (their computer using multiple code repository)

In fact, the principle is: because each warehouse requires ssh connections, ssh command default is to use the private key to .ssh directory connection code repository, so we can redefine it for domain different warehouses in .ssh / config directory inside private key.

Examples are as follows:

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

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

Command line project initialization environment

  1. First, create an empty warehouse in gitlab code above to get the warehouse at the following address:
    ssh://[email protected]:55725/huangdc/test.git
  1. In the local initialization warehouse, submit code, pushed 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

The old project migration command-line environment

  1. First, create an empty warehouse in gitlab code above to get the warehouse at the following address:
    #注意:已存在代码的旧项目只能推送到空的远程代码仓库
    ssh://[email protected]:55725/dev/memberApi.git     
  1. Local initialize the project, associated with the remote repository, pushed 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

SourceTree installation and open

  1. Net official download link: https://www.sourcetreeapp.com/
  2. After opening SourceTree, you need to log Atlassian account to activate SourceTree. You can use Google account login directly related.
  3. After logging also need some settings, in the most simple way to skip the line.

Git Flow

http://flc.ren/2015/12/381.html

Remark

This article focuses on how to install and use recording GitLab, late again share a branching model to explain the strategy articles.

Guess you like

Origin www.cnblogs.com/hjbf/p/10949241.html