【gitlab】gitlab快速部署教程

gitlab快速部署教程

部署环境

  • Ubuntu 16.04(亲测可用)

开始部署

安装依赖

sudo apt-get install curl openssh-server ca-certificates postfix

执行完成后,出现邮件配置,选择Internet那一项(不带Smarthost的)

下载软件包

下载页面: https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/

可以自行选择想要部署的版本,使用命令curl进行下载

curl -O https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/gitlab-ce_11.3.6-ce.0_amd64.deb

安装软件包

sudo dpkg –i gitlab-ce_11.3.6-ce.0_amd64.deb

如果安装过程出现错误则需要自行解决依赖等问题(笔者安装时一切正常)

配置生成

sudo gitlab-ctl reconfigure

初次安装使用请一定记得生成配置

检查

输入以下命令检查是否安装正确

sudo gitlab-ctl status

出现类似以下的结果,则说明运行正常

run: gitlab-workhorse: (pid 1148) 884s; run: log: (pid 1132) 884s  
run: logrotate: (pid 1150) 884s; run: log: (pid 1131) 884s 
run: nginx: (pid 1144) 884s; run: log: (pid 1129) 884s 
run: postgresql: (pid 1147) 884s; run: log: (pid 1130) 884s
run: redis: (pid 1146) 884s; run: log: (pid 1133) 884s 
run: sidekiq: (pid 1145) 884s; run: log: (pid 1128) 884s   
run: unicorn: (pid 1149) 885s; run: log: (pid 1134) 885s

 使用

使用的时候,系统管理员账户名称为root,需要先设置一个root账户密码。

如果出现502错误的话,则将以下文件的读权限打开

sudo chmod -R o+x /var/opt/gitlab/gitlab-rails

配置调整

部署域名调整

编辑配置文件

sudo nano /etc/gitlab/gitlab.rb

将内部的external_url修改为自己的部署域名,例如:

  • 如果是局域网直接ip访问的话,设置为http://xxx.xxx.xxx.xxx即可
  • 如果是外网通过域名访问的话,设置为http://your.domain-name.com

然后,重新生成配置

sudo gitlab-ctl reconfigure

自行使用nginx部署

实际上,这个快速部署的软件包内是自带nginx的,然而实际服务器部署的话,我们常常需要部署在系统原生的nginx上,我们可以按照这样的方式进行操作:

nginx配置文件中添加配置:

# gitlab socket 文件地址
upstream gitlab {
  # 7.x 版本在此位置
  # server unix:/var/opt/gitlab/gitlab-rails/tmp/sockets/gitlab.socket;
  # 8.0+ 版本位置(11.x版本亲测可用)
  server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
}

server {
  listen *:80;

  server_name gitlab.liaohuqiu.com;   # 请修改为你的域名

  server_tokens off;     # don't show the version number, a security best practice
  root /opt/gitlab/embedded/service/gitlab-rails/public;

  # 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;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/gitlab/nginx/gitlab_access.log;
  error_log   /var/log/gitlab/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    # If you use https make sure you disable gzip compression 
    # to be safe against BREACH attack

    proxy_read_timeout 300; # Some requests take more than 30 seconds.
    proxy_connect_timeout 300; # Some requests take more than 30 seconds.
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header   X-Frame-Options   SAMEORIGIN;

    proxy_pass http://gitlab;
  }

  # Enable gzip compression as per rails guide: http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  # WARNING: If you are using relative urls do remove the block below
  # See config/application.rb under "Relative url support" for the list of
  # other files that need to be changed for relative url support
  location ~ ^/(assets)/  {
    root /opt/gitlab/embedded/service/gitlab-rails/public;
    # gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  error_page 502 /502.html;
}

编辑gitlab配置文件

sudo nano /etc/gitlab/gitlab.rb

禁用掉自带的nginx(如果原本没有这句话的话需要加上)

nginx['enable'] = false

重启nginx,重启gitlab服务

sudo /usr/local/nginx/sbin/nginx -s reload
sudo gitlab-ctl reconfigure

同样的,如果再次出现502错误的话,需要修改一下配置

sudo chmod -R o+x /var/opt/gitlab/gitlab-rails

转载于:https://www.cnblogs.com/HansBug/p/9813627.html

你可能感兴趣的:(【gitlab】gitlab快速部署教程)