Ubuntu16.04搭建gitea1.14.1

本文详细介绍了如何在Ubuntu16.04系统上部署Gitea1.14.1版本,包括MySQL数据库的配置、Gitea二进制文件的安装及服务启动等步骤,并提供了官方教程链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下教程为在Ubuntu16.04上搭建gitea1.14.1,同时附上官方教程链接

1. 数据库准备

本教程采用的数据库为MySQL

1.1 登录数据库

mysql -uroot -p
password

1.2 创建gitea用户

密码可以设置为自己的密码,这里采用gitea作为用户密码

SET old_passwords=0;
CREATE USER 'gitea' IDENTIFIED BY 'gitea';

1.3 创建gitea数据库

这里采用utf8mb4而不是utf8作为字符集,是因为utf8mb4支持的Unicode字符更多

CREATE DATABASE giteadb CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';

1.4 给gitea用户赋予数据库的权限

GRANT ALL PRIVILEGES ON giteadb.* TO 'gitea';
FLUSH PRIVILEGES;
exit # 退出数据库

1.5 测试数据库连接

mysql -ugitea -p
password

2. 安装gitea

本教程采用二进制文件安装

2.1 下载gitea二进制文件

这里下载的gitea版本为1.14.1,新版本可以查看此链接

wget -O gitea https://dl.gitea.io/gitea/1.14.1/gitea-1.14.1-linux-amd64
chmod +x gitea

2.2 服务器配置

2.2.1 检查是否安装git

git --version

2.2.2 添加git用户

需要在root用户下执行

adduser \
   --system \
   --shell /bin/bash \
   --gecos 'Git Version Control' \
   --group \
   --disabled-password \
   --home /home/git \
   git

2.2.3 创建所需的目录

mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea
touch /etc/gitea/app.ini
chown root:git /etc/gitea/app.ini
chmod 770 /etc/gitea/app.ini

这里官方安装教程提示只是临时将/etc/gitea设置了用户git的写入权限,在web的安装过程中就可以写入配置文件,在安装完成后,可以通过以下命令将权限修改为只读

chmod 750 /etc/gitea
chmod 640 /etc/gitea/app.ini

2.2.4 将gitea二进制文件复制到指定路径

cp gitea /usr/local/bin/gitea

3. 运行gitea

这里采用官方推荐的通过创建一个service file来自动启动gitea

3.1 创建gitea.service文件

将以下内容写入到/etc/systemd/system/gitea.service中,因为本教程采用的是MySQL数据库,所以同时将有关MySQL配置的注释打开,如果采用其他的数据可以打开其他注释并将MySQL的配置注释了

[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

3.2 启动gitea服务

sudo systemctl enable gitea
sudo systemctl start gitea

3.3 访问web页面

url链接为http://serverip:3000/

4. 进行web界面配置

4.1 设置数据库认证

在这里插入图片描述

4.2 设置常规设置

默认即可
在这里插入图片描述

4.3 禁用用户自行注册(可选)

选择此选项意味着只能通过管理员来手动创建用户账户
在这里插入图片描述

4.4 创建管理员账户

在这里插入图片描述

4.5 登录

点击install Gogs之后便可登录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值