1 环境准备

1.1 机器要求

要求:
2 核 CPU +/512MB+ 内存/Mysql:5.7+/git:1.8.3+

操作系统:Centos7

hostname host IP 作用
gogs gogs.local.com 192.168.8.182 代码版本管理

1.2 hostname

[root@base ~]# hostnamectl set-hostname gogs --static
[root@base ~]# echo "192.168.8.182 gogs.local.com" >> /etc/hosts

1.3 网络设置

[root@base1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO="static" #dhcp改为static 
ONBOOT="yes" #开机启用本配置
IPADDR=192.168.8.182 #静态IP
GATEWAY=192.168.8.2 #默认网关
NETMASK=255.255.255.0 #子网掩码
DNS1=114.114.114.114 #DNS 配置
DNS2=8.8.8.8 #DNS 配置

$# reboot

1.4 安装依赖环境

$ yum install wget
$ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
$ yum localinstall mysql57-community-release-el7-8.noarch.rpm
$ yum repolist enabled | grep "mysql.*-community.*"
$ yum install epel-release

1.5 安装mysql,go,git

$ yum install mysql-community-server go git -y
$ git version
git version 1.8.3.1
$ go version
go version go1.15.5 linux/amd64

1.6 查看MySQL运行状态

$ systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html

1.7 查找初始密码并修改密码

[root@gogs ~]# grep "password" /var/log/mysqld.log
2020-12-31T18:43:03.052671Z 1 [Note] A temporary password is generated for root@localhost: I.TfdqsLu6d;
$ mysql -u root -p
Enter password:
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=6;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

1.8 创建库gogs

推荐使用InnoDB引擎。创建库时候选择utf8

$ mysql -u root -p
Enter password:
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=6;
mysql> SET GLOBAL default_storage_engine = 'InnoDB';
mysql> CREATE DATABASE gogs CHARACTER SET utf8 COLLATE utf8_bin;
mysql> create user gogs@'localhost' identified by '123456';
mysql> grant all privileges on gogs.* to gogs@'localhost' identified by '123456';
mysql> FLUSH PRIVILEGES;
mysql>exit;

2 安装配置gogs

# 下载软件包
$ wget https://dl.gogs.io/0.12.3/gogs_0.12.3_linux_amd64.tar.gz
# 解压
$ tar -zxvf gogs_0.12.3_linux_amd64.tar.gz
# 添加git用户
useradd git
$ mv gogs /home/git/

chown -R git:git /home/git/gogs
mkdir /home/git/gogs-repositories
chown -R git:git /home/git/gogs-repositories

3 防火墙开放3000端口

[root@gogs ~]# firewall-cmd --zone=public --list-ports//查看所有开放端口状态
[root@gogs ~]# firewall-cmd --zone=public --add-port=3000/tcp --permanent
success
[root@gogs ~]# firewall-cmd --reload

4 启动服务

# 启动gogs
[root@gogs /]# /home/git/gogs/gogs web &
[1] 1755
[root@gogs /]# 2021/01/01 04:57:58 [ WARN] Custom config "/usr/local/gogs/custom/conf/app.ini" not found. Ignore this warning if you're running for the first time
2021/01/01 04:57:58 [TRACE] Log mode: Console (Trace)
2021/01/01 04:57:58 [ INFO] Gogs 0.12.3
2021/01/01 04:57:58 [TRACE] Work directory: /usr/local/gogs
2021/01/01 04:57:58 [TRACE] Custom path: /usr/local/gogs/custom
2021/01/01 04:57:58 [TRACE] Custom config: /usr/local/gogs/custom/conf/app.ini
2021/01/01 04:57:58 [TRACE] Log path: /usr/local/gogs/log
2021/01/01 04:57:58 [TRACE] Build time: 2020-10-07 03:03:48 UTC
2021/01/01 04:57:58 [TRACE] Build commit: f0e3cd90f8d7695960eeef2e4e54b2e717302f6c
2021/01/01 04:57:58 [ INFO] Run mode: Development
2021/01/01 04:57:58 [ INFO] Listen on http://0.0.0.0:3000
2021/01/01 04:58:16 [TRACE] Session ID: 1489bae95a6a3571
2021/01/01 04:58:16 [TRACE] CSRF Token: WCR4aL2a2EYxKNiTT9f5gOZfL2I6MTYwOTQ0NDY5NjU0MTA5NDIxMw
2021/01/01 04:58:16 [TRACE] Session ID: 1489bae95a6a3571
2021/01/01 04:58:16 [TRACE] CSRF Token: lzzWLbccH-jSndhHVGgIm2MurtU6MTYwOTQ0NDY5NjU0NTg5NzY5OA
2021/01/01 04:58:16 [TRACE] Template: install
[root@gogs ~]# cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
[git@gogs ~]$ systemctl start gogs
[git@gogs ~]$ systemctl enable gogs
[git@gogs ~]$ systemctl status gogs
● gogs.service - Gogs
   Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-01-01 06:10:43 JST; 7s ago
 Main PID: 2256 (gogs)
   CGroup: /system.slice/gogs.service
           └─2256 /home/git/gogs/gogs web

注意:记得注册的第一个用户,就是管理员

  

转自:https://www.jianshu.com/p/910cb32e7abb