wsl2+ubuntu20.04安裝gitea備忘

安裝wsl2

適用于 Linux 的 Windows 子系統安裝指南 (Windows 10)

注意:1909以下的系統一定要先升級才能使用wsl2

自動啟動

wsl2不支持systemd,需要在/etc/init.d下注冊服務腳本。或者使用supervisor
在 Ubuntu 16.04 LTS 中以 service 方式運行

安裝mysql

gitea默認使用mysql,安裝及使用參見mysql文檔

create database gitea;
create user 'gitea'@'%' identified by 'PASSWORD';
grant all privileges on gitea.* to 'gitea'@'%';

安裝gitea

獲取可執行文件

gitea-runable-1.13.2下載gitea的可執行文件,版本任選
若不能從github下載可執行文件,也可以從gitea-github或者鏡像網站gitea-src-mirror下載源碼自行編譯

gitea-${GITEA_VERSION}-linux-amd64是可執行文件,直接運行即可

創建工作環境

創建數據目錄鏈接

如果是使用獨立數據盤,需要進行額外鏈接設置

mkdir -p ${DATA_DIR}
cd /home
ln -s ${DATA_DIR} git

在創建了git用戶后,更改數據目錄權限

chown git:git ${DATA_DIR}

創建git用戶

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

參考 如何在 Ubuntu 18.04 上安裝和配置 Gogs

創建gitea程序安裝環境

mkdir -p ${TOOL_ROOT}/gitea
cp gitea-${GITEA_VERSION}-linux-amd64 ${TOOL_ROOT}/gitea
sudo mkdir -p /opt/gitea
cd /opt/gitea
sudo ln -s ${TOOL_ROOT}/gitea/gitea-${GITEA_VERSION}-linux-amd64 gitea
cd ${TOOL_ROOT}/gitea
chmod 775 gitea-${GITEA_VERSION}-linux-amd64

創建啟動腳本

mkdir -p ${TOOL_ROOT}/gitea/autostart
cd ${TOOL_ROOT}/gitea/autostart
tee gitea.supervisor << EOF
[program:gitea]
directory=/home/git/gitea/
command=/opt/gitea/gitea --work-path /home/git/gitea/workpath --custom-path /home/git/gitea/workpath/custom --config /home/git/gitea/workpath/conf/app.ini web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/home/git/log/gitea/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/home/git/log/gitea/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
user = git
environment = HOME="/home/git", USER="git"
EOF
cd /etc/supervisor/conf.d
ln -s ${TOOL_ROOT}/gitea/autostart/ gitea.supervisor gitea.conf

sudo service supervisor restart

測試gitea啟動命令

因為gitea服務是用git用戶啟動,因此測試gitea的啟動命令是否正確需要使用su或runuser命令。而因為git用戶無法登錄,直接su -l git -c 'command'會報權限錯誤,因此我們需要先通過su命令登錄為root后再使用su或runuser命令以git身份進行操作。

su

輸入密碼登錄為root后

su -l git -c "/opt/gitea/gitea --work-path /home/git/gitea/workpath --custom-path /home/git/gitea/workpath/custom --config /home/git/gitea/workpath/conf/app.ini web"

runuser -l git -c "/opt/gitea/gitea --work-path /home/git/gitea/workpath --custom-path /home/git/gitea/workpath/custom --config /home/git/gitea/workpath/conf/app.ini web"
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容