ubuntu下gitlab以及gitlab-ci安装笔记

今天给一台vps机器安装配置了gitlab以及gitlab-ci,花了大半天的时间,为了不让自己的辛苦再次重复,这里记录一下安装配置过程。以后再安装就快了。 gitlab的web部分使用的是rails写的,所以配置起来还是挺熟悉的。

个人原创,版权所有,转载请注明原文出处,并保留原文链接:

http://www.embbnux.com/2015/09/09/install_gitlab_on_ubuntu/

一 服务器环境介绍

我使用的服务器为一台ubuntu 14.04 vps , 一直用来当作测试机用,上面放了一个rails app,nginx作为web服务,使用postgresql做为数据库,redis为缓存。gitlab对内存消耗较大,如果内存比较少的话要配置下swap.

二 gitlab安装

gitlab有多种安装方式,这里推荐使用omnibus安装,也就是deb安装包

可以直接使用apt-get:

sudo apt-get install curl openssh-server ca-certificates
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce

本来很简单的两句话就该安装好了,可惜国内的网络问题,安装包是从亚马逊的s3下载的,有300m大小,下载速度慢到不得了,于是直接下载安装包安装

wget https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/trusty/gitlab-ce_7.14.1-ce.0_amd64.deb/download
mv download gitlab-ce_7.14.1-ce.0_amd64.deb
dpkg -i gitlab-ce_7.14.1-ce.0_amd64.deb

gitlab的安装包有300m大,是因为里面不止是一个gitlab,还包括ruby,rails,nginx,postgresql,redis等,如果你之前没有装过的话,这里自动安装倒是挺好的,可是之前装过的话,就被新装了一个,不过不会影响旧的安装,只是启动gitlab服务的时候会同时启动两个postgresql以及redis等,不是很好,再多的内存也得被耗掉,所以需要进一步的配置。

gitlab被安装在系统的几个地方:

/etc/gitlab, /var/opt/gitlab,/opt/gitlab,  /home/git/

gitlab的源码主要在 /opt/gitlab/embedded/service下gitlab-rails为gitlab的web端,gitlab-ci为ci的web端,gitlab-shell用于http下git的使用等

三 gitlab配置

这里主要配置gitlab,gitlab-ci的url,以及使用已有的postgres和redis,nginx等服务

首先更改gitlab的配置主要是/etc/gitlab/gitlab.rb

修改下面的地方:

#gitlab网站的地址
external_url 'http://gitlab.embbnux.com'
#gitlab的发信邮箱配置
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['gitlab_email_display_name'] = 'Embbnux.Com GITLAB'

#关闭第三方登录
gitlab_rails['omniauth_enabled'] = false
#ssh的端口,ubuntu默认为22,如果更改过则改为相应的
gitlab_rails['gitlab_shell_ssh_port'] = 23333

#postgresql数据库配置
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_encoding'] = "utf8"
gitlab_rails['db_database'] = "gitlabhq_production"
gitlab_rails['db_pool'] = 5
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = 'password'
gitlab_rails['db_host'] = '127.0.0.1'
gitlab_rails['db_port'] = 5432

#redis配置
gitlab_rails['redis_host'] = "127.0.0.1"
gitlab_rails['redis_port'] = 6379
gitlab_rails['redis_database'] = 0

#使用smtp发送邮件
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.embbnux.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_domain'] = "embbnux.com"
gitlab_rails['smtp_authentication'] = "login"

#unicorn配置
unicorn['worker_timeout'] = 60
unicorn['worker_processes'] = 1
## Advanced settings
unicorn['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'
unicorn['pidfile'] = '/opt/gitlab/var/unicorn/unicorn.pid'

#禁止gitlab自带的postgresql
postgresql['enable'] = false

#禁止gitlab自带的redis
redis['enable'] = false

#禁止gitlab自带的nginx
nginx['enable'] = false
web_server['external_users'] = ['www-data']

#禁止gitlab自带的logrotate
logrotate['enable'] = false

然后使配置生效

sudo gitlab-ctl reconfigure

这个用重新生成gitlab rails的配置

还需要配置一下外部的postgresql以及nginx

ln -s /usr/bin/pg_dump /usr/bin/psql /opt/gitlab/bin/
sudo su - postgres
psql
CREATE USER gitlab WITH PASSWORD 'password';
CREATE DATABASE gitlabhq_production OWNER gitlab;
GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab;

nginx则新增网站配置文件

/etc/nginx/site-enabled/gitlab.conf:


upstream gitlab {
 server unix:///var/opt/gitlab/gitlab-rails/sockets/gitlab.socket fail_timeout=0;
}

server {
 listen *:80;
 server_name gitlab.embbnux.com;
 server_tokens off;
 root /opt/gitlab/embedded/service/gitlab-rails/public;
 client_max_body_size 50m;
 access_log /var/log/gitlab/nginx/gitlab_access.log;
 error_log /var/log/gitlab/nginx/gitlab_error.log;

 location / {
   try_files $uri $uri/index.html $uri.html @gitlab;
 }

location /uploads/ { 
 proxy_read_timeout 300;
 proxy_connect_timeout 300;
 proxy_redirect off;

 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-Forwarded-Proto $scheme;
 proxy_set_header X-Frame-Options SAMEORIGIN;

 proxy_pass http://gitlab;
 }

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-rails

sudo gitlab-rake gitlab:setup
sudo gitlab-ctl restart
sudo service nginx restart

如果你熟悉rails开发上面应该不成问题,访问你的url,如gitlab.embbnux.com就可以开始使用gitlab了,初始管理员用户为root,密码5iveL!fe,需要及时修改,进入后在admin配置更多选项。

四 gitlab-ci配置

gitlab-ci的配置文件为/etc/gitlab/gitlab.rb的后半部分,和之前的配置大同小异,不过这里要配置使用gitlab用户登录:

先root用户进入你的gitlab网站,在admin管理页面application里面新建一个应用获得app_id和app_secret

然后配置文件里面更改如下:

ci_external_url 'http://ci.embbnux.com
gitlab_ci['gitlab_server'] = { "url" = 'http://gitlab.embbnux.com', "app_id" ='app_id', "app_secret" ='app_secret' }

生成配置:sudo gitlab-ctl reconfigure

同样需要在postgresql新建数据库和用户,然后配置nginx,nginx配置:

/etc/nginx/site-enabled/gitlab-ci.conf

server {
 listen *:80;
 server_name ci.embbnux.com;
 server_tokens off;
 root /opt/gitlab/embedded/service/gitlab-ci/public;

 client_max_body_size 50m;

 access_log /var/log/gitlab/nginx/gitlab_ci_access.log;
 error_log /var/log/gitlab/nginx/gitlab_ci_error.log;

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

 location @gitlab_ci {
   proxy_read_timeout 300;
   proxy_connect_timeout 300;
   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_ci;
  }
}

使配置生效

sudo gitlab-ci-rake setup
sudo gitlab-ctl restart
sudo service nginx restart

然后访问ci.embbnux.com可用gitlab的用户登录到ci中。差不多就这样

 

《ubuntu下gitlab以及gitlab-ci安装笔记》上有1条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Time limit is exhausted. Please reload the CAPTCHA.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据