樹莓派3b+Ubuntu18.04+gogs搭建git服務

硬件設備

  1. 樹莓派3B、128G內存卡
  2. 讀卡器

樹莓派系統安裝和配置

  1. 使用SDCardFormatter對內存卡進行格式化。
  2. 下載樹莓派ubuntu18.04服務器版系統,下載地址
  3. 使用Win32DiskImager或者balenaetcher將鏡像寫入到tf卡中。
  4. 系統安裝完成後默認用戶名密碼均爲ubuntu,系統ssh服務默認打開。
  5. 通過修改/etc/netplan目錄中的類似命名爲50-cloud-init.yaml文件可已修改靜態IP,修改完之後使用sudo netplan apply。(可選)
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        eth0:
            dhcp4: false
            addresses: [172.16.1.118/24]
            gateway4: 172.16.1.1
            nameservers: 
                     addresses: [8.8.8.8,9.9.9.9]
    version: 2
  1. 使用apt-get updateapt-get upgrade更新源以及系統,如果官方源比較慢可以換成中科大或者清華的源,網上有很多教程,這裏不贅述。

配置Gogs

  1. 安裝nginx apt-get install nginx
  2. 安裝git apt-get install git
  3. 安裝mysql apt-get install mysql-server
  4. 下載樹莓派版Gogs,通過二進制文件安裝(這裏我的樹莓派3B選armv6的)下載地址
  5. 初始化mysql數據庫
> cd gogs/scripts
> mysql -u root -p < mysql.sql
  1. 啓動gogs配置頁面
> ./gogs web

在這裏插入圖片描述
程序啓動後,可通過http://ip:3000來訪問完成配置。二進制安裝配置

  1. 開啓後臺運行,nohup ./gogs web &
  2. 開機自動運行
    編輯/home/ubuntu/gogs/scripts/systemd裏面的gogs.service文件,將文件中的用戶和目錄參數修改爲你自己的設置。
    cp /home/ubuntu/gogs/scripts/systemd/gogs.service  /usr/lib/systemd/system/  #拷貝到系統服務目錄
    sudo systemctl enable xxxx.service #註冊服務
    
  3. 重啓,發現已經可以自動啓動了。

部署HTTPS證書

生成證書,如下修改``文件,重啓服務即可。

[server]
DOMAIN           = your ip 
HTTP_PORT        = 3000
PROTOCOL         = https
ROOT_URL         = https://your ip :3000/
CERT_FILE        = /path/server-cert.pem
KEY_FILE         = /path/server-key.pem
DISABLE_SSH      = false
SSH_PORT         = 22
START_SSH_SERVER = false
OFFLINE_MODE     = false

結束

(2020.02.16)


補充一(2020.02.16)

  1. 對於自簽證書使用GitHubDesktop無法Clone的問題可以嘗試在本地安裝git
  2. 安裝完之後使用管理員運行cmd執行以下命令:
    git config --system http.sslbackend openssl
    git config --global http.sslVerify false
    
發佈了15 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章