admin管理员组

文章数量:1568582

项目场景:

基于晶晨S905L3A的CM311-1A刷入armbian系统,并部署本地Gitea服务器
armbian系统:Armbian_jammy_6.1.93_server
Gitea二进制文件:gitea-1.21.11-linux-arm-6(经测试1.22.0版本无法运行,原因未知)


操作步骤

1.安装数据库

apt update
apt install sqlite3 //sqlite轻量化

2.创建独立用户git
Gitea无法使用root权限运行,因此需要创建一个账户"git"运行Gitea

#通过命令创建一个新的系统用户,无需密码
sudo adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git Version Control' git
# 该命令将创建一个名为git的新用户和组,并将主目录设置为/home/git
输出如下所示:
Adding system user `git' (UID 111) ...
Adding new group `git' (GID 116) ...
Adding new user `git' (UID 111) with group `git' ...
Creating home directory `/home/git' ...

3.下载Gitea二进制文件
Gitea下载页面(地址:https://dl.gitea.io/gitea/),根据ARM Cortex-A53架构故选择linux-arm-6的安装文件,通过wget下载选择1.21.11版本

wget -O /tmp/gitea https://dl.gitea.io/gitea/1.21.11/gitea-1.21.11-linux-arm-6
#下载的gitea文件暂存在/tmp路径
mv /tmp/gitea /usr/local/bin  # 移动文件,一般二进制文件存放此处
chmod +x /usr/local/bin/gitea  # 可执行权限

4.准备Git环境
检查是否安装 Git。要求 Git 版本 >= 2.0。

git --version

若没安装Git则先安装

apt update
apt install git

5.创建工作路径

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

注意: 为了让 Web 安装程序可以写入配置文件,我们临时为 /etc/gitea 路径授予了组外用户 git 写入权限。建议在安装结束后将配置文件的权限设置为只读
在Gitea Web服务启动以后执行以下

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

6.创建Linux服务自动启动 Gitea(推荐)
systemd 方式

sudo nano /etc/systemd/system/gitea.service

编写gitea.service文件;拷贝示例代码 gitea.service 并取消对任何需要运行在主机上的服务部分的注释,譬如 MySQL

[Unit]
Description=Gitea 
After=syslog.target
After=network.target
###
# Don't forget to add the database service dependencies
###
#
#Wants=mysql.service
#After=mysql.service
#
#Wants=mariadb.service
#After=mariadb.service
#
#Wants=postgresql.service
#After=postgresql.service
#
#Wants=memcached.service
#After=memcached.service
#
#Wants=redis.service
#After=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]
# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that
# LimitNOFILE=524288:524288
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
#WorkingDirectory 参数来配置工作路径,否则使用环境变量 GITEA_WORK_DIR 的方式来明确指出程序工作和数据存放路径:export GITEA_WORK_DIR=/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
###
# In some cases, when using CapabilityBoundingSet and AmbientCapabilities option, you may want to
# set the following value to false to allow capabilities to be applied on gitea process. The following
# value if set to true sandboxes gitea service and prevent any processes from running with privileges
# in the host user namespace.
###
#PrivateUsers=false
###

[Install]
WantedBy=multi-user.target

精简版如下:

[Unit]
Description=Gitea 
After=syslog.target
After=network.target

[Service]
RestartSec=10s
Type=simple
User=git
Group=git
ExecStart=/usr/local/gitea web --config /usr/local/gitea/custom/conf/app.ini
Restart=always

[Install]
WantedBy=multi-user.target

6.启动Gitea服务和设置Gitea开机启动

# 运行
systemctl start gitea
# 设置开机启动
systemctl enable gitea
# 查看进程是否成功运行
ps -aux | grep gitea
# 如果成功会看到一条git用户运行的gitea进程
git       1525  9.8 12.1 1375512 227352 ?      Ssl  17:17   0:00 /git/gitea web --config /git/custom/conf/app.ini
root      1525  0.0  0.0  12324  1040 pts/0    S+   17:17   0:00 grep --color=auto gitea
#查看Gitea服务状态
systemctl status gitea.service
● gitea.service - Gitea (Git with a cup of tea)
     Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-11-02 16:59:55 CST; 25s ago
   Main PID: 899 (gitea)
      Tasks: 9 (limit: 4658)
     Memory: 142.9M
        CPU: 1.310s
     CGroup: /system.slice/gitea.service
             └─899 /usr/local/bin/gitea web --config /etc/gitea/app.ini

相关指令

 #重载daemon,让新的服务文件生效
 systemctl daemon-reload
 #停止Gitea
 systemctl stop gitea
 #安全地重启程序
 systemctl restart gitea
 #查看日志
 journalctl -b 0 -u gitea
 #查看服务列表与状态
 systemctl list-units --type=service
 #在开机时禁用一个服务
 systemctl disable postfix.service
 #查看服务是否开机启动
 systemctl is-enabled postfix.service
 #查看已启动的服务列表
 systemctl list-unit-files | grep enabled
#查看启动失败的服务列表
 systemctl --failed

7.升级Gitea最新版本
通过停止程序,替换 /usr/local/bin/gitea 并重启来更新到新版本。直接替换可执行程序时不要更改或使用新的文件名称,以避免数据出错。

8.WEB配置Gitea
Gitea默认端口3000,初次打开http://YOUR_DOMAIN_IR_IP:3000会提示进行配置

9.故障排查
1.若Gitea服务崩溃,先停止服务,检查EMMC是否error变成ro(read only)。若是则输入 mount –o remount,rw /
重新挂载。或reboot系统自动重新挂载(注:重启系统后立即停止服务,避免EMMC再次变成ro)
2.重新执行chown和chmod赋予git用户权限
3.若重启服务还是不行则重新下载Gitea二进制文件替换,并执行以上操作

本文标签: ArmbianGitea