gogs 二进制安装
系统centos7.6
[ ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
gogs要求mysql的版本>=mysql5.7
服务器mysql版本5.7.28。mysql采用的是二进制安装,此处省略安装过程
/usr/local/mysql/bin/mysql -V /usr/local/mysql/bin/mysql Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using EditLine wrapper
git服务端和客户端均需版本 >= 1.7.1
centos7.6默认已经安装好git,且 git版本如下: [ ~]# /usr/bin/git --version git version 1.8.3.1
服务器关闭selinux,服务器开启iptables,放行gogs服务默认的3000端口
二、gogs安装部署
2.1创建gogs库
登录MySQL创建gogs库,新建用户用来访问gogs数据库
DROP DATABASE IF EXISTS gogs; CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; grant all on gogs.* to ‘127.0.0.1‘ identified by ‘gogsABC9paswd‘;flush privileges;
2.2创建git系统用户,并设置密码
建议使用 git 系统用户,因为 gogs 配置文件默认使用的 git 用户来启动gogs服务
useradd git ;passwd git
2.3下载二进制gogs安装包解压安装
切到git系统账户下载二进制gogs安装包
[ ~]$su - git [ ~]$wget https://dl.gogs.io/0.11.91/gogs_0.11.91_linux_amd64.tar.gz [ ~]$ tar xf gogs_0.11.91_linux_amd64.tar.gz [ ~]$ ls gogs gogs_0.11.91_linux_amd64.tar.gz [ ~]$ cd gogs [ gogs]$ ls gogs LICENSE public README.md README_ZH.md scripts templates [ gogs]$
切回root账户,拷贝文件和服务,采用下面2种启动方式启动gogs服务:
[ ~]# cp /home/git/gogs/scripts/init/centos/gogs /etc/init.d/gogs [ ~]# chmod +x /etc/init.d/gogs [ ~]# cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
启动gogs服务,让gogs服务开机自启动:
[ ~]# systemctl enable gogs.service Created symlink from /etc/systemd/system/multi-user.target.wants/gogs.service to /etc/systemd/system/gogs.service. [ ~]# systemctl status gogs.service ● gogs.service - Gogs Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: disabled) Active: inactive (dead) [ ~]# [ ~]# systemctl start gogs.service [ ~]# systemctl start gogs [ ~]# ss -lntup|grep gogs tcp LISTEN 0 128 :::3000 :::* users:(("gogs",pid=9982,fd=3))
默认端口是3000,代表启动成功
2.4浏览器访问如下链接进行安装注册gogs服务
http://60.110.176.59:3000/install
提示:
管理员账户在注册时可以设置也可以不设置,要是在注册时,不设置管理员账户的话,首次注册的账户即为管理员账户
首次注册是gogs服务默认的端口为3000,当然这个端口是可以修改的。
2.5修改gogs服务端口
当gogs注册完成后会自动在服务器上生成一个app.ini的配置文件,修改次配置文件中的端口,重启gogs服务即可
修改前:
[ ~]$ grep 3000 /home/git/gogs/custom/conf/app.ini HTTP_PORT = 3000 ROOT_URL = http://60.110.176.59:3000/
修改后的端口:
[ ~]# grep 20891 /home/git/gogs/custom/conf/app.ini HTTP_PORT = 20891 ROOT_URL = http://60.110.176.59:20891/
切到root账户下,重启gogs服务生效:
[ ~]# /etc/init.d/gogs restart Restarting gogs (via systemctl): [ 确定 ] [ ~]# ss -lntup|grep gogs tcp LISTEN 0 128 :::20891 :::* users:(("gogs",pid=3227,fd=6))
iptables放行端口20891
输入管理员登录账户和密码登录:
http:///60.110.176.59:20891/
gogs二进制安装注册到此完成
2.6采用域名方式访问gogs服务
提示:要是采用域名方式登录的话,配置下nginx的反向代理即可实现,nginx配置文件如下:
[ vhost]# cat gogs.conf server { listen 80; server_name gogs.hhllyt.com; location / { proxy_pass http://127.0.0.1:20891; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }
参考资料:
https://www.tisnz.com/2019/04/03/gogs-install/
https://www.cnblogs.com/hoxis/p/11462959.html
https://blog.51cto.com/13043516/2124597