How to build your own GitLab repository on CentOS7
Preamble
Hello everyone, I am a programming snail. As a java developer, in team development, we generally need to use git and git repository to manage our code, which is very convenient. When I was in a small company, I basically developed a project by myself, so I didn't have much contact with git. Later, I went to a larger company and only came into contact with it for the first time. One of the most used warehouses is gitlab, but others have helped me build it before. Recently, in order to study the automated deployment of jenkins, I have to install the git warehouse first. The first choice here is gitlab. Of course, before this, we may still You need to install a centos system, this can refer to my previous article: How to create a Linux virtual machine with VMWARE
Without further ado, let's start the installation.
install sshd
First, install the sshd dependency first and execute the following command:
yum install -y curl policycoreutils-python openssh-server
According to the normal assumption, it should be waiting for the installation to complete, but an error is reported, as shown in the figure:
It seems that there is a problem with the default yum source image in centos7. I checked it online and found a solution. The general reason is that the domain name pointed to in the yum configuration file cannot be recognized; the DNS point needs to be reset. For details, please refer to this article. https://blog.csdn.net/linhua_111/article/details/103522748
After the solution, execute the above command again to install successfully.
After installation, you need to enable and start the sshd service, execute the command:
systemctl enable sshd systemctl start sshd
set up firewall
Open the /etc/sysctl.conf file and add a new line at the end of the file.
Enter the following text:
net.ipv4.ip_forward = 1
In this way, the firewall is configured. The effect of this setting is that when the Linux host has multiple network cards, the information received by one network card can be passed to other network cards, that is, the data can be forwarded.
Then, start the firewall:
systemctl enable firewalld systemctl start firewalld
Finally, restart the firewall to make the firewall settings take effect.
systemctl reload firewalld
install postfix
Since gitlab needs to use postfix as a mail sending service, this service has to be installed.
Enter the command directly to install, in the confirmation installation link, enter [y] to:
yum install postfix
After the installation is complete, open the /etc/postfix/main.cf file, find inet_protocols = all, and change all to ipv4.
Then, start postfix and enter the command:
systemctl enable postfix systemctl start postfix
install gitlab
It's finally time to install gitlab.
First, due to network reasons, we need to change the mirror source address. Create a new gitlab-ce.repo file in the /etc/yum.repos.d directory, and enter the following in it:
[gitlab-ce]name=Gitlab CE Repositorybaseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/gpgcheck=0enabled=1
Then save the file, so that the address of the mirror source is set to that of Tsinghua University, and the download will be faster.
After saving, you need to regenerate the environment and execute the following command:
yum makecache
However, here, I encountered another problem, as shown in the figure:
The reason for this problem is obvious, that is, on my system, the /var mount point has insufficient space. It is because my mount point has a small space, and then installing gitlab consumes more space, so an error is reported. Helpless, I searched the Internet again.
Finally found a way to allocate part of the space in the root directory to other mount points, and successfully solved this problem. If you also encounter this problem, you can refer to this article, which is written in more detail. https://www.linuxidc.com/Linux/2019-04/158346.htm
Then, we can officially install gitlab and execute the following command:
yum install -y gitlab-ce
This installation takes a long time, you need to wait patiently, about 10 minutes.
When you see this screen, it means that gitlab has been basically installed.
run gitlab
First of all, we need to configure the domain name of GitLab. Of course, this is not necessary, but it is recommended to configure it, otherwise the name will not be easy to remember when accessing gitlab.
Open the /etc/gitlab/gitlab.rb file, find the external_url option, and change it to the ip or domain name of the machine, as shown in the figure:
Then, it is to initialize gitlab, which is necessary and takes a long time. Please wait patiently.
input the command:
gitlab-ctl reconfigure
When the screen as shown in the figure appears, the configuration has been completed.
Here are the commonly used commands:
sudo gitlab-ctl reconfiguresudo gitlab-ctl stopsudo gitlab-ctl start
They are to initialize gitlab, close gitlab, and start gitlab. Now let's start gitlab. But this time, the problem reappeared. The 502 interface appears, which is not the login interface we want.
I have found a lot of solutions on the Internet. It is said that port 8080 is occupied, but I am using port 80 here, so this is not the problem. It is also said that the startup may be slow and it takes a while, but I have waited for about 10 minutes, and it is still 502, so this is not the problem.
Finally, I saw that there may be insufficient memory. This is possible. When I set up the virtual machine, I only set the memory to 1GB. The Internet said that it is better to be greater than 2GB, so I changed the memory of the virtual machine to a larger size. , changed to 4GB. I am using the VMWare virtual machine here. For the operation of this change, you can also refer to my previous article I mentioned above, so I will not discuss it here.
login to gitlab
A lot of calls started to come out. It's finally time to log in, but the question is, the account is root, so what is the password?
Some students may say that it is not enough to register an account directly, so it should be possible, just click the registration option below the interface.
However, I still hope to log in with the root account first, after all, I may be able to see more comprehensively. If the password is found later, it is in one of our files. And there is a time limit, when the time comes, the password will be erased. I found this file in the log information, as shown in the figure
Then, we open the file and take out the password directly, and there is no encryption or decryption operation.
Finally, you can finally use root and this password to log in and see the effect after logging in.
Summarize
I installed this gitlab today. Although I encountered many problems in the middle, fortunately, they were all solved in the end. If there is a problem, we need to check how others solved it. Of course, we also need our own careful observation and rigorous thinking. I will write down how to use gitlab to create a warehouse and some common configurations later.
0 Comments