**1. 环境** CentOS 7 **2. 安装MariaDB** ```bash # 安装 yum -y install mariadb mariadb-server # 启动MariaDB systemctl start mariadb.service # 设置开机启动(可选 systemctl enable mariadb.service # 停止MariaDB systemctl stop mariadb.service # 设置开机自启关闭 systemctl disenable mariadb.service # 进行数据库安全设置 mysql_secure_installation # 数据库登录 mysql -uroot -p ``` **3. 安装gogs** - gogs地址:https://dl.gogs.io/ - 下载需要版本的gogs包 ```bash 此处使用0.11.4的包 [gogs0.11.4_amd64.tar.gz](http://erica.kkwen.cn/usr/uploads/2019/03/1195550822.gz) ``` - gogs以git用户运行 ```bash [root@ _21_ ~]# useradd git [root@ _22_ ~]# id git uid=1002(git) gid=1003(git) 组=1003(git) [root@ _23_ ~]# mv gogs0.11.4_amd64.tar.gz /home/git/ [root@ _24_ ~]# ls /home/git/ gogs0.11.4_amd64.tar.gz [root@ _25_ ~]# su - git [git@localhost ~]$ ls gogs0.11.4_amd64.tar.gz [git@localhost ~]$ tar xf gogs0.11.4_amd64.tar.gz [git@localhost ~]$ ls gogs gogs0.11.4_amd64.tar.gz [git@localhost ~]$ cd gogs [git@localhost gogs]$ ls gogs LICENSE public README.md README_ZH.md scripts templates ``` - 初始化数据库 ```bash # 创建gogs数据库 [git@localhost gogs]$ mysql -uroot -p < scripts/mysql.sql # 为gogs数据库创建用户gogs,并授权 [git@localhost gogs]$ mysql -uroot -p MariaDB [(none)]> grant all on gogs.* to 'gogs'@'%' identified by 'gogs'; MariaDB [(none)]> flush privileges; ``` - 配置 ```bash [git@localhost gogs]$ ls gogs LICENSE public README.md README_ZH.md scripts templates [git@localhost gogs]$ mkdir -p custom/conf [git@localhost gogs]$ cd custom/conf [git@localhost conf]$ touch app.ini [git@localhost conf]$ vim app.ini # 输入下面的配置文件 ``` ``` APP_NAME = erica RUN_USER = git RUN_MODE = dev [server] HTTP_ADDR = 0.0.0.0 HTTP_PORT = 5000 [database] DB_TYPE = mysql HOST = 127.0.0.1:3306 NAME = gogs USER = gogs PASSWD = gogs [security] INSTALL_LOCK = false SECRET_KEY = f9d02fa9-3509-43ab-8b9d-0e8f53bc5a84 ``` - 在gogs文件夹下创建log文件夹,否则gogs不能启动 ```bash [git@localhost gogs]$ mkdir log ``` - 启动 ```bash [root@ _29_ ~]# cp /home/git/gogs/scripts/init/centos/gogs /etc/init.d/ [root@ _30_ ~]# chmod +x /etc/init.d/gogs [root@ _31_ ~]# chkconfig gogs on [root@ _32_ ~]# chkconfig --list gogs gogs 0:关 1:关 2:开 3:开 4:开 5:开 6:关 [root@ _33_ ~]# systemctl start gogs [root@ _34_ ~]# ss -tanl [root@ _35_ ~]# ps aux | grep gogs ``` - 首次登录 http://ip:5000/install  输入数据库密码点击下面的 立即安装 然后需要注册第一个用户,这个用户自动成为管理员 在gogs里面,无论第一个用户是什么,这个用户一旦创建,他在数据库中的id是1,这个id是1的用户自动称为管理员 - 使用 使用时创建第二个用户,为普通用户,创建后登录  **3. gogs问题解决** (1) 打开网页很慢 - 原因 ```bash # 日志中我们可以看到 [git@localhost log]$ tail -f gogs.log 2019/03/26 13:25:10 [ WARN] AvatarLink.LibravatarService.FromEmail [test@qq.com]: lookup _avatars-sec._tcp.qq.com on 114.114.114.114:53: read udp 192.168.11.131:57101->114.114.114.114:53: i/o timeout ``` 访问不到gravatar.com的头像服务导致 - 解决办法 禁用gravatar的服务,使用本地头像,修改配置文件 ```bash [git@localhost gogs]$ vim custom/conf/app.ini [picture] DISABLE_GRAVATAR = true ENABLE_FEDERATED_AVATAR = true # 重启gogs [root@ _43_ ~]# systemctl restart gogs ``` 也可在install的时候就禁用gravatar服务  最后修改:2019 年 08 月 21 日 11 : 15 AM © 著作权归作者所有