硬件設備
- 樹莓派3B、128G內存卡
- 讀卡器
樹莓派系統安裝和配置
- 使用SDCardFormatter對內存卡進行格式化。
- 下載樹莓派ubuntu18.04服務器版系統,下載地址
- 使用
Win32DiskImager
或者balenaetcher將鏡像寫入到tf卡中。 - 系統安裝完成後默認用戶名密碼均爲
ubuntu
,系統ssh服務默認打開。 - 通過修改
/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
- 使用
apt-get update
和apt-get upgrade
更新源以及系統,如果官方源比較慢可以換成中科大或者清華的源,網上有很多教程,這裏不贅述。
配置Gogs
- 安裝nginx
apt-get install nginx
- 安裝git
apt-get install git
- 安裝mysql
apt-get install mysql-server
- 下載樹莓派版Gogs,通過二進制文件安裝(這裏我的樹莓派3B選armv6的)下載地址
- 初始化mysql數據庫
> cd gogs/scripts
> mysql -u root -p < mysql.sql
- 啓動gogs配置頁面
> ./gogs web
程序啓動後,可通過http://ip:3000
來訪問完成配置。二進制安裝配置
- 開啓後臺運行,
nohup ./gogs web &
- 開機自動運行
編輯/home/ubuntu/gogs/scripts/systemd
裏面的gogs.service
文件,將文件中的用戶和目錄參數修改爲你自己的設置。cp /home/ubuntu/gogs/scripts/systemd/gogs.service /usr/lib/systemd/system/ #拷貝到系統服務目錄 sudo systemctl enable xxxx.service #註冊服務
- 重啓,發現已經可以自動啓動了。
部署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)
- 對於自簽證書使用GitHubDesktop無法Clone的問題可以嘗試在本地安裝git。
- 安裝完之後使用管理員運行
cmd
執行以下命令:git config --system http.sslbackend openssl git config --global http.sslVerify false