自己搭建git server,從網(wǎng)上搜索似乎非常簡單, 只需要簡單的幾步就能完成. 但這樣的git server 只有最基本的功能, 沒有PR, 沒有Wiki, 沒有web端, 不適合工程用.
經(jīng)過一番搜索, 找到了gitea這個(gè)神器
Ubuntu安裝 gitea
很簡單,
- 首先確保安裝了數(shù)據(jù)庫, 我選擇了mysql:
#更新源
sudo apt-get update
#安裝, 安裝過程中會詢問root用戶名和密碼,自己設(shè)置即可
sudo apt-get install mysql-server
#啟動
systemctl start mysql
#隨系統(tǒng)啟動
systemctl enable mysql
# 登陸mysql shell
/usr/bin/mysql -u root -p
# 建立gitea數(shù)據(jù)庫, 注意, gitea數(shù)據(jù)庫的charset必須是`utf8-geleral-ci`
CREATE DATABASE IF NOT EXISTS gitea DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
至此數(shù)據(jù)庫安裝完成
- 測試安裝gitea, 先體驗(yàn)一下:
找到一個(gè)合適的位置,運(yùn)行:
# 這是目前l(fā)inux最新版本(1.6)的二進(jìn)制文件
sudo wget -O gitea https://dl.gitea.io/gitea/1.6/gitea-1.6-linux-amd64
# 賦予權(quán)限
sudo chmod +x gitea
# 運(yùn)行以下命令就可以開始測試了, 建議在一個(gè)測試文件夾中完成這個(gè)工作,因?yàn)槲覀儺吘故且猿煞?wù)的
./gitea web
這時(shí),打開http://localhost:3000
將會看到gitea的初始頁面:
gitea的初始頁面
# 更新源
sudo apt-get update
# 安裝git
sudo apt install git
# 添加git用戶用來運(yùn)行g(shù)itea
sudo adduser --system --shell /bin/bash --gecos 'Gitea user' --group --disabled-password --home /home/git git
# 建立所需的文件夾結(jié)構(gòu)并賦予權(quán)限
sudo mkdir -p /home/git/gitea/{custom,data,indexers,public,log}
sudo chown git:git /home/git/gitea/{custom,data,indexers,public,log}
sudo chmod 750 /home/git/gitea/{custom,data,indexers,public,log}
sudo chown git:git /home/git/gitea
# 可以把測試時(shí)的安裝包c(diǎn)opy進(jìn)來或者重新下載
cd /home/git/gitea
sudo wget -O gitea https://dl.gitea.io/gitea/1.6/gitea-1.6-linux-amd64
sudo chmod +x gitea
# 安裝服務(wù), github上又一個(gè)示范配置文件,我們先下載下來
cd /home/git/gitea
sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service
sudo nano gitea.service
可看到以下內(nèi)容:
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service
[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/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
對其中的重要內(nèi)容進(jìn)行修改:
Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
# 使用mysql
After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service
[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=/home/git/gitea/
# 此處要改
ExecStart=/home/git/gitea/gitea web -c /home/git/gitea/custom/conf/app.ini
Restart=always
# 此處要改
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/home/git/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
Save (ctrl+o) and close (ctrl+x) the editor.
# 添加服務(wù)軟連接
sudo ln -s /home/git/gitea/gitea.service /lib/systemd/system/gitea.service
sudo systemctl daemon-reload
# 啟動并檢查服務(wù)狀態(tài)
sudo systemctl start gitea
sudo systemctl status gitea
# 如果服務(wù)沒有啟動, 查看日志文件
sudo journalctl -u gitea
# 添加開機(jī)啟動
sudo systemctl enable gitea
sudo systemctl is-enabled gitea
這樣就安裝好了gitea
image.png
- 一鍵安裝(沒試過,建議不要用)
https://git.coolaj86.com/coolaj86/gitea-installer.sh