How to configure a highly available local code repository (such as GitLab) on Linux

WBOY
Release: 2023-07-05 18:27:10
Original
2184 people have browsed it

How to configure a highly available local code repository (such as GitLab) on Linux

As software development and teamwork become increasingly complex, the demand for code management and version control is also increasing. As an open source code hosting platform, GitLab is widely used in team collaborative development. In order to improve the reliability and stability of the code warehouse, we can configure a highly available local code warehouse so that it can automatically switch to a backup server when a single server fails, ensuring that the team's work is not affected.

This article will take configuring GitLab on a Linux system as an example to introduce how to implement a highly available local code repository.

1. Install and configure GitLab

  1. Install GitLab

There are many ways to install GitLab on a Linux system. Here we take CentOS as an example. , use yum to install.

First, add the software source of GitLab:

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
Copy after login

Then, install GitLab:

sudo yum install -y gitlab-ee
Copy after login
  1. Configure GitLab

After the installation is complete , we need to perform some basic configurations on GitLab, including setting the administrator account and password, and binding domain names, etc.

Configure by editing the configuration file/etc/gitlab/gitlab.rbConfigure:

sudo vi /etc/gitlab/gitlab.rb
Copy after login
Copy after login

Find the following line, uncomment it and modify it to the corresponding value:

external_url 'http://yourdomain.com'
Copy after login

After saving and exiting the configuration file, reconfigure GitLab:

sudo gitlab-ctl reconfigure
Copy after login
Copy after login

2. Configure a highly available local code repository

In order to achieve a highly available local code repository, we need Set up a primary server and a backup server, and distribute traffic to the two servers through load balancing.

The following is an example configuration. The primary server address is 192.168.0.1 and the backup server address is 192.168.0.2.

  1. Install and configure load balancing

Install and configure a load balancer on both the primary server and the backup server. Here we use Nginx as load balancer.

First, install Nginx:

sudo yum install -y nginx
Copy after login

Then, edit the Nginx configuration file/etc/nginx/nginx.conf:

sudo vi /etc/nginx/nginx.conf
Copy after login

In the http module Add the following configuration:

http { upstream gitlab { server 192.168.0.1:80 weight=5; server 192.168.0.2:80 weight=1 backup; } server { listen 80; server_name yourdomain.com; location / { proxy_pass http://gitlab; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } } }
Copy after login

After saving and exiting the configuration file, restart the Nginx service:

sudo systemctl restart nginx
Copy after login
  1. Configure the main server and backup server

In Perform the following configuration on both the primary server and the backup server.

First, edit the GitLab configuration file/etc/gitlab/gitlab.rb:

sudo vi /etc/gitlab/gitlab.rb
Copy after login
Copy after login

Find the following line and modify it to the corresponding value:

external_url 'http://yourdomain.com' gitlab_rails['gitlab_shell_ssh_port'] = 10022
Copy after login

Then, close the Nginx service that comes with GitLab, and add the following lines in/etc/gitlab/gitlab.rb:

nginx['enable'] = false
Copy after login

After saving and exiting the configuration file, reconfigure GitLab :

sudo gitlab-ctl reconfigure
Copy after login
Copy after login

Finally, modify the SSH configuration file/etc/ssh/sshd_configand change the SSH listening port to 10022:

sudo vi /etc/ssh/sshd_config
Copy after login

Find the following line and modify it For the corresponding value:

Port 10022
Copy after login

After saving and exiting the configuration file, restart the SSH service:

sudo systemctl restart sshd
Copy after login

3. Test the high availability configuration

After completing the above configuration, we can Conduct some tests to verify that the high availability configuration is working.

  1. Test load balancing

Enterhttp://yourdomain.comin the browser to see if you can access the GitLab page normally. Refresh the page several times to confirm that you are accessing a different server each time.

  1. Test active/standby switching

Stop the GitLab service on the main server:

sudo gitlab-ctl stop
Copy after login

Then enterhttp: in the browser again: //yourdomain.com, confirm whether to automatically switch to the backup server.

Through the above tests, we can confirm that the highly available local code repository has been successfully configured and effective.

When configuring a highly available local code repository, we used tools such as GitLab and Nginx and made relevant configurations. Through these configurations, we successfully configured a highly available local code warehouse on the Linux system. In this way, even if the main server fails, the backup server can take over, ensuring that the team's work is not affected and improving the reliability and stability of the code warehouse.

The above is the detailed content of How to configure a highly available local code repository (such as GitLab) on Linux. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!