15 minutes to build an elegant code warehouse like GitHub


As an old driver, how can he not have his own private code warehouse?


GitHub is familiar to everyone.

In addition to open source projects, sometimes people will transfer their own or team or company projects to GitHub’s private warehouse and treat GitHub as their own private git server.

However, there are some problems with GitHub:

  1. GitHub’s domestic visit is not very stable, sometimes it is very slow, which affects its use;
  2. GitHub, after all, is a commercial website. Whether some rules will change in the future is unknown;
  3. Generally, we don’t do a very careful cleaning for the projects that we put in the private warehouse. The key, server address and account number in the code are written there. Once the library is made public, this information will become the biggest vulnerability of the production system.

The third point is particularly important. Recall that GitHub’s private warehouse was broken by hackers a few days ago. Will it affect you or your team?

So we want to have our own git server,

  1. It can meet the needs of GIT code management, which is the most basic;
  2. Like GitHub, it has a complete management interface of BS architecture (I like that interface and am familiar with it);
  3. It’s better to be completely controllable and build your own git server.

Today, I’m going to introduce gitea, which is my own git server.

    In order to prevent the reprint of the original web address from not being provided, the original link is added here: https://www.cnblogs.com/tiger-wang/p/12925099.html

1、 Gitea

Let’s see what gitea looks like after it runs

Are you familiar with it?

Gitea is an open source community driven code hosting solution, which uses go as the back-end language and forms an executable program. It can support x86, x64, arm and PowerPC, in other words, you can install it on any operating system you like and need.

Gitea’s website: https://gitea.io

Download address of the latest version of gitea: https://dl.gitea.io/gitea

On gitea’s website, you can find all the help from installation to use. This article, based on my own experience and the pit I have planed, teaches you to complete the complete construction and configuration adjustment of gitea step by step.

2、 Preparation before installation

Gitea needs two external systems to run: database and git client.

Part one: database

Gitea needs database support.

Gitea’s code warehouse is in the form of files. The database is used to record relevant versions, settings and various pull & commit information.

Gitea supports PostgreSQL, mysql, SQLite and MS SQL, and there is no difference in use effect.

If you have these databases, you can skip this step.

If not, you can install a SQLite, which is convenient and simple.

In order to facilitate your use, I will divide the installation of windows and Linux into two lines.

The significance of the installation of the two systems lies in: windows is the platform for most people to develop, and one can be installed for their own code; Linux is the platform for server, and one can be installed for the team.

  1. Windows install SQLite

SQLite website: https://sqlite.org

SQLite latest version download address: https://sqlite.org/download.html

To install SQLite under windows, you only need to download it from the official website: https://sqlite.org/2020/sqlite-dll-win64-x64-3310100.zip Just do it. After downloading, unzip to a directory, for example:D:\Program Files\SQLite3

Then, we need to add this directory to the environment variable path. In windows, press Win + R to open and runsysdm.cplOpen the system properties and go tosenior->environment variable, inSystem variablesIn, editPath, add at the end of the variable value;D:\Program Files\SQLite3That’s it.

That’s it. SQLite is installed under windows.

Of course, this installation completes the application system using SQLite support. If you want to manage SQLite or see what’s in the database, you can download one more: https://sqlite.org/2020/sqlite-tools-win32-x86-3310100.zip , download, also unzip toD:\Program Files\SQLite3Under the directory, it’s OK. When using, enter:

> sqlite3 your_path/your_database_file_nameSQLite version 3.31.1 2020-01-27 19:55:54Enter ".help" for usage hints.sqlite>

If you don’t see this, path is not enabled. Just exit and log on windows again.

  1. Installing SQLite on Linux

When installing SQLite under Linux, you can download the source code from the download page and compile it by yourself, or download the compiled binary package directly. Of course, it is easier to install from the package source

# apt-get install sqlite3

SQLite is also installed under Linux.

Part 2: git client

Git clients are also required to run gitea. You can use any git client. If it is already installed, you can skip the next step.

  1. Windows install git client

Git website: https://gitforwindows.org

After entering the official website, there is a big oneDownloadPush the button, press it hard, and the download starts.

After downloading, it is an executable installation file. Run the installation file to complete the GIT client installation.

After the installation is completed, it also needs to be set in the environment variablePath, add inGitThe running directory of the command. Git running directory is under git installation directorybincatalog.

  1. Installing git client on Linux

In most cases, Linux will bring its own git client. You can check:

# git --version

If installed, version information is returned.

If not, use package management to install one

# apt-get install git

3、 Install gitea

To install gitea, I also write in two lines: windows and Linux. Because Linux and windows system permissions are managed differently, the installation process will be different.

  1. windows setup

Download the latest version of 1.11.5 for windows: https://dl.gitea.io/gitea/1.11.5/gitea-1.11.5-windows-4.0-amd64.exe .

Change the name of the downloaded file togitea.exeAnd put it in a directory, for exampleD:\giteaDirectory, the installation is complete.

Gitea can be run directly on windows or added as a service.

Let’s run it directly

> d:\gitea\gitea.exe webcmd/web.go:107:runWeb() [I] Starting Gitea on PID: 5840

That’s the start.

Of course, it’s just a check. When running, we still need to add it to the service to run. Press Win + R, open and run, input command:

sc create gitea start= auto binPath= "\"d:\gitea\gitea.exe\" web --config \"d:\gitea\custom\conf\app.ini\""

Click OK and add it to the windows service.

Next, start the service gitea, and you’re done.

  1. Linux Installation

Download the latest version of 1.11.5 for Linux:

# wget -O gitea https://dl.gitea.io/gitea/1.11.5/gitea-1.11.5-linux-amd64

After downloading, move gitea to/usr/local/binDirectory and changed to executable.

# mv gitea /usr/local/bin# chmod +x gitea

Gitea is installed.

Here are some gitea data directories:

# mkdir /var/lib/gitea# mkdir /var/lib/gitea/{custom,data,log}# mkdir /etc/gitea

The location of the directory is recommended by gitea. It can be defined in actual installation.

Among them:

/Var / lib / gitea is the directory where the files related to the warehouse are stored

/Etc / gitea is used to store configuration files app.ini Directory of

For the security of the server, we need to do a little technical processing: create a system usergit

# adduser git --system --shell /bin/bash --group --disabled-password --home /home/git

Give me the above directoriesgitUser:

# chown -R git:git /var/lib/gitea# chown git:git /var/gitea

Gitea needs to run as a service on Linux.

Save the following configuration to a filegitea.service

[Unit]Description=Gitea (Git with a cup of tea)After=syslog.targetAfter=network.target[Service]RestartSec=2sType=simpleUser=gitGroup=gitWorkingDirectory=/var/lib/gitea/ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.iniRestart=alwaysEnvironment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea[Install]WantedBy=multi-user.target

modifygitea.serviceIs executable and copied to/etc/systemd/systemcatalog:

# chmod +x gitea.service# mv gitea.service /etc/systemd/system# systemctl enable gitea.service

Finally, start the service:

# systemctl start gitea.service


4、 Set up gitea

After the installation is complete and running, we need to configure gitea.

Gitea runs on port 3000 by default. So, in the browser, open: http://your_ gitea_ server_ IP: 3000, see a beautiful interface, it means that the installation is correct, connected to the server.

  1. configure server

From the top right corner of the interfaceregisterorSign inClick in, you will see a very long form, don’t panic, I said one by one.

Select the database type first. If the original database is used, relevant parameters need to be filled in. We installed SQLite3, so we chose this one. There will be a database path below. You don’t need to change it, just use the default. Under windows, gitea will create its own directory and data files under the running directory; under Linux, we have built them in advance.

Of course, if you have a certain habit, you can change it at will, but note that there is no problem under windows, and you need to pay attention to the permissions of the directory under Linux. This permission will be set with the “run as user name” parameter below. If you want to change it, let’s take a look at the following statement.

  • general setting


Site name, your site you name yourself;

The root directory of the warehouse is the same as the database file path above. It has a default location. You decide whether to change it or not;

The LFS root directory, like the warehouse, is used to store large files,

To run with a user name, this should be noted: under windows is system, which is the running account of the service, so if you want to change it, you need to modify the running account of the service synchronously; under Linux is git, which is the system account established in the Linux installation section above, and also the owner of several directories established. So,In Linux, if you need to modify all the places related to the file directory, you should change the permission of the directory to this user at the same time

Other parameters are easy to understand, not detailed.

  • Service and third party service settings

User self registration is prohibited. The meaning is very clear. It’s usually banned.

Enable page access restriction. This parameter determines whether the website is public or private. If the outsider visits your warehouse like browsing GitHub, you can check it.

  • Administrator account settings

This website, the first registered account, will automatically become an administrator. You need this administrator to set up a user account after you disable registration.

After finishing the above settings, click the bottom to install immediately, and the configuration is complete.

5、 Upgrade

The gitea community is very active and the version iterations are very fast.

When there is a new version, first download the new version of gitea, then stop the service, cover the old gitea program, and then start the service. It’s done.

Well, next, enjoy your private GitHub!!!



WeChat official account: Lao Wang Plus

Scanning the two-dimensional code, paying attention to the official account, can get the latest personal articles and content push.

The copyright of this article belongs to the author. Please keep this announcement and the link of the original text