Gitlab has a large function and occupies a lot of resources. It is recommended to put it on a server with better resources. The virtual machine runs 4GB+

features

  • Build with Docker-compose
  • Build it in the way of Docker, based on gitlab-CE community version (ee version can be obtained as required)
  • Use Nginx as a layer of reverse proxy, and finally through a secondary domain name can direct to GitLab

The ultimate goal is to use a secondary domain name that maps directly to the past

Gitlab.vm.com -> 192.168.204.138 -> gitlab-docker:80 Gitlab-docker :443 -> gitlab-docker:443 -> gitlab-docker:443 -> gitlab-docker:443 Gitlab.vm.com :7080 -> gitlab-docker # Finally use nginx to do a layer of reverse proxy gitlab.vm.com -> gitlab-dockerCopy the code

Install the docker

curl https://get.docker.com/ > install-docker.sh Download the installation script

sh install-docker.sh Execute the installation script

# Modify docker Ali source (here is my Docker source, you can go to Ali Cloud free access to their own exclusive accelerator source)
vim /etc/docker/daemon.json

# daemon.json
{
  "registry-mirrors": ["https://brnzp166.mirror.aliyuncs.com"]}Copy the code

Systemctl enable Docker

Docker-compose install Docker-compose

# download docker - composeThe curl -l https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose- ` uname-s`-`uname -m` > /usr/local/bin/docker-compose

# grant permission
chmod +x /usr/local/bin/docker-compose
Copy the code

Setting an External Directory

Since it is a Docker image running, we need to save the configuration, data and logs of GitLab outside the container, that is, mount it to the host computer.

mkdir -p /home/software/gitlab/etc
mkdir -p /home/software/gitlab/logs
mkdir -p /home/software/gitlab/data
Copy the code

Make the docker-comemage. yml file

Because docker-compose is used to help us deploy, there is no need to pull the image, etc., it will automatically do it for us

Find a directory to store the docker-comemage. yml file, using the /home/software/gitlab directory

  1. The new file
cd /home/software/gitlab

vim docker-compose.yml
Copy the code
  1. Edit the docker-comemess. yml file and modify the corresponding directory if necessary
# docker-compose.yml

gitlab:
  image: 'gitlab/gitlab-ce:latest'
  restart: unless-stopped
  hostname: 'gitlab.vm.com' # finally exposed host
  environment:
    GITLAB_OMNIBUS_CONFIG: |

      Gitlab url can be accessed externally
      external_url 'http://gitlab.vm.com' 
      
      # SSH related (note that this may conflict with the SSH connection tool port)
      gitlab_rails['gitlab_ssh_host'] = 'gitlab.vm.com'
      gitlab_rails['gitlab_shell_ssh_port'] = 7022

      # email related
      gitlab_rails['smtp_enable'] = true
      gitlab_rails['smtp_address'] = "smtp.163.com" # SMTP server address
      gitlab_rails['smtp_port'] = 465
      gitlab_rails['smtp_user_name'] = "[email protected]" The email address from which the email is sent
      gitlab_rails['smtp_password'] = "Authorization Code"     # Email authorization code
      gitlab_rails['smtp_domain'] = "smtp.163.com"
      gitlab_rails['smtp_authentication'] = "login"
      gitlab_rails['smtp_enable_starttls_auto'] = true
      gitlab_rails['smtp_tls'] = true 
      gitlab_rails['gitlab_email_from'] = '[email protected]' The email address from which the email is sent
  ports:
    - '7080:80'
    - '7443:443'
    - '7022:22'
  volumes:
    - '/home/software/gitlab/etc:/etc/gitlab'
    - '/home/software/gitlab/logs:/var/log/gitlab'
    - '/home/software/gitlab/data:/var/opt/gitlab'
Copy the code

Checking configuration Success

Run docekr

Switch to the address where the docker-comemage. yml file resides (at this point in /home/software/gitlab)

cd /home/software/gitlab

# Run docker in background
docker-compose up -d
Copy the code

Use Docker PS to check the current docker operating status, wait for GitLab to be in healthy/unhealthy state (about 5 minutes), that is, after the packaging is completed, visit 192.168.204.138:7080, if you can see the welcome interface, congratulations, the construction will be successful

In the future, directly switch to the address where docker-compose. Yml file exists, and use docker-compose up -d to restart the docker, and the previous Settings of docker startup.

In this case, the password of user root is the super administrator

Click the profile picture box Settings -> Preferences -> Language to switch to Chinese

Test Mailbox Service

After the modification is complete, enter another terminal and enter gitlab-Docker

Get the gitLab service containerID
docker ps

Enter the docker container
docker exec -it <containerID> /bin/bash

Check whether the mailbox is complete
gitlab-rails console     Enter the mail console, wait a moment to enter
Notify.test_email('[email protected]'.'Message Subject'.'Message Body').deliver_now
Copy the code

Use the nginx reverse proxy

Reverse proxy means that when you visit 192.168.204.138, the server arranges 192.168.204.138:7080 to serve you without your knowledge. At this time, it is the background server, through a middleman, to serve you.

Install nginx using yum

# Download the nginx package for the current system version.
wget  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm  

# Build the Nginx yum repository
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm  

# according to the/etc/yum. Repos. D/nginx. The information in the repo download and install nginx
yum install nginx   

# Start nginx service
systemctl start nginx 

# Start nginx service
systemctl enable nginx 
Copy the code

Configuring a Reverse Proxy

With nginx installed this way, the configuration file is scattered and can be viewed using Whereis Nginx

Go to the nginx configuration directory
cd /etc/nginx/conf.d

/etc/nginx/nginx.conf /nginx/nginx.conf /etc/nginx/nginx.conf
vim proxy_gitlab.conf

# my reverse proxy, gitlab.vm.com:80 -> HTTP :127.0.0.1:7080
# is the gitlab directory mapped by Dockerserver { listen 80; server_name gitlab.vm.com; Location / {proxy_pass http://127.0.0.1:7080; }}Copy the code

Restart the nginx service systemctl restart nginx

Visit http://gitlab.vm.com

Possible problems

SELINUX(for reverse proxies)

Linux security module, turn it off directly here (not recommended, find a better selinux solution)

vim /etc/sysconfig/selinux

SELINUX=disabled
Copy the code

firewalld

The firewall may cause the browser to keep circling

Local VIRTUAL machine, directly shut down (not recommended, you can go to Firewalld better solution)

systemctl stop firewalld   # disable firewall

systemctl disable firewalld   # Permanently shut down (not recommended)
Copy the code

Gitlab – Docker unlimited restart

There may be something wrong with the configuration. This happened when extends_URL was configured before, so it is not being configured now

[gitlab-docker] [gitlab] [docker ps -a

docker container logs gitlab
Copy the code

The Nginx server starts abnormally

You can switch SELINUX back to the previous mode and restart it. After nginx can start normally, restart SELINUX and modify SELINUX

Critical memory

Because GITlab still has certain requirements for equipment and gITLAB hardware requirements

If you’re running slow, try adding virtual memory

# 4GB of virtual memory
dd if=/dev/zero of=/home/swap bs=1024 count=4194304

# format partition
mkswap /home/swap

Swapoff /home/swap
swapon /home/swap

# Mount partition
vim /etc/fstab

/home/swap swap swap default 0 0
Copy the code

reference

Docker build GitLab

Add a swap partition for the cloud server