Any project I have code for, public or private, I put on Github. It is equivalent to backing up a copy of code in the cloud, and it can be easily shared with others. But for private projects, it’s never a good idea to store them on someone else’s site, and Github is often inaccessible (even with a ladder). So we decided to build a private warehouse, based on GitLab.

You can visit Kuizuo · GitLab to see the build effect.

An overview of the page

The premise

One server, Linux, memory >=4g

My lightweight application server configuration is as follows

Set up

I choose to install the pagoda panel for the server. For personal projects, it is recommended to install it. It integrates some software stores, including the protagonist of this time, and provides visual page operation, which can save a lot of time to type commands and increase the memory of forgetting commands.

Install GitLab

Go to the pagoda panel, click on the App Store, find the latest Community edition of GitLab, and click Install

After 8 minutes of testing, you can check the access address and account password of GitLab after installation. The default port number is 8099. Remember to open this port under the firewall

Enter the address you can see the login page of GitLab.

Change the password

Reset a user’s password | GitLab

Enter the console (wait a while to enter)

sudo gitlab-rails console
Copy the code

The following page is displayed

[root@VM-4-5-centos ~]# sudo gitlab-rails console -------------------------------------------------------------------------------- Ruby: Ruby 2.7.5P203 (2021-11-24 Revision F69AEb8314) [x86_64-Linux] GitLab: 14.9.3 (ec11aba56F1) 13.24.0 PostgreSQL: 12.7 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [booted in 29.71 s] Loading production environment (Rails 6.1.4.6) irb (main) : 001-0 >Copy the code

Enter the following code

u=User.find(1)
u.password='a12345678'
u.password_confirmation = 'a12345678'
u.save!
Copy the code

The output

irb(main):001:0> u=User.find(1)
=> #<User id:1 @root>
irb(main):002:0> u.password='a12345678'= >"a12345678"
irb(main):003:0> u.password_confirmation = 'a12345678'= >"a12345678"irb(main):004:0> u.save! = >true
irb(main):005:0>
Copy the code

Finally, type Exit to exit the console, then type the code below to restart GitLab and the password is set

gitlab-ctl restart
Copy the code

:::info

If error 502 occurs after restart or port modification, you may need to wait 3-5 minutes before accessing GitLab normally

: : :

Change the language

Click the profile picture in the upper right corner ->Preferences to go to Settings, find the language set to Simplified Chinese, and click Save Changes in the lower left corner. Refresh the web language is set

Configure HTTPS

Letsencrypt is integrated inside GitLab, so you only need to enable letsEncrypt here and do the necessary configuration

Open the/opt/gitlab/etc/gitlab rb. The template, modify the following content

  1. Around line 32, delete the # in front of external_url and fill in single quotes with the HTTPS address of the Gitlab server, for example, gitlab.kuizuo.cn

     external_url 'https://gitlab.kuizuo.cn'
    Copy the code
  2. Gitlab uses the Nginx80 port by default, so this needs to be changed

    nginx['listen_port'] = 8100
    Copy the code
  3. At about line 2434 (which you can locate by searching letsENCRYPT), modify the following items

    Letsencrypt ['enable'] = true # Delete previous #, Letsencrypt ['contact_emails'] = ['[email protected]'] # Change the value to true letsencrypt['auto_renew'] = true. Encrypt ['contact_emails'] = ['[email protected]'] # Delete the preceding # to automatically updateCopy the code

Then reload the configuration (it takes a while)

gitlab-ctl reconfigure
Copy the code

Then restart GitLab for the configuration to take effect

gitlab-ctl restart
Copy the code

Gitlab will automatically issue a free HTTPS certificate through LetsENCRYPT. Once the certificate is successfully issued, you can access the code repository through the domain name specified above.

You can also create a site in nginx, configure SSL, and use a reverse proxy to 127.0.0.1:8099 to configure HTTPS. (recommended)

:::danger

Gitlab’s nginx service may not start because of a modification or conflict with gitlab’s nginx service. Modify/opt/gitlab/sv/nginx/run

exec chpst -P /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx
# is changed to
exec chpst -P /opt/gitlab/embedded/sbin/gitlab-web -p /var/opt/gitlab/nginx
Copy the code

Restart gitlab

gitlab-ctl start
Copy the code

: : :

Management center

Click the menu in the upper left corner to select the administrator, and you can set the related Settings of GitLab in the administrative center. For example,

Prohibiting the registration

In Settings -> General -> Registration Restrictions, uncheck enabled registration so that registration can be disabled (there is no registration button on the page). Of course, you can also allow, and then you need to approve and confirm the email.

You can view user information in Overview > Users.

As for the other Settings to study.

Create a project

Click New Project and import my blog project here.

After selecting Github, you will be prompted to use Github authentication, where you need to obtain the Github Token

Visit github.com/settings/to…

After the Token is generated, copy the Token to GitLab, and then you can see all the warehouses under the Github account. Here I choose Blog for import (import takes some time).

There is no special difference with the original warehouse after import

Automatic synchronization items

Go to Project Settings -> Warehouse to find the mirror warehouse. Enter the following format in the Git repository URL

// the original repository git
https://github.com/kuizuo/blog
// Add username@ to https://
https://[email protected]/kuizuo/blog
Copy the code

The passwords are the tokens above (Regenerate in the Github Token page if you forget them) as shown in the figure below


Almost anything github can do, GitLab can do.

Other features

Web IDE (Online editing code)

Running state

Put a few picture

Enter the top command and press M to sort by memory.

Still quite eat memory, after all, when the installation requires more than 4g memory.

conclusion

Actually, back to the original question, since Github may not be accessible, why not migrate to Gitee in China?

Other than playing around, some companies might not necessarily use such open source code hosting platforms, but instead build their own repository management systems like GitLab. In addition, most of other people’s things have certain restrictions, such as the number of project members and so on, which is why I made this attempt. The overall experience feels very playable.