Gitea 是 Gogs 的社區管理分支,Gogs 是用 Go 編寫並在 MIT 許可下發布的輕量級代碼託管解決方案。
安裝
安裝 gitea包 或 gitea-gitAUR 軟體包。還有一個 gitea fork forgejo包 軟體包。
Gitea 需要使用資料庫後端,支持以下資料庫:
- MariaDB/MySQL
- PostgreSQL
- SQLite
- MSSQL
配置
用戶配置文件位於 /etc/gitea/app.ini
。
有關更多配置示例,參見 Gitea 文檔 。
PostgreSQL
安裝 並 配置 PostgreSQL.
在 TCP 或 UNIX 套接字之間進行選擇,然後跳轉到相應的部分。
用 TCP socket
以 postgres
用戶身份連接伺服器時創建新用戶(系統會提示輸入新用戶的密碼):
[postgres]$ createuser -P gitea
創建用戶 gitea
擁有的 Gitea 資料庫:
[postgres]$ createdb -O gitea gitea
PostgreSQL#Configure PostgreSQL to be accessible from remote hosts
驗證它是否有效:
$ psql --host=ip_address --dbname=gitea --username=gitea --password
通過首次運行安裝程序或更新 app.ini
配置 Gitea:
/etc/gitea/app.ini
DB_TYPE = postgres HOST = hostadress:port NAME = gitea USER = gitea ; Use PASSWD = `your password` for quoting if you use special characters in the password. PASSWD = password
用 Unix socket
以 postgres
用戶身份連接伺服器時創建新用戶(系統會提示輸入新用戶的密碼):
[postgres]$ createuser gitea
創建用戶 gitea
擁有的 Gitea 資料庫:
[postgres]$ createdb -O gitea gitea
通過將以下行添加到 /var/lib/postgres/data/pg_hba.conf
來設置 Unix 套接字:
/var/lib/postgres/data/pg_hba.conf
local gitea gitea peer
重新啟動 postgresql.service
.
驗證它是否有效:
[gitea]$ psql --dbname=gitea --username=gitea
通過首次運行安裝程序或更新 app.ini
配置 Gitea:
/etc/gitea/app.ini
DB_TYPE = postgres HOST = /run/postgresql/ NAME = gitea USER = gitea PASSWD =
MariaDB/MySQL
/var/run/mysqld/mysqld.sock
作為監聽參數,即可啟用 MySQL 套接字支持。以下是設置MariaDB的示例,設置所需的密碼:
$ mysql -u root -p
mysql> CREATE DATABASE `gitea` DEFAULT CHARACTER SET `utf8mb4` COLLATE `utf8mb4_unicode_ci`; mysql> CREATE USER `gitea`@'localhost' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON `gitea`.* TO `gitea`@`localhost`; mysql> FLUSH PRIVILEGES; mysql> \q
嘗試使用新用戶連接到新資料庫:
$ mysql -u gitea -p -D gitea
通過首次運行安裝程序或更新 app.ini
配置MariaDB:
/etc/gitea/app.ini
DB_TYPE = mysql HOST = 127.0.0.1:3306 ; or /var/run/mysqld/mysqld.sock NAME = gitea USER = gitea PASSWD = password
用法
啟動/啟用 gitea.service
, 網絡接口應在 http://localhost:3000
上監聽。
首次運行 Gitea 時,應該會重定向到 http://localhost:3000/install
。
- 您可能希望配置反向代理以進行遠程訪問,例如 nginx.
- 如果希望 Gitea 監聽所有接口,請在
/etc/gitea/app.ini
中設置HTTP_ADDR = 0.0.0.0
。
技巧和竅門
本地 shell 客戶端 (tea)
通過 tea包,您可以使用 gitea 的官方客戶端。更多信息請訪問 https://gitea.com/gitea/tea 。
啟用 SSH 支持
確保 SSH 已正確配置並運行。
設置域名
您可能希望設置SSH_DOMAIN
, 例如
/etc/gitea/app.ini
SSH_DOMAIN = git.domain.tld
配置 SSH
默認情況下,Gitea 將以用戶 gitea
的身份運行;該帳戶也將用於 ssh 版本庫訪問。要使 ssh 訪問正常,必須啟用 PAM。或者,也可以解鎖服務帳戶。
/etc/ssh/sshd_config
... UsePAM yes ...
如果在 SSH 配置 中使用 AllowUsers
,請在其中添加 AllowUsers gitea
,例如:
/etc/ssh/sshd_config
... AllowUsers archie gitea ...
如果使用 sshd.service
,請重新啟動該服務(如果使用 sshd.socket
,則無需重啟)。
Disable HTTP protocol
By default, the ability to interact with repositories by HTTP protocol is enabled.
You may want to disable HTTP-support if using SSH, by setting DISABLE_HTTP_GIT
to true
.
Binding on restricted ports
If you use the built-in SSH server and want Gitea to bind it on port 22, or if you want to bind Gitea webserver directly on ports 80/443 (that is in a setup without proxy), you will need to add a drop-in systemd unit override:
/etc/systemd/system/gitea.service.d/override.conf
[Service] AmbientCapabilities=CAP_NET_BIND_SERVICE CapabilityBoundingSet=CAP_NET_BIND_SERVICE PrivateUsers=false
Enable Dark Theme
In the ui section, you can set the DEFAULT_THEME
to arc-green
for making the web interface use a dark background.
Customize the appearance of Gitea
See the Gitea docs[1] for more detail.
The appearance of gitea is highly customizable using Go templates.
First, create the /var/lib/gitea/custom
directory.
Templates can be overridden by editing files in /var/lib/gitea/custom/templates
.
The default templates can be found in the Gitea source code under the templates
directory. For instance, to customize the home page, copy templates/home.tmpl
from the source code to /var/lib/gitea/custom/templates/home.tmpl
and edit the template as desired.
In addition, the logo and favicon can be changed by creating the following files: /var/lib/gitea/custom/public/img/logo.svg
and /var/lib/gitea/custom/public/img/favicon.svg
Gitea needs to be restarted after any changes to these files.
Configure reverse proxy
For additional information and examples, see the Reverse Proxies section on the Gitea documentation website [2].
nginx
The following is an example of using nginx as reverse proxy for Gitea over unix socket (you need to provide the SSL certificate):
/etc/nginx/servers-available/gitea.conf
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name git.domain.tld; ssl_certificate /path/to/fullchain.pem; ssl_certificate_key /path/to/privkey.pem; location / { client_max_body_size 512M; proxy_pass http://unix:/run/gitea/gitea.socket; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
Update the [server]
and [session]
section of app.ini
:
/etc/gitea/app.ini
[server] PROTOCOL = unix DOMAIN = git.domain.tld ROOT_URL = https://git.domain.tld HTTP_ADDR = /run/gitea/gitea.socket LOCAL_ROOT_URL = [session] COOKIE_SECURE = true
/etc/gitea/app.ini
.
Apache HTTP Server
The following is an example of using the Apache HTTP Server as reverse proxy for Gitea over unix socket.
To forward domain.tld
to the gitea server, use
/etc/httpd/conf/httpd.conf
ProxyPreserveHost On ProxyRequests off AllowEncodedSlashes NoDecode Proxypass / unix:/run/gitea/gitea.socket|http://domain.tld nocanon ProxypassReverse / unix:/run/gitea/gitea.socket|http://domain.tld nocanon
where domain.tld
should be replaced by your domain name (this entry is only passed as a header to the proxy, and does not seem to matter for this setup).
/etc/gitea/app.ini
[server] PROTOCOL = unix DOMAIN = domain.tld ROOT_URL = https://domain.tld HTTP_ADDR = /run/gitea/gitea.socket LOCAL_ROOT_URL =
To forward a subpath such as domain.tld/git
to the gitea server, use
/etc/httpd/conf/httpd.conf
<Proxy *> Order allow,deny Allow from all </Proxy> AllowEncodedSlashes NoDecode Proxypass /git unix:/run/gitea/gitea.socket|http://domain.tld nocanon ProxypassReverse /git unix:/run/gitea/gitea.socket|http://domain.tld nocanon
/etc/gitea/app.ini
[server] PROTOCOL = unix DOMAIN = domain.tld ROOT_URL = https://git.domain.tld HTTP_ADDR = /run/gitea/gitea.socket LOCAL_ROOT_URL =
Setup for custom data directory
As of now, you cannot use a custom path like /srv/gitea
as your server home, since the shipped gitea.service
unit file marks everything read-only.
To enable these custom paths, create a drop-in snippet with your server home directory as a new ReadWriteDirectories
directive:
/etc/systemd/system/gitea.service.d/data-directory.conf
[Service] ReadWriteDirectories=/srv/gitea
Then do a daemon-reload and restart gitea.service
for the changes to take effect.
Troubleshooting
Database error on startup after upgrade to 1.5.0
A problem can appear after the upgrade to 1.5.0. The service will not start, and the following error is present in the logs:
/var/log/gitea/gitea.log
2018/08/21 16:11:12 [...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: Sync2: Error 1071: Specified key was too long; max key length is 767 bytes
To fix this problem, run the following command as the `root` user on your MySQL/MariaDB server
$ mysql -u root -p
MariaDB> set global innodb_large_prefix = `ON`;
gitea should stop complaining about key size and startup properly.
Service failing with permission denied
If you manually create the gitea
user with a usual home folder /home/gitea
the gitea service will not start and output an error like :
Sep 04 04:44:32 systemd[1]: gitea.service: Failed with result 'exit-code'. Sep 04 04:44:32 systemd[1]: gitea.service: Main process exited, code=exited, status=200/CHDIR Sep 04 04:44:32 (gitea)[30727]: gitea.service: Failed at step CHDIR spawning /usr/bin/gitea: Permission denied Sep 04 04:44:32 (gitea)[30727]: gitea.service: Changing to the requested working directory failed: Permission denied
The service needs the home folder of the user to be the main gitea folder, the default being /var/lib/gitea
a fix would be:
$ usermod -d /var/lib/gitea gitea