Construction environment:
Gitlab server 192.168.152.131
gitlab installation address: https://about.gitlab.com/install/
1: Native manual installation gitlab
1. Install and configure the necessary dependencies
sudo apt-get update sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
2. Add GitLab package and install it
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
3. Install gitlab and log in to gitlab
gitlab is divided into ce (community version) and ee (enterprise version). Here, the default is enterprise version ee
sudo apt -y install gitlab-ee
After installation for a period of time, the size is 1026M. After installation, it displays:
After installation, enter the IP in the browser to access.
The default user is root, and the default password is / etc/gitlab/initial_root_password
Check the root password. This file will be automatically deleted 24 hours after the first reconfigure execution:
sudo cat /etc/gitlab/initial_root_password
After logging in, please change your password as soon as possible. Or there is no redirection to modify the root password interface. You need to reset the password. See the tutorial of resetting the password at the end of this article.
Note: in case of 502 error or 500 error. Possible causes:
1: There is not enough memory. At least 2G memory is required. Otherwise, it will crash. The solution is to increase the memory. Or add virtual memory swap.
2: Port 80 is occupied. Solution: change the configuration file port (described below).
4. Reconfigure Gitlab (optional)
Configuration file location / etc/gitlab/gitlab.rb
Change profile:
sudo vim /etc/gitlab/gitlab.rb
The security requirements can be changed at will. For example, the login connection can be changed to IP, or http can be changed to https, so that GitLab will automatically redirect the user to the site protected by Let's encryption certificate:
#Original configuration external_url 'http://gitlab.example.com' #Modified configuration external_url 'https://192.168.152.131'
Change the port and remove the comment
#Original configuration #nginx['listen_port'] #After modification nginx['listen_port'] = 9099
There is also a mailbox configuration. You can find the configuration yourself. Because you don't use much, you don't write it.
After modification, the configuration must be reloaded, otherwise it will not take effect.
Save the configuration and restart.
sudo gitlab-ctl reconfigure sudo gitlab-ctl restart sudo gitlab-ctl status
Attach GitLab common commands:
Common commands | explain |
---|---|
sudo gitlab-ctl reconfigure | Reload the configuration and execute it every time you modify the / etc/gitlab/gitlab.rb file |
sudo gitlab-ctl status | View GitLab status |
sudo gitlab-ctl start | Start GitLab |
sudo gitlab-ctl stop | Stop GitLab |
sudo gitlab-ctl restart | Restart GitLab |
sudo gitlab-ctl tail | View all logs |
sudo gitlab-ctl tail nginx/gitlab_acces.log | View nginx access log |
sudo gitlab-ctl tail postgresql | View postgresql log |
Here, the native installation configuration is complete.
2: docker quick install gitlab
1. Download gitlab image
Here you can download the ce Community Edition by default
sudo docker pull gitlab/gitlab-ce
2. Create a local mount folder
Usually, GitLab's configuration (etc), log and data are placed outside the container for future upgrading. Therefore, please prepare these three directories first.
sudo mkdir -p /var/gitlab/etc sudo mkdir -p /var/gitlab/log sudo mkdir -p /var/gitlab/data
3. Start docker and mount files
docker run -d -h gitlab -p 443:443 -p 80:80 -p 2222:22 --name gitlab --restart always -v /var/gitlab/etc:/etc/gitlab -v /var/gitlab/log:/var/log/gitlab -v /var/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce
4. Configure GitLab hostname
sudo vim /var/gitlab/etc/gitlab.rb
The original configuration connection is annotated. Cancel the annotation and modify the IP connection
#Original configuration #external_url 'GENERATED_EXTERNAL_URL' #Modified configuration external_url 'http://192.168.152.131'
If the container port 80 is mapped to another port of the host, you need to change the port in the configuration file. My 80 is also mapped to 80, so there is no need to change it.
sudo vim /var/gitlab/data/gitlab-rails/etc/gitlab.yml
Restart docker after making changes
sudo docker restart gitlab
When accessing IP login in the browser, it may not be displayed for the first time. It can be displayed after a while or several more refreshes. If there is no password file or there is no redirection to modify the root password interface, the password needs to be reset. This is the case for me.
5. Reset password
Enter container:
docker exec -it gitlab /bin/bash
Enter the command.
gitlab-rails console -e production user = User.where(id:1).first user.password ='12345678' user.password_confirmation ='12345678' user.save!
The first time I set the password 123456, the prompt is too short, at least 8 mantissa. Finally, save and exit to log in successfully.
docker installation gitlab completed.