# 以root用户登录数据库
mysql -u root -p
Enter password:
# 如果你的gitea和mysql是在同一台服务器上,按照下面的创建
mysql> CREATE USER 'gitea' IDENTIFIED BY '密码';
# 对于不在一台服务器上的,则可以按照下面的语句进行创建
# %是对于所有外部服务器进行匹配的,如果你只想限定某一台服务器登录mysql,可以把%换成你的gitea服务器的IP地址
mysql> CREATE USER 'gitea'@'%' IDENTIFIED BY '密码';
# 创建gitea所需的数据库giteadb,编码用utf8mb4.
mysql> CREATE DATABASE giteadb CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
# 授权数据库的权限
# git服务和mysql在一台服务器上的:
mysql> GRANT ALL PRIVILEGES ON giteadb.* TO 'gitea';
# git服务和mysql不在一台服务器上的:
# 可以把%换成你的gitea服务器的IP地址。
mysql> GRANT ALL PRIVILEGES ON giteadb.* TO 'gitea'@'%';
mysql> FLUSH PRIVILEGES;
# 安装git
yum -y install git
apt-get install git
# 创建目录
mkdir /home/git
# 添加git用户
groupadd git
useradd git -g git
# 创建运行所需的目录
mkdir -p /var/lib/gitea/{custom,data,log, indexers}
chown git:git /var/lib/gitea/{data,indexers,log}
mkdir /etc/gitea
chown root:git /etc/gitea/
chmod 770 /etc/gitea/
# 下载gitea
mkdir /usr/local/bin/
cd /usr/local/bin/
wget -O gitea https://dl.gitea.io/gitea/1.9.6/gitea-1.9.6-linux-amd64
chmod +x gitea
cp ./gitea /usr/local/bin/
# 将gitea做成系统服务
# vim /etc/systemd/system/gitea.service
[Unit]
Description=Gitea (Git with a cup of tea)
After=network.target
Requires=mysqld.service
[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.target
# 启动gitea
systemctl daemon-reload
systemctl enable gitea
systemctl start gitea
# nginx配置
server {
listen 80;
server_name git.renhj.org;
location / {
proxy_pass http://127.0.0.1:3000/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
}
location ~ .*\.(js|css|png)$ {
proxy_pass http://127.0.0.1:3000;
}
}
# 配置仓库地址
# vim /etc/gitea/app.ini
[server]
SSH_DOMAIN = git.renhj.org
DOMAIN = git.renhj.org
HTTP_PORT = 3000
ROOT_URL = http://git.renhj.org/
参考: https://www.renhj.org/posts/2020-02-26-%E6%90%AD%E5%BB%BA%E8%87%AA%E5%B7%B1%E7%9A%84git%E6%9C%8D%E5%8A%A1%E5%99%A8-gitea%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B