When it comes to git, many IT professionals are familiar with it, whether it’s GitLab for managing code in the company or GitHub (which is a social networking platform, but let’s not go there) that we often interact with. Git is an excellent project management software created by the genius Linus Torvalds, who developed it to manage the source code of the Linux kernel. Since then, more and more projects have started using git as their version management tool.
As the largest social platform in the world, GitHub not only hosts many excellent project source codes but also provides a considerable amount of open-source resources for free download, such as the course resources from the Computer Science Department of the University of Science and Technology of China (https://github.com/ustcwpz/USTC-CS-Courses-Resource).
Or some quirky knowledge (Hangzhou house buying guide: https://github.com/houshanren/hangzhou_house_knowledge).
You might think GitHub looks like this.
But in reality, it looks like this.
Or like this.
In our daily work and life, when it comes to writing code or documents, using git can conveniently manage our creative content. Here, I will briefly introduce how to set up a GitLab server at home. First, we need to ensure the stability of the git server, which should be online 24/7 with sufficient performance to support stable operation. I have planned two solutions: using a router and a Raspberry Pi. Since my home router has slightly lower performance, I chose the Raspberry Pi 4b (2G rom version). As the latest generation of Raspberry Pi, it inherits the portability, open-source nature, and rich interfaces of the Raspberry Pi family, and its performance has significantly upgraded compared to the Raspberry Pi 3b+. It is undoubtedly the best choice for a home server.
(From this angle, the Raspberry Pi has a unique aesthetic appeal.)
Next, I will introduce the relevant content for installing GitLab on the Raspberry Pi: 1. Visit the GitLab official website (https://packages.gitlab.com/gitlab) to obtain information about the gitlab-ce package. Since GitLab has provided support for the Raspberry Pi, you can directly download the corresponding version from the official website using wget. Here, I am using the latest version 12.8.6 as the GitLab server.
According to the prompts on the right, we can add the relevant remote repository and use the apt-get package management tool for online installation. After adding the relevant repository address locally, apt-get still failed to install, so I chose to directly download the corresponding deb package. Due to the large size of the package, after multiple attempts with wget, it still failed. It is recommended to directly use a download manager to download the download.deb package for installation.
installing…
2. After the installation is successful: Installing the deb package takes about 5 minutes. After installation, since the port 80 used by GitLab is occupied by the built-in apache service of the Raspberry Pi, we need to stop the apache service before proceeding with the GitLab deployment.
3. Now, we can run the gitlab-ctl reconfigure command to initialize the GitLab server (approximately ten minutes). After the prompt is complete, you can access the GitLab interface by using the Raspberry Pi’s IP + port 80 in the local area network. Thus, the installation of GitLab is basically complete.
Enter the GitLab management interface to create a super niubility project (covering face and escaping).
4. Now we can conveniently use the git service within the local area network. If we want to manage our projects remotely, I will introduce a practical tool: PHTunnel. On the PHTunnel open platform (https://open.oray.com/), I saw that they have opened an embedded solution for developers. Compared to the traditional PC client for mapping internal network services, PHTunnel is a more suitable choice for git services. Therefore, I embedded PHTunnel into my Raspberry Pi.
First, log in to the developer platform (https://open.oray.com/) to apply for developer permissions. I won’t elaborate here. After successful application, I obtained my own APPID and APPKEY. Then, I can download the Raspberry Pi SDK for embedding. After opening the compressed package, I saw the following four packages:
Although my local device is aarch64, the Raspbian Buster downloaded from the Raspberry Pi official website is 32-bit. Here, I chose the armv8 version of the package. After trying to run it according to the help document, it currently works normally. After scanning the code and logging in with the debug account, it shows a successful login and the domain status becomes online.
You can also obtain account information through the local management interface.
Now, PHTunnel is still running in the foreground. After binding the account information, restart it with the -d parameter to make the program run in the background. After this startup, the program will use the previous configuration file without needing to bind again. The local management interface call also validated this assumption. By adding a mapping to the local port 80, we can access the niubility project from the external network.
5. Clone to local: After clicking clone, get the address: http://raspi.git.com/root/niubility_project.git. We need to change the previous domain name to the mapping domain name of PHTunnel: http://thedim.qicp.vip/root/niubility_project.git to perform git clone.
After using the git clone command to clone the project, use git remote -v in the project directory to check the current cloned project path. At this point, the information displayed by git remote -v has changed to the mapping address of PHTunnel. In subsequent git operations, there is no need to configure the host or perform other operations separately. Modify local files and push:
6. Create a startup script: Here we use systemd to manage the process. systemd is a system-level system and service manager that has replaced systemV in newer Linux distributions, becoming a more mainstream daemon management method. Here, we will write a simple phtunnel.service file so that PHTunnel can start at boot. The content of the file is as follows:
[Unit] Description=Start phtunnel program
[Service] Type=simple ExecStart=/usr/bin/phtunnel -l /var/log/phtunnel.log -c /etc/phtunnel.json -r -i <fill in APPID> -k <fill in APPKEY> RemainAfterExit=no Restart=always
[Install] WantedBy=network-online.target
Place this service file in the /lib/systemd/system/ directory. You can manage the systemd startup files using the systemctl command. The commonly used management commands are as follows:
systemctl enable phtunnel # Create a soft link and add phtunnel.service to the corresponding target to set it to start at boot.
systemctl start phtunnel # Start the phtunnel service.
systemctl status phtunnel # View the current running status of the phtunnel service.
systemctl restart phtunnel # Restart the phtunnel service.
Thus, our “mini fake public IP version Git server” has been set up, allowing us to happily play (pretend) with our friends. PHTunnel is implemented in C language, with a minimum size of about 80KB, capable of easily achieving high-performance reverse proxy applications, supporting TCP, UDP, HTTP, HTTPS protocols, end-to-end TLS encryption communication, and black-and-white list anti-black verification, covering mainstream operating systems such as Windows, Linux, Raspberry Pi, Mac, and Android.
As a core component of PHTunnel for penetrating internal networks, PHTunnel can be integrated into various networks and smart IoT devices without needing a public IP. As long as there is internet access, it can easily penetrate various complex routers and firewalls, achieving external access to various applications within the internal network.
In the future: We can use the GitLab + PHTunnel docker image to create a GitLab service more conveniently (related images: gitlab/gitlab-ce:latest, bestoray/phtunnel:latest), both of which support the arm platform. Alternatively, we can package the GitLab and PHTunnel services into our own image. The git set up now only supports HTTP access; the method for adding HTTPS mapping needs further research. The other Raspberry Pi device I have is the Raspberry Pi Zero W, which is smaller than the Raspberry Pi 4b. I will try to fully utilize this remaining computing power to set up some interesting personal websites. We will introduce this part in detail next time.
If you want to know more about PHTunnel, feel free to scan the code to join the discussion group.