第1步 - 更新和升級系統
運行下面的apt命令。
sudo apt update
sudo apt upgrade
第2步 - 安裝Git
使用下面的 apt
命令從庫中安裝 Git,並創建系統用戶 git,
sudo apt install git
sudo adduser --disabled-login --gecos 'Gogs' git
切換至 git
賬戶並且創建名爲 git
的目錄。
su - git
mkdir -p /home/git
切換到 git
目錄,依照下方所展示的內容,使用 wget
命令下載 Go(最新版)。
cd /home/git
wget https://dl.gogs.io/0.11.86/gogs_0.11.86_linux_amd64.tar.gz
若 wget 未安裝 則需要 安裝命令
sudo apt install wget
下載完成解壓
tar -xf gogs_0.11.86_linux_amd64.tar.gz
切換回root用戶
su root
輸入密碼 ,
這一步,我們將在 Debian Stretch 系統上配置 Gogs 服務器。我們會在 /etc/systemd/system
目錄下創建一個新的服務器配置文件 gogs.service
。
切換到 /etc/systemd/system
目錄,使用 cp命令拷貝服務器配置文件 gogs.service
。
cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/gogs.service
也可以自行創建
cd /etc/systemd/system
vim gogs.service
文件內容
[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=mariadb.service mysqld.service postgresql.service memcached.service 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
Type=simple
User=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
Environment=USER=git HOME=/home/git
# Some distributions may not support these hardening directives. If you cannot start the service due
# to an unknown option, comment out the ones not supported by your version of systemd.
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
保存並退出。
重載系統服務器,並設置 Gogs 服務器爲開機自啓動。
systemctl daemon-reload
systemctl start gogs
systemctl enable gogs
使用下面的命令開啓 Gogs 服務器並設置爲開機啓動。 Gogs 服務器現在已經運行在你的 Debian 系統上了。
使用下面的命令檢測:
netstat -lnptu
systemctl status gogs
root@Debian:~# netstat -lnptu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN 559/java
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN 559/java
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 559/java
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 686/nginx: master p
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 817/sshd
tcp6 0 0 :::33060 :::* LISTEN 661/mysqld
tcp6 0 0 :::3306 :::* LISTEN 661/mysqld
tcp6 0 0 :::80 :::* LISTEN 686/nginx: master p
tcp6 0 0 :::3000 :::* LISTEN 1723/gogs
udp 0 0 0.0.0.0:68 0.0.0.0:* 462/dhclient
udp 0 0 127.0.0.1:323 0.0.0.0:* 547/chronyd
udp6 0 0 ::1:323 :::* 547/chronyd
root@Debian:~# systemctl status gogs
● gogs.service - Gogs
Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-06-20 14:12:07 CST; 21min ago
Main PID: 1723 (gogs)
CGroup: /system.slice/gogs.service
└─1723 /home/git/gogs/gogs web
Jun 20 14:15:12 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:12: Completed GET /org/create 200 OK in 3.476298ms
Jun 20 14:15:17 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:17: Started POST /org/create for 116.52.95.115
Jun 20 14:15:17 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:17: Completed POST /org/create 200 OK in 3.248238ms
Jun 20 14:15:36 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:36: Started POST /org/create for 116.52.95.115
Jun 20 14:15:36 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:36: Completed POST /org/create 302 Found in 15.592257ms
Jun 20 14:15:36 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:36: Started GET /org/kunming_note_liability/dashboard for 116.52.95.115
Jun 20 14:15:36 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:36: Completed GET /org/kunming_note_liability/dashboard 200 OK in 11.278073ms
Jun 20 14:15:37 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:37: Started GET /avatars/2 for 116.52.95.115
Jun 20 14:15:37 Debian gogs[1723]: [Macaron] [Static] Serving /2
Jun 20 14:15:37 Debian gogs[1723]: [Macaron] 2019-06-20 14:15:37: Completed GET /avatars/2 200 OK in 152.695µs
如果是阿里雲 騰訊雲 這類服務器 記得打開3000端口成安全策略組哦
如果不想安裝數據 直接選擇SQLite3