以下教程为在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之后便可登录