CI 系统搭建:二. GitLab 的安装配置
An error occurred while installing github-linguist (4.7.6), and Bundler cannot
continue.
Make sure that `gem install github-linguist -v '4.7.6'` succeeds before
bundling.
2013-12-26日 | 标签: CI Git Gitlab | 作者:Geek
上一篇文章 CI 系统搭建:一. 基础环境设置、规划 大概规划了下环境,本文主要用来记录安装 Gitlab 的过程,主要参考官方文档 并没有做太多的修改。
设置源
设置国内 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 libxslt1-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 gitk
升级 Git 版本(可选)
sudo apt-get install -y git gitweb sudo apt-get remove git-core sudo apt-get install -y libexpat1-dev gettext libz-dev (zlib1g-dev) 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/ 下载 2.0.0版
curl --progress https://www.kernel.org/pub/software/scm/git/git-2.0.0.tar.gz | tar xz cd git-2.0.0/
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 下载 2.1.2 版的 ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz
cd ruby-2.1.2
./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
执行结果:
mkdir -p /home/git/repositories: OK
mkdir -p /home/git/.ssh: OK
chmod 700 /home/git/.ssh: OK
touch /home/git/.ssh/authorized_keys: OK
chmod 600 /home/git/.ssh/authorized_keys: OK
chmod ug+rwX,o-rwx /home/git/repositories: OK
Mysql
安装 Mysql 包
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
给 Gitlab 创建 Mysql 数据库并授权用户访问
登录 mysql 创建 gitlab 用户
# sudo mysql -uroot -p
> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password'; # 把这里的 $password 换成你自己的密码
设置存储引擎为 Innode
SET storage_engine=INNODB;
创建gitlab的数据库
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
给数据库用户授权
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
退出
> \q
测试刚刚创建的 gitlab 用户名和密码是否可以正常登录
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
可以正常登录后,即可退出,继续下面的安装
> \q
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
最新版是 7-2-stablesudo -u git -H git checkout 7-2-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: gitlab@thstack.com
support_mail: gitlab@thstack.com
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 "127.0.0.1:8080", :tcp_nopush => true 改为下面的:
listen "gitlab.thstack.com:8081", :tcp_nopush => true
配置 GitLab 访问 mysql 数据库设置
cd /home/git/gitlab/
sudo -u git -H 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 => 'gitlab@thstack.com',
: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/"
Gem::RemoteFetcher::FetchError: Errno::ETIMEDOUT: Connection timed out - connect(2) for "rubygems.org" port 443 (https://rubygems.org/gems/rake-10.4.2.gem)
An error occurred while installing rake (10.4.2), and Bundler cannot continue.
Make sure that `gem install rake -v '10.4.2'` succeeds before bundling.
虽然在文件中指向了国内 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:
login.........admin@local.host
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: git@gitlab.thstack.com: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
用户名:admin@local.host
密码:5iveL!fe
2: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/insta llation.md
界面简单使用
原文网址:http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/