Skip to content

Gitea 服务

前置操作

bash
mkdir /data/gitea
adduser --system --shell /bin/bash --user-group --home-dir /home/git git
mkdir /home/git
chown -R git:git /home/git
chmod -R 750 /home/git
mkdir -p /data/gitea
chown -R git:git /data/gitea
chmod -R 750 /data/gitea
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea

创建配置 /etc/gitea/app.ini

ini
; This file lists the default values used by Gitea
;; Copy required sections to your own app.ini (default is custom/conf/app.ini)
;; and modify as needed.
;; Do not copy the whole file as-is, as it contains some invalid sections for illustrative purposes.
;; If you don't know what a setting is you should not set it.
;;
;; see https://docs.gitea.io/en-us/config-cheat-sheet/ for additional documentation.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; General Settings
APP_NAME = ; Gitea: Git with a cup of tea
RUN_USER = ; git
RUN_MODE = ; prod


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[database]
DB_TYPE = mysql
HOST = 127.0.0.1:3306 ; can use socket e.g. /var/run/mysqld/mysqld.sock
NAME = gitea
USER = your_gitea_db_username
PASSWD = xxxxxxx

创建服务 /usr/lib/systemd/system/gitea.service

ini
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
Wants=mysql.service
After=mysql.service


[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/data/gitea
ExecStart=/data/gitea/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/data/gitea


[Install]
WantedBy=multi-user.target

创建用户

bash
sudo useradd git
chown -R git:git /data/gitea
chown -R git:git /etc/gitea

创建数据库

sql
CREATE DATABASE IF NOT EXISTS gitea DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'your_gitea_db_username'@'%' IDENTIFIED BY 'xxxxxxxx';
flush privileges;
GRANT all ON gitea.* TO 'your_gitea_db_username'@'%';
flush privileges;

服务启动

bash
systemctl start gitea.service
systemctl stop gitea.service
systemctl restart gitea.service
systemctl status gitea.service
systemctl enable gitea.service
systemctl disable gitea.service