第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