Gitea安装
资料
准备
# 数据库(MySQL)
# https://docs.gitea.io/zh-cn/database-prep/
# 创建数据库
> CREATE DATABASE DB_GITEA CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
# 创建用户
> CREATE USER 'gitea'@'%' IDENTIFIED WITH mysql_native_password BY 'Gitea!2020';
# 用户授权
> GRANT ALL PRIVILEGES ON DB_GITEA.* TO 'gitea'@'%';
# 刷新权限,立即生效
> FLUSH PRIVILEGES;
# 用户
$ useradd gitea
安装
# 安装
# https://docs.gitea.io/zh-cn/install-from-binary/
# https://docs.gitea.io/zh-cn/install-from-package/
# https://docs.gitea.io/zh-cn/install-from-source/
$ curl -L https://dl.gitea.io/gitea/1.11.2/gitea-1.11.2-linux-amd64 -o /usr/local/bin/gitea
$ chmod +x /usr/local/bin/gitea
# 测试
$ gitea -v
Gitea version 1.11.2 built with GNU Make 4.1, go1.14 : bindata, sqlite, sqlite_unlock_notify
# http://192.168.1.102:3000/
$ gitea web
命令
$ gitea -h
NAME:
Gitea - A painless self-hosted Git service
USAGE:
gitea [global options] command [command options] [arguments...]
VERSION:
1.11.2 built with GNU Make 4.1, go1.14 : bindata, sqlite, sqlite_unlock_notify
DESCRIPTION:
By default, gitea will start serving using the webserver with no
arguments - which can alternatively be run by running the subcommand web.
COMMANDS:
web Start Gitea web server
serv This command should only be called by SSH shell
hook Delegate commands to corresponding Git hooks
dump Dump Gitea files and database
cert Generate self-signed certificate
admin Command line interface to perform common administrative operations
generate Command line interface for running generators
migrate Migrate the database
keys This command queries the Gitea database to get the authorized command for a given ssh key fingerprint
convert Convert the database
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--port value, -p value Temporary port number to prevent conflict (default: "3000")
--pid value, -P value Custom pid file path (default: "/var/run/gitea.pid")
--custom-path value, -C value Custom path file path (default: "/usr/local/bin/custom")
--config value, -c value Custom configuration file path (default: "/usr/local/bin/custom/conf/app.ini")
--version, -v print the version
--work-path value, -w value Set the gitea working path (default: "/usr/local/bin")
--help, -h show help
DEFAULT CONFIGURATION:
CustomPath: /usr/local/bin/custom
CustomConf: /usr/local/bin/custom/conf/app.ini
AppPath: /usr/local/bin/gitea
AppWorkPath: /usr/local/bin
配置
# 创建配置文件目录
$ mkdir /etc/gitea
# 默认会相对于 gitea 可执行程序生成 custom/conf/app.ini 配置文件
# 建议按标准目录创建该文件,并在启动 gitea 服务时指定配置文件路径
# 官方配置文件模板:https://github.com/go-gitea/gitea/blob/master/custom/conf/app.ini.sample
$ touch /etc/gitea/app.ini
[database]
; ; Either "mysql", "postgres", "mssql" or "sqlite3", it's your choice
DB_TYPE = mysql
HOST = 192.168.1.104:3306
NAME = DB_GITEA
USER = gitea
; ; Use PASSWD = `your password` for quoting if you use special characters in the password.
PASSWD = Gitea!2020@zlikun.com
; ; For Postgres, schema to use if different from "public". The schema must exist beforehand,
; ; the user must have creation privileges on it, and the user search path must be set
; ; to the look into the schema first. e.g.:ALTER USER user SET SEARCH_PATH = schema_name,"$user",public;
; SCHEMA =
; ; For Postgres, either "disable" (default), "require", or "verify-full"
; ; For MySQL, either "false" (default), "true", or "skip-verify"
; SSL_MODE = disable
; ; For MySQL only, either "utf8" or "utf8mb4", default is "utf8".
; ; NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this.
CHARSET = utf8mb4
服务
前置
$ mkdir /etc/gitea
$ chown gitea:gitea -R /etc/gitea
$ mkdir /var/lib/gitea
$ chown gitea:gitea -R /var/lib/gitea
脚本
# /etc/systemd/system/gitea.service
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#
###
# 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=gitea
Group=gitea
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/gitea GITEA_WORK_DIR=/var/lib/gitea
# 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
反代
# gitea.i.zlikun.com.conf
server {
listen 80;
server_name gitea.i.zlikun.com;
# allow large uploads of files - refer to nginx documentation
client_max_body_size 128M;
location / {
proxy_pass http://192.168.1.102:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name nexus.i.zlikun.com;
# allow large uploads of files - refer to nginx documentation
client_max_body_size 128M;
ssl on;
ssl_certificate gitea.i.zlikun.com.pem;
ssl_certificate_key gitea.i.zlikun.com.key;
location / {
proxy_pass http://192.168.1.102:3000/;
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 https;
}
}
设置
Gitea
可以通过UI来设置数据库、邮件配置、管理员帐号等信息,系统第一个用户登录时会弹出设置表单
# 管理员
gitea / gitea@admin / gitea@zlikun.com