持续集成环境Gitlab-CI的官方安装过程解析
持续集成环境是一个非常重要的工具,在分工合作的项目中有着举足轻重的作用。公司最近要用Gitlab,需要配套的持续集成环境。研究了官方的文档,感觉官方的文档不是很明了。各种修改过后终于成功了。为了大家安装时不再重蹈覆辙,特写这篇博客。博客内容大部分都是官方文档的内容,我仅仅是在一些容易失误的地方做了写解释。官方文档可能会不时更新。但这些注意的点应该变化不是很大。官方安装文档网址:https://github.com/gitlabhq/gitlab-ci/wiki 进入后点击相应的版本。
Requirements:
- GitLab 5.3+
Setup:
1. Packages / Dependencies
sudo is not installed on Debian by default. Make sure your system is up-to-date and install it.
sudo apt-get update
sudo apt-get upgrade
Note: Vim is an editor that is used here whenever there are files that need to be edited by hand. But, you can use any editor you like instead.
# Install vim
sudo apt-get install -y vim
Install the required packages:
sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev openssh-server git-core libyaml-dev postfix libpq-dev libicu-dev
sudo apt-get install redis-server
2. Ruby
Download Ruby and compile it:
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz
cd ruby-1.9.3-p392
./configure
make
sudo make install
Install the Bundler Gem:
sudo gem install bundler --no-ri --no-rdoc
3. Prepare the database
You can use either MySQL or PostgreSQL.
MySQL
# Install the database packages
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
# Login to MySQL
$ mysql -u root -p
# Create the GitLab CI database
mysql> CREATE DATABASE IF NOT EXISTS `gitlab_ci_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Create the MySQL User change $password to a real password 这里的 $password密码需要替换为你希望的密码
mysql> CREATE USER 'gitlab_ci'@'localhost' IDENTIFIED BY '$password';
# Grant proper permissions to the MySQL User
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlab_ci_production`.* TO 'gitlab_ci'@'localhost';
PostgreSQL
# Install the database packages
sudo apt-get install -y postgresql-9.1 libpq-dev
# Login to PostgreSQL
sudo -u postgres psql -d template1
# Create a user for GitLab. (change $password to a real password) 这里的 $password密码需要替换为你希望的密码
template1=# CREATE USER gitlab_ci WITH PASSWORD '$password';
# Create the GitLab production database & grant all privileges on database
template1=# CREATE DATABASE gitlab_ci_production OWNER gitlab_ci;
# Quit the database session
template1=# \q
# Try connecting to the new database with the new user
sudo -u git -H psql -d gitlab_ci_production
4. GitLab CI user:
sudo adduser --disabled-login --gecos 'GitLab CI' gitlab_ci
5. Get code
cd /home/gitlab_ci/
sudo -u gitlab_ci -H git clone https://github.com/gitlabhq/gitlab-ci.git
cd gitlab-ci
sudo -u gitlab_ci -H git checkout 3-0-stable
6. Setup application
# Edit application settings
sudo -u gitlab_ci -H cp config/application.yml.example config/application.yml
sudo -u gitlab_ci -H vim config/application.yml
#下边是application.yml的例子defaults: &defaults
allowed_gitlab_urls:
- 'http://earth.bao.ac.cn/gitlab/' #这是你的gitlab的地址
#- 'https://dev.gitlab.org/' #这两个注释掉
#- 'https://staging.gitlab.org/' development:
<<: *defaults
neat_setting: 800 test:
<<: *defaults
#allowed_gitlab_urls: #这个注释掉
# - 'http://demo.gitlab.com/' production:
<<: *defaults
allowed_gitlab_urls:
- 'http://earth.bao.ac.cn/gitlab/'#这是你的gitlab的地址
# Create a sockets directory
sudo -u gitlab_ci -H mkdir -p tmp/sockets/
sudo chmod -R u+rwX tmp/sockets/
Install gems
sudo -u gitlab_ci -H bundle --without development test postgres --deployment
sudo -u gitlab_ci -H bundle --without development test postgres --deployment
Setup db
# mysql
sudo -u gitlab_ci -H cp config/database.yml.mysql config/database.yml
# postgres
sudo -u gitlab_ci -H cp config/database.yml.postgres config/database.yml
# Edit user/password
sudo -u gitlab_ci -H vim config/database.yml
以下是database.yml例子
#
# PRODUCTION
#
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlab_ci_production
pool: 5
username: gitlab_ci
password: "travelchallenge" #这里设置你的先前设置的gilab_ci的密码
# host: localhost
# socket: /tmp/mysql.sock #
# Development specific
#
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlab_ci_development
pool: 5
username: debian-sys-maint
password: "r0VpzdDxG33ruj0m"
# socket: /tmp/mysql.sock # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlab_ci_test
pool: 5
username: debian-sys-maint
password: "r0VpzdDxG33ruj0m"
# socket: /tmp/mysql.sock
# Setup tables
sudo -u gitlab_ci -H bundle exec rake db:setup RAILS_ENV=production
# Setup scedules
#
sudo -u gitlab_ci -H bundle exec whenever -w RAILS_ENV=production
7. Install Init Script
Download the init script (will be /etc/init.d/gitlab_ci):
sudo wget https://raw.github.com/gitlabhq/gitlab-ci/master/lib/support/init.d/gitlab_ci -P /etc/init.d/
sudo chmod +x /etc/init.d/gitlab_ci
Make GitLab start on boot:
sudo update-rc.d gitlab_ci defaults 21
Start your GitLab instance:
sudo service gitlab_ci start
# or
sudo /etc/init.d/gitlab_ci restart
8. Nginx
Installation
sudo apt-get install nginx
Site Configuration
Download an example site config:
sudo wget https://raw.github.com/gitlabhq/gitlab-ci/master/lib/support/nginx/gitlab_ci -P /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/gitlab_ci /etc/nginx/sites-enabled/gitlab_ci
Make sure to edit the config file to match your setup:
# Change **YOUR_SERVER_IP** and **YOUR_SERVER_FQDN**
# to the IP address and fully-qualified domain name
# of your host serving GitLab CI
sudo vim /etc/nginx/sites-enabled/gitlab_ci
#下面是gitlab_ci的例子
upstream gitlab_ci {
server unix:/home/gitlab_ci/gitlab-ci/tmp/sockets/gitlab-ci.socket;
}
server {
#设置访问gitlab_ci的地址
listen 192.168.47.46:9292;
server_name 192.168.47.46;
root /home/gitlab_ci/gitlab-ci/public;
access_log /var/log/nginx/gitlab_ci_access.log;
error_log /var/log/nginx/gitlab_ci_error.log;
location / {
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 Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Sendfile-Type X-Accel-Redirect;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab_ci;
}
}
Restart
sudo /etc/init.d/nginx restart
9. Runners
Requirements
The project is designed for the Linux operating system.
We officially support (recent versions of) these Linux distributions:
- Ubuntu Linux
- Debian/GNU Linux
Installation
# Get code
git clone https://github.com/gitlabhq/gitlab-ci-runner.git # Enter code dircd gitlab-ci-runner # Install dependencies # a) Linux
sudo apt-get install libicu-dev # b) MacOSx (make sure you have brew installed)
sudo brew install icu4c gem install bundler
bundle install # Install runner in interactive mode
bundle exec ./bin/install # SSH into your GitLab server and confirm to add host key to known_hosts
ssh git@<your gitlab url>
Run
bundle exec ./bin/runner
Autostart Runners
On linux machines you can have your runners operate like daemons with the following steps
# make sure you install any system dependancies first
administrator@server:~$ sudo adduser --disabled-login --gecos 'GitLab CI Runner' gitlab_ci_runner
administrator@server:~$ sudo su gitlab_ci_runner
gitlab_ci_runner@server:/home/administrator$ cd ~/
# perform the setup above
gitlab_ci_runner@server:~$ exit;
gitlab_ci_runner@server:/home/gitlab_ci_runner$ sudo cp ./gitlab-ci-runner/lib/support/init.d/gitlab_ci_runner /etc/init.d/gitlab-ci-runner
gitlab_ci_runner@server:/home/gitlab_ci_runner$ cd ~
administrator@server:~$ sudo chmod +x /etc/init.d/gitlab-ci-runner
administrator@server:~$ sudo update-rc.d gitlab-ci-runner defaults 21
administrator@server:~$ sudo service gitlab-ci-runner start
Done!
Visit YOUR_SERVER for your first GitLab CI login. You should use your GitLab credentials in orider to login
持续集成环境Gitlab-CI的官方安装过程解析的更多相关文章
- 有手就行3——持续集成环境—maven、tomcat、安装和配置
有手就行3--持续集成环境-maven.tomcat.安装 持续集成环境(5)-Maven安装和配置 持续集成环境(6)-Tomcat安装和配置 持续集成环境(5)-Maven安装和配置 在Jenki ...
- 手把手详解持续集成之GitLab CI/CD
一.环境准备 首先需要有一台 GitLab 服务器,然后需要有个项目:这里示例项目以 Spring Boot 项目为例,然后最好有一台专门用来 Build 的机器,实际生产中如果 Build 任务不频 ...
- [Jenkins]持续集成环境下fingbug插件的安装使用与配置
参考:https://wiki.jenkins.io/display/JENKINS/FindBugs+Plugin 突然,天降杂事.我是想安安静静的做个美丽的测试...但是事与愿违,项目经理叫我帮忙 ...
- 【持续集成】GitLab CI + Docker 实现持续集成
GitLab CI + Docker 实现持续集成 一.持续集成(Continuous Integration, CI)的基本概念 概述 在传统软件的开发中,代码的集成工作通常是在所有人都将工作完成后 ...
- Docker——Jenkins + Git + Registry构建自动化持续集成环境(CI/CD)
前言 在互联网时代,对于每一家公司,软件开发和发布的重要性不言而喻,目前已经形成一套标准的流程,最重要的组成部分就是持续集成(CI)及持续部署.交付(CD). 本文基于Jenkins+Docker+G ...
- 从零入门 Serverless | 教你 7 步快速构建 GitLab 持续集成环境
作者 | 存诚 阿里云弹性计算团队 本文整理自<Serverless 技术公开课>,"Serverless"公众号后台回复"入门",即可获取系列文章 ...
- 使用Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(二)
前言 上一篇随笔Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(一)介绍maven和nexus的环境搭建,以及如何使用maven和nexus统一管理库 ...
- Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(二)
上一篇随笔Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(一)介绍maven和nexus的环境搭建,以及如何使用maven和nexus统一管理库文件和版本,以 ...
- 使用Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境
前言 但凡一个略有规模的项目都需要一个持续集成环境的支撑,为什么需要持续集成环境,我们来看一个例子.假如一个项目,由A.B两位程序员来协作开发,A负责前端模块,B负责后端模块,前端依赖后端.A和B都习 ...
随机推荐
- ArcEngine载入中SDE问题栅格数据
当直接加载矢量数据到IFeatureWorkspace接口可,但是,在装载门格当要传送的数据IRasterWorkspaceEx接口. 效果如下面的,对可以被添加到双击Globe在. watermar ...
- 如何使用Ubuntu online account API创建微博HTML5申请书
在这篇文章中.我们将使用Ubuntu SDK提供online account API来訪问微博的API并显示所须要的内容.这篇文章的重点是展示怎样在HTML 5中使用online account AP ...
- AngularJS应用开发思维之3:依赖注入
找不到的API? AngularJS提供了一些功能的封装,但是当你试图通过全局对象angular去 访问这些功能时,却发现与以往遇到的库大不相同. $http 比如,在jQuery中,我们知道它的AP ...
- Android NDK进入发展
使用互联网有很多javah命令生成一个头文件来完成JNI写,但事实上ADT集成NDK后.点点鼠标就可以了,网上的介绍是非常小懒的方法,在这里,我们主要谈论的懒惰JNI发展. 为ADT组态NDK.请个人 ...
- QT界面应用程序的语言国际化
对字符串使用tr包含起来,因为tr是QObject的一个静态函数,所以它可以直接调用. 在生成language.ts文件之前应该编辑.pro文件,如下: QT += core gui greaterT ...
- Xamarin移动跨平台解决方案是如何工作
Xamarin移动跨平台解决方案是如何工作的? 概述 上一篇 C#移动跨平台开发(1)环境准备发布之后不久,无独有偶,微软宣布了开放.NET框架源代码并且会为Windows.Mac和Linux开发一个 ...
- Spring之单元测试
引言 是否在程序运行时使用单元测试是衡量一个程序员素质的一个重要指标.使用单元测试既可以让我检查程序逻辑的正确性还可以让我们减少程序测试的BUG,便于调试可以提高我们写程序的效率.以前我们做单元测试的 ...
- kvm与qemu
载请注明出处: http://www.openext.org/2014/04/kvmqemu/ http://blog.csdn.net/muge0913/article/details/245577 ...
- Scala 的 Web 框架 Lift 开始 3.0 版本开发
Scala 的 Web 框架 Lift 开始 3.0 版本开发 http://demo.liftweb.net/ http://liftweb.net/download Lift 框架在不断的成长和改 ...
- 干净的架构The Clean Architecture
干净的架构The Clean Architecture 这是著名软件大师Bob大叔提出的一种架构,也是当前各种语言开发架构.干净架构提出了一种单向依赖关系,从而从逻辑上形成一种向上的抽象系统. 我们经 ...