转载CI系统搭建二、Gitlab的安装和配置

博客转载于longgeek.com, 地址 http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/#i-4

我在自己电脑上安装了这个gitLab,亲自测试过博客中描述的步骤很全。其中 域名如果没有替换为自己本地的地址,需要带上端口号。其中端口号为8081

上一篇文章 CI 系统搭建:一. 基础环境设置、规划 大概规划了下环境,本文主要用来记录安装 Gitlab 的过程,主要参考官方文档 并没有做太多的修改。

目录

  • 1 设置源
  • 2 安装依赖包
  • 3 系统用户
  • 4 GitLab Shell
  • 5 Mysql
  • 6 GitLab
  • 7 Nginx
  • 8 界面简单使用
设置源

设置国内 163 apt 源

# vim /etc/apt/sources.list
deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted

deb-src http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
# apt-get update

安装依赖包

Gitlab 依赖包、库

sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev                         libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall                         libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate

安装 markdown 文档风格依赖包

sudo apt-get install -y python-docutils

安装 git,Gerrit 依赖 gitweb,同时 GitLab 依赖 git 版本 >= 1.7.10,Ubuntu apt-get 默认安装的是 1.7.9.5,当然不升级也是没有问题的

sudo apt-get install -y git git-core gitweb git-review

升级 Git 版本(可选)

sudo apt-get install -y git gitweb
sudo apt-get remove git-core
sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
cd /tmp
curl --progress https://git-core.googlecode.com/files/git-1.8.4.1.tar.gz | tar xz
cd git-1.8.4.1/
make prefix=/usr/local all
sudo make prefix=/usr/local install
# * 如果升级了 git 的版本,相应修改 Gitlab.yml 中的 git 脚本位置,这一步在 clone gitlab 后在操作*
sudo -u git -H vim /home/git/gitlab/config/gitlab.yml
bin_path: /usr/local/bin/git

Gitlab 需要收发邮件,安装邮件服务器

sudo apt-get install -y postfix

如果安装了 ruby1.8,卸载掉,Gitlab 依赖 2.0 以上

sudo apt-get remove ruby1.8

下载编译 ruby2.0

mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
cd ruby-2.0.0-p353
./configure --disable-install-rdoc
make
sudo make install

修改 gem 源指向 taobao

gem source -r https://rubygems.org/
gem source -a http://ruby.taobao.org/

安装 Bundel 命令

sudo gem install bundler --no-ri --no-rdoc

系统用户

给 Gitlab 创建一个 git 用户

sudo adduser --disabled-login --gecos ‘GitLab‘ git

GitLab Shell

下载 Gitlab Shell,用来 ssh 访问仓库的管理软件

cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
sudo -u git -H cp config.yml.example config.yml

修改 gitlab-shell/config.yml

sudo -u git -H vim /home/git/gitlab-shell/config.yml
gitlab_url: "http://gitlab.thstack.com/"

安装 GitLab Shell

cd /home/git/gitlab-shell
sudo -u git -H ./bin/install

Mysql

安装 Mysql 包

sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

给 Gitlab 创建 Mysql 数据库并授权用户访问

sudo mysql -uroot -p
> create database gitlabdb;
> grant all on gitlabdb.* to ‘gitlabuser‘@‘localhost‘ identified by ‘gitlabpass‘;

GitLab

下载 GitLab 源代码,并切换到最新的分支上

cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
sudo -u git -H git checkout 6-4-stable

配置 GitLab,修改 gitlab.yml,其中 host: 项和 gitlab-shell 中 gitlab_url 的主机一致

cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H vim config/gitlab.yml
host: gitlab.thstack.com
email_from: [email protected]
support_mail: [email protected]
signup_enabled: true             #开启用户注册

创建相关目录

cd /home/git/gitlab
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo -u git -H mkdir public/uploads
sudo -u git -H mkdir /home/git/repositories
sudo -u git -H mkdir /home/git/gitlab-satellites

修改相关目录权限

sudo chown -R git:git log/ tmp/
sudo chmod -R u+rwX  log/ tmp/ public/uploads

修改 unicorn.rb 监听端口为:8081

cd /home/git/gitlab/
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H vim config/unicorn.rb
listen "gitlab.thstack.com:8081", :tcp_nopush => true

配置 GitLab 访问 mysql 数据库设置

cd /home/git/gitlab/
sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H vim config/database.yml
*修改 Production 部分:*
production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gitlabdb
  pool: 10
  username: gitlabuser
  password: "gitlabpass"
  host: localhost
  socket: /var/run/mysqld/mysqld.sock

设置 GitLab 使用指定邮箱发送邮件,注意 production.rb 的文件格式,开头空两格

cd /home/git/gitlab/
sudo -u git -H vim config/environments/production.rb
  #修改 :sendmail 为 :smtp
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "smtp.googlemail.com",
    :port                 => 587,
    :domain               => ‘thstack.com‘,
    :user_name            => ‘[email protected]‘,
    :password             => ‘password‘,
    :authentication       =>  :plain,
    :enable_starttls_auto => true
  }
end          # 上面内容加入到 end 里面

安装 gem

修改 Gemfile 文件中源指向为 taobao

cd /home/git/gitlab/
sudo -u git -H vim Gemfile
source "http://ruby.taobao.org/"

虽然在文件中指向了国内 taobao 源,但是依然会卡一会,耐心等待…

cd /home/git/gitlab/
sudo -u git -H bundle install --deployment --without development test postgres aws

初始化数据库并激活高级功能

cd /home/git/gitlab/
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

输入 yes 来初始化数据库、创建相关表,最后会输出 GitLab Web 管理员用来登录的账号和密码

Do you want to continue (yes/no)? yes
...
Administrator account created:
[email protected]
password......5iveL!fe

设置 GitLab 启动服务

cd /home/git/gitlab/
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo update-rc.d gitlab defaults 21

设置 GitLab 使用 Logrotate 备份 Log

cd /home/git/gitlab/
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

检查GitLab及其环境的配置是否正确:

cd /home/git/gitlab/
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System:         Ubuntu 12.04
Current User:   git
Using RVM:      no
Ruby Version:   2.0.0p353
Gem Version:    2.0.14
Bundler Version:1.3.5
Rake Version:   10.1.0

GitLab information
Version:        6.4.2
Revision:       214a013
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://gitlab.thstack.com
HTTP Clone URL: http://gitlab.thstack.com/some-project.git
SSH Clone URL:  [email protected]:some-project.git
Using LDAP:     no
Using Omniauth: no

GitLab Shell
Version:        1.8.0
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/bin/git

启动 GitLab 服务

/etc/init.d/gitlab restart
Shutting down both Unicorn and Sidekiq.
GitLab is not running.
Starting both the GitLab Unicorn and Sidekiq..
The GitLab Unicorn web server with pid 17771 is running.
The GitLab Sidekiq job dispatcher with pid 17778 is running.
GitLab and all its components are up and running

最后编译一下

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

Nginx

安装 Nginx 包

sudo apt-get install -y nginx

配置 Nginx

cd /home/git/gitlab
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
sudo vim /etc/nginx/sites-available/gitlab
listen *:80 default_server;
server_name gitlab.thstack.com;
proxy_pass http://gitlab.thstack.com:8081;

启动 Nginx

/etc/init.d/apache2 stop
/etc/init.d/nginx restart

访问

用浏览器访问: http://gitlab.thstack.com
用户名:[email protected]
密码:5iveL!fe

2: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/insta llation.md

界面简单使用

使用 [email protected] 账号登录:

登录后系统让修改密码,先修改密码:

修改完密码后,用新密码登录一下,然后修改 Admin 用户得邮箱地址为:[email protected]

点击保存更改后,系统会自动给刚才输入的邮箱地址发送一封确认修改信息,点击邮件内容中的连接后会自动用新账号邮箱登录。

创建一个 GROUP:

输入 Group 名字为:DevGroup

点击创建项目:

创建一个项目,名为:OpenStack,这个项目属于 DevGroup:

创建完项目后,点击添加 ssh 密钥:

生成 [email protected] 邮箱密钥:

在界面输入刚才生成得密钥:

再注册一个账号,登录页面点击注册按钮:

注册一个 Longgeek 用户,输入邮箱、密码,然后去输入得邮箱验证:

创建一个 Longgeek 用户,并生成密钥:

用 [email protected] 用户登录 GitLab,添加刚才生成得密钥到 sshkey 里:

用 [email protected] 用户登录 GitLab,把 [email protected] 添加到 DevGroup 组中,权限是 Reporter,这样 longgeek 用户也可以访问 OpenStack 这个项目,不过没有权限直接 Push:

用 [email protected] 用户登录就可以看到 OpenStack 项目:

用 [email protected] clone 项目,尝试 push:

很显然 longgeek 用户是没有 push 到 master 分支得权限。接下来会安装 Gerrit、Jenkins。以及它们三个如何整合成流程。请参考后面得文章。

时间: 2024-08-06 13:52:55

转载CI系统搭建二、Gitlab的安装和配置的相关文章

Cacti+Nagios监控系统(二):安装Cacti

一.设置mysql,创建Cacti数据库和账号 mysql -u root -p mysql> create database cactidb; mysql> GRANT ALL ON cactidb.* TO [email protected] IDENTIFIED BY '123456'; mysql> flush privileges; mysql> quit 二.安装rrdtool yum -y install rrdtool  rrdtool-devel  rrdtool

从零开始搭建系统1.6——Https证书安装及配置

从零开始搭建系统1.6--Https证书安装及配置 原文地址:https://www.cnblogs.com/provence666/p/8638532.html

Tomcat学习之二:tomcat安装、配置及目录文件说明

我们看到tomcat目录/bin文件夹里有个tomcat6w.exe,顾名思义就是tomcat以window方式显示控制台.第1次点击打开它时候,可能会提示:tomcat指定的服务未安装,此时我们可以这样解决它. 打开命令行提示符窗口-> 进入Tomcat安装目录-> 进入bin目录下-> 输入:service.bat install 即可,如图操作,tomcat目录按自己电脑上的来即可 <!--[endif]--> 这样就可以让tomcat以window方式显示控制台.点击

Linux搭建JDK、Tomcat安装及配置

一.JDK安装及配置 1.JKD下载地址:http://pan.baidu.com/s/1i5NpImx 2.查看安装: rpm -qa | grep jdk 3.卸载:rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.i686     rpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.i686 4.上传JDK文件到Linux服务器 5.解压缩:tar -zxvf j

Hyper-V虚拟化测试04环境搭建之二Hyper-V角色安装及配置

2.2.3.Hyper-V主机角色安装及配置2.2.3.1.首先把Hyper-V主机加域 在服务器管理器界面,点击"添加角色和功能" 默认点击"下一步" 选择"基于角色或基于功能的安装",点击"下一步" 默认点击"下一步" 勾选"Hyper-V"服务器角色,在弹出的依赖功能中,点击"添加功能" 点击"下一步" 默认点击"下一步"

持续集成(CI)工具------Hudson/Jenkins(Continuous Integration)安装与配置具体解释

本文同意转载.但请标明出处:http://blog.csdn.net/wanghantong/article/40985653/, 版权全部 文章概述: 一. 描写叙述了持续集成工具Hudson的安装与配置 二. 描写叙述了Git .Maven环境的安装与配置 三. 描写叙述了扩展邮件通知及其配置方法 四. 描写叙述了jira的配置 一.Hudson简单介绍 Hudson是Jenkins的前身,是基于Java开发的一种持续集成工具.用于监控持续的软件版本号公布/測试项目 下载地址:http://

[转载]CentOS6.4下Samba服务器的安装与配置

原文地址:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/06/3001863.html 一.先恶狠狠地吐槽一下: 这篇随笔真是让我折腾了2天2夜才敢下笔写!!!为什么呢?之前是通过去Samba的官网下载的源码包,也就是.tar.gz来进行安装配置,不过 这个让我折腾来折腾去就是没折腾出结果,还花了我整整1天1夜的时间,最后实在是熬不住了,想通过yum来重新进行Samba服务器的安装与配置,但是要 使用yum首先必须是CentOS要

Gitlab的安装与配置

gitlab的安装 参考治疗:https://www.gitlab.com.cn/installation/#centos-7 http://www.21yunwei.com/archives/4351 1.安装并配置必要的依赖关系 如果你想使用 Postfix 发送邮件,请在安装过程中根据提示选择 'Internet Site'. 你也可以用 Sendmail 或者 配置一个自定义的 SMTP 服务 并 把它作为一个 SMTP 服务器. 在 CentOS 系统上,下面的命令将会打开系统防火墙

LXD 2.0 系列(二):安装与配置

导读 简单来说,LXD是一个守护进程,为LXC容器的管理提供一组REST API.主要目标是提供一种类虚拟机的用户体验,是一种第三方的容器管理工具.下面呢,我们来介绍LXD 2.0 的安装与配置 安装篇 有很多种办法可以获得 LXD.我们推荐你配合最新版的 LXC 和 Linux 内核使用 LXD,这样就可以享受到它的全部特性.需要注意的是,我们现在也在慢慢的降低对旧版本 Linux 发布版的支持. Ubuntu 标准版安装 所有新发布的 LXD 都会在发布几分钟后上传到 Ubuntu 开发版的