從零開始搭建gitea代碼管理平臺

Gitea,一款極易搭建的Git自助服務。如其名,Git with a cup of tea。跨平臺的開源服務,支持Linux、Windows、macOS和ARM平臺。配置要求低,甚至可以運行在樹莓派上。

搭建之前,首先提示兩個坑:

1、gitea不支持Centos6和更早的版本內核。

2、gitea不能在root下運行,必須是普通用戶權限。

 不確定是否使用gitea服務的,可以看一下官網功能對比。

https://docs.gitea.io/zh-cn/comparison/

一、選擇安裝環境

我這邊是物理主機服務器,安裝的Centos7。

[xxx@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[xxx@localhost ~]# uname -sr
Linux 3.10.0-1160.62.1.el7.x86_64

 

二、下載gitea

這個很簡單,直接去官網下載二進制或者去github上下載。

[xxx@localhost gitea]# wget -O gitea https://dl.gitea.io/gitea/1.16.8/gitea-1.16.8-linux-amd64
[xxx@localhost gitea]# chmod +x gitea

這裏我用二進制方式運行的。也可以用docker方式運行。

 

三、安裝git

安裝git,並配置環境變量,否則失敗。

[xxx@localhost data]# yum install git

創建一個git用戶,專門用來管理git相關服務。

sudo useradd \
   --system \
   --shell /bin/bash \
   --comment 'Git Version Control' \
   --create-home \
   --home /home/git \
   git
git用戶設置密碼
[xxx@localhost data]# passwd git
Changing password for user git.
New password:

 

四、創建gitea相關目錄

創建gitea工作目錄:

[xxx@localhost data]# pwd
/data
[xxx@localhost data]# mkdir gitea
[xxx@localhost data]# chown -R git:git gitea/
[xxx@localhost data]# ls -lth
total 0
drwxr-xr-x 2 git  git   6 Jun  1 16:02 gitea

創建gitea 可執行文件存放目錄

[xxx@localhost opt]# chown -R git:git gitea/
[xxx@localhost opt]# ls -lth
total 0
drwxr-xr-x  2 git  git  19 May 31 16:34 gitea

 

五、測試gitea服務

[xxx@localhost gitea]$ ./gitea web

從web打開 http://服務器IP:3000/ ,可進行配置更改和安裝。

 

六、安裝

下載服務配置文件

sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service -P /etc/systemd/system/

更改gitea配置文件

[xxx@localhost system]# vim /etc/systemd/system/gitea.service

# 更改路徑如下:
WorkingDirectory=/data/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=/opt/gitea/gitea web --config /data/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/data/gitea

啓動gitea服務

[xxx@localhost opt]# systemctl daemon-reload
[xxx@localhost opt]# systemctl enable --now gitea
[xxx@localhost opt]#
[xxx@localhost opt]# systemctl status gitea
● gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-06-01 17:19:01 CST; 3s ago
 Main PID: 10567 (gitea)
    Tasks: 29
   Memory: 153.5M
   CGroup: /system.slice/gitea.service
           └─10567 /opt/gitea/gitea web --config /data/gitea/app.ini

Jun 01 17:19:01 localhost.localdomain gitea[10567]: 2022/06/01 17:19:01 ...s/install/setting.go:21:PreloadSettings() [I] AppPa.../giteaJun 01 17:19:01 localhost.localdomain gitea[10567]: 2022/06/01 17:19:01 ...s/install/setting.go:22:PreloadSettings() [I] AppWo.../giteaJun 01 17:19:01 localhost.localdomain gitea[10567]: 2022/06/01 17:19:01 ...s/install/setting.go:23:PreloadSettings() [I] Custo...customJun 01 17:19:01 localhost.localdomain gitea[10567]: 2022/06/01 17:19:01 ...s/install/setting.go:24:PreloadSettings() [I] Log p...ea/logJun 01 17:19:01 localhost.localdomain gitea[10567]: 2022/06/01 17:19:01 ...s/install/setting.go:25:PreloadSettings() [I] Confi...pp.iniJun 01 17:19:01 localhost.localdomain gitea[10567]: 2022/06/01 17:19:01 ...s/install/setting.go:26:PreloadSettings() [I] Prepa...l pageJun 01 17:19:01 localhost.localdomain gitea[10567]: 2022/06/01 17:19:01 ...s/install/setting.go:29:PreloadSettings() [I] SQLit...portedJun 01 17:19:02 localhost.localdomain gitea[10567]: 2022/06/01 17:19:02 cmd/web.go:208:listen() [I] Listen: http://0.0.0.0:3000
Jun 01 17:19:02 localhost.localdomain gitea[10567]: 2022/06/01 17:19:02 cmd/web.go:212:listen() [I] AppURL(ROOT_URL): http://l...:3000/Jun 01 17:19:02 localhost.localdomain gitea[10567]: 2022/06/01 17:19:02 ...s/graceful/server.go:61:NewServer() [I] Starting ne... 10567Hint: Some lines were ellipsized, use -l to show in full.
打開web進行安裝 http://服務器IP:3000/  。
選擇使用sqlite,數據庫文件路徑  /data/gitea/gitea.db

其他的更改:

倉庫根目錄 /data/gitea/gitea-repositories
LFS根目錄 /data/gitea/lfs

然後添加一個添加管理員賬號:

用戶名 youname
密碼 youcode
Email: [email protected]

點擊開始安裝,很快就搞定了。

 

七、可以愉快的玩耍了

由於更換了端口號,現在用瀏覽器打開新的地址 

http://server_ip:new_port/

接下來,創建組織,創建團隊,註冊用戶賬號。玩起來。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章