CentOS7下gogs安装总结 - 低调的狮子 - 博客园

一、使用yum安装Git:

sudo yum install git

二、添加git用户:

sudo useradd git

三、查看CentOS内核版本,确定架构(x64、x86还是arm)

uname -a  

四、下载与其对应的二进制安装包:

wget https://dl.gogs.io/0.11.34/linux_amd64.tar.gz

五、将安装包解压至git用户目录下(/home/git)并修改其权限和所有者:

sudo tar -xf linux_amd64.tar.gz -C /home/git
sudo chmod -R 700 /home/git/gogs
sudo chown -R git:git /home/git/gogs

六、使用git用户运行gogs:

sudo su - git -c "cd /home/git/gogs && ./gogs web &"

七、使用浏览器访问http://IP:3000,完成配置安装,建议使用SQLite:

  按需求自行配置(此处略)

八、添加启动项和守护进程:

sudo ln -sf /home/git/gogs/scripts/systemd/gogs.service /usr/lib/systemd/
sudo chmod u+x /home/git/gogs/scripts/systemd/gogs.service
sudo ln -sf /home/git/gogs/scripts/init/centos/gogs /etc/init.d/
sudo chmod u+x /home/git/gogs/scripts/init/centos/gogs
sudo /sbin/chkconfig gogs on
sudo service gogs restart

亲测

Welcome to Alibaba Cloud Elastic Compute Service !

[root@izwz96m2zz9b7rc6veo8mwz ~]# ln -sf /home/install/gogs/scripts/systemd/gogs.service /usr/lib/systemd/
[root@izwz96m2zz9b7rc6veo8mwz ~]# chmod u+x /home/install/gogs/scripts/systemd/gogs.service 
[root@izwz96m2zz9b7rc6veo8mwz ~]# ln -sf /home/install/gogs/scripts/init/
centos/  debian/  freebsd/ gentoo/  openbsd/ suse/    
[root@izwz96m2zz9b7rc6veo8mwz ~]# ln -sf /home/install/gogs/scripts/init/centos/gogs /etc/init.d/
[root@izwz96m2zz9b7rc6veo8mwz ~]# chmod u+x /home/install/gogs/scripts/init/centos/gogs 
[root@izwz96m2zz9b7rc6veo8mwz ~]# chkconfig gogs on
[root@izwz96m2zz9b7rc6veo8mwz ~]# service gogs start
Starting gogs (via systemctl):                             [  OK  ]
[root@izwz96m2zz9b7rc6veo8mwz ~]# 

如果要域名访问

server {
  listen *:80;
  listen 443 ssl http2;
  ssl_certificate /usr/local/nginx/conf/ssl/gitlab.t-salon.cc.crt;
  ssl_certificate_key /usr/local/nginx/conf/ssl/gitlab.t-salon.cc.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_buffer_size 1400;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name gitlab.t-salon.cc;
  # don't show the version number, a security best practice
  server_tokens off;
  # Increase this if you want to upload large attachments
  # Or if you want to accept large git objects over http
  client_max_body_size 250m;
  #access_log off;
  # individual nginx logs for this gitlab vhost
  access_log  /home/install/gogs/nginx/gitlab_access.log;
  error_log   /home/install/gogs/nginx/gitlab_error.log;
  #index index.html index.htm index.php;
  # root /data/wwwroot/gitlab.t-salon.cc;
  # root /opt/gitlab/embedded/service/gitlab-rails/public;
  # if ($ssl_protocol = "") { return 301 https://$host$request_uri; }

  #include /usr/local/nginx/conf/rewrite/none.conf;
  #error_page 404 /404.html;
  #error_page 502 /502.html;


  location ~ { # 如果你希望通过子路径访问,此处修改为子路径,注意以 / 开头并以 / 结束
    proxy_pass http://0.0.0.0:3000;
    include proxy.conf;
  }
}

proxy.conf

proxy_connect_timeout 300s;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

到此为止,Centos7下gogs的配置基本完成,如果想了解更多信息,还请移步https://gogs.io/docs/advanced/configuration_cheat_sheet  

注:如果SELinux和firewall处于打开状态,请注意相应规则的配置。  

反思和总结:

  由于不熟悉gogs在实际配置过程中犯了以下几个错误,和大家共勉一下:

  1、应当先完成install安装再进行启动项和守护进程配置;

  2、配置systemd时需要同时两个文件,因为对网上一篇文章的误解,没有坚持下去,最后配置失败后才绕回来;

  3、在摸索过程中,盲目的运行过script目录下各种安装脚本,导致安装文件混乱不堪(部分程序文件丢失),期间各种安装失败,折腾大半天后,在意外检查程序目录时才发现已损坏;

  4、运行安装脚本时错误的使用root权限运行导致安装后文件权限的各种问题;

  5、首次下载安装包时,下载了错误版本的安装包,非常低级的问题;

  6、对git用户的登录权限进行了过于严格控制,导致push的时候无法上传;

  7、应该在gogs目录下运行./gogs web这点非常重要,因为之前未注意,在/home/git下执行,导致data目录位置生成路径错误。

标签: CentOS7, gogs


原网址: 访问
创建于: 2018-10-27 01:08:22
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论