Gitea - 一款易搭建,运行快的Git服务器

简介

Gitea是一个极易安装,运行非常快速,安装和使用体验良好的自建Git服务。采用Go作为后端语言,这使得只要生成一个可执行程序即可。并且他还支持跨平台,支持Linux、macOS和Windows以及各种架构,除了x86,amd64,还包括ARM和 PowerPC。

Github地址:https://github.com/go-gitea/gitea

请输入图片描述

功能

支持活动时间线
支持SSH以及HTTP/HTTPS协议
支持SMTP、LDAP和反向代理的用户认证
支持反向代理子路径
支持用户、组织和仓库管理系统
支持添加和删除仓库协作者
支持仓库和组织级别Web钩子(包括Slack集成)
支持仓库Git钩子和部署密钥
支持仓库工单(Issue)、合并请求(Pull Request)以及Wiki
支持迁移和镜像仓库以及它的Wiki
支持在线编辑仓库文件和Wiki
支持自定义源的Gravatar和Federated Avatar
支持邮件服务
支持后台管理面板
支持MySQL、PostgreSQL、SQLite3、MSSQL和TiDB(实验性支持)数据库
支持多语言本地化(21种语言)

二进制安装

1、安装MySQL/Mariadb数据库

安装完成后,安装MySQL,至少5.5.3版本。

2、安装Git

#Debian和Ubuntu系统

apt-get -y install git

#CentOS系统

yum -y install git

3、安装Gitea

最新版本下载地址:https://dl.gitea.io/gitea

cd /usr/local/gitea

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

chmod +x gitea

./gitea web

​​​​接下来打开http://ip:3000即可。

4、域名访问
如果想用域名访问,可以用Nginx反代。反代配置为:

#在配置文件里添加

location / {

proxy_pass http://localhost:3000

proxy_redirect off;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}
 ​​​​​

5、使用服务来启动

新建一个rclone.service文件:

vi /usr/lib/systemd/system/gitea.service

写入:

[Unit]
Description=gitea

[Service]
User=root
ExecStart=/usr/local/gitea/gitea
Restart=on-abort

[Install]
WantedBy=multi-user.target

重载daemon,让新的服务文件生效:

systemctl daemon-reload

现在就可以用systemctl来启动gitea了:

systemctl start gitea

设置开机启动:

systemctl enable gitea

停止、查看状态可以用:

systemctl stop gitea

systemctl status gitea

​​​​​​​接下来就是打开网址去初始化gitea配置。
[官方完整配置文件]

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
###
# Don't forget to add the database service requirements
###
#
#Requires=mysql.service
#Requires=mariadb.service
#Requires=postgresql.service
#Requires=memcached.service
#Requires=redis.service
#
###
# If using socket activation for main http/s
###
#
#After=gitea.main.socket
#Requires=gitea.main.socket
#
###
# (You can also provide gitea an http fallback and/or ssh socket too)
#
# An example of /etc/systemd/system/gitea.main.socket
###
##
## [Unit]
## Description=Gitea Web Socket
## PartOf=gitea.service
##
## [Socket]
## Service=gitea.service
## ListenStream=<some_port>
## NoDelay=true
##
## [Install]
## WantedBy=sockets.target
##
###

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
#RuntimeDirectory=gitea
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you install Git to directory prefix other than default PATH (which happens
# for example if you install other versions of Git side-to-side with
# distribution version), uncomment below line and add that prefix to PATH
# Don't forget to place git-lfs binary on the PATH below if you want to enable
# Git LFS support
#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin
# If you want to bind Gitea to a port below 1024, uncomment
# the two values below, or use socket activation to pass Gitea its ports as above
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
###

[Install]
WantedBy=multi-user.target