GitLab 是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。它提供Git版本控制、代码检查、Bug跟踪和Wiki,它可以通过LDAP或活动目录来进行安全认证和授权。单个GitLab可以支持25000个用户,同时它也可以通过设置多台服务器来实现其高可用性。GitLab并没有被收入到Ubuntu14.04软件库中,但安装GitLab却也十分方便,下面讲讲如何安装GitLab:
首先照着GitLab的官方文档,输入以下命令:
wget -c https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.0.0-omnibus-1_amd64.deb su<span class="operator"><span class="keyword" style="font-weight: bold;">do</span> apt-<span class="keyword" style="font-weight: bold;">get</span> install openssh-server sudo apt-<span class="keyword" style="font-weight: bold;">get</span> install postfix sudo dpkg -i gitlab_7<span class="number" style="color: rgb(0, 153, 153);">.0</span><span class="number" style="color: rgb(0, 153, 153);">.0</span>-omnibus-<span class="number" style="color: rgb(0, 153, 153);">1</span>_amd64.deb</span>
因为GitLab这个包的地址下载速度很慢,还经常出现断点,所以在wget后加上了-c这个参数。安装openssh-server这句其实可以去掉,因为我一般都是在安装服务器的时候就勾选安装了这个服务,毕竟需要远程登录服务器嘛!Postfix是邮件服务,如果不安装这个服务的话,也可以安装Sendmail或Exim等相似的邮件服务(如果有邮件服务器的话,这一步可以忽略,可以通过gitlab-ctl来重配置SMTP服务)。
接下来是设置GitLab的域名:
su<span class="operator"><span class="keyword" style="font-weight: bold;">do</span> mkdir -p /etc/gitlab sudo touch /etc/gitlab/gitlab.rb sudo chmod <span class="number" style="color: rgb(0, 153, 153);">600</span> /etc/gitlab/gitlab.rb sudo vi /etc/gitlab/gitlab.rb</span>
然后添加一条域名配置:
external_url "# 如果没有安装Postfix或Sendmail这类邮件服务的话,那么就需要象邮件客户端那样根据SMTP服务器的参数来设置以下的内容了 gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.server" gitlab_rails['smtp_port'] = 456 gitlab_rails['smtp_user_name'] = "smtp user" gitlab_rails['smtp_password'] = "smtp password" gitlab_rails['smtp_domain'] = "example.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true
然后对GitLab进行重配置即可:
su<span class="operator"><span class="keyword" style="font-weight: bold;">do</span> gitlab-ctl reconfigure</span>
注意:正如GitLab大多数配置文件(如gitlab.yml或database.yml等)中所注释的那样:
<span class="comment" style="color: rgb(153, 153, 136); font-style: italic;"># This file is managed by gitlab-ctl. Manual changes will be</span> <span class="comment" style="color: rgb(153, 153, 136); font-style: italic;"># erased! To change the contents below, edit /etc/gitlab/gitlab.rb</span> <span class="comment" style="color: rgb(153, 153, 136); font-style: italic;"># and run `sudo gitlab-ctl reconfigure`.</span>
在GitLab中的大部分关于配置方面的修改,现在都需要在/etc/gitlab/gitlab.rb中进行设置,然后再运行sudo gitlab-ctl reconfigure进行修改。
如果对如何配置gitlab.rb有兴趣的话,可以参见: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md 这个网址,基本上已经讲得很清楚了。
接下来就是检测是否安装成功了,可以输入下面的命令:
sudo gitlab-ctl status [sudo] password <span class="keyword" style="font-weight: bold;">for</span> firehare: run: nginx: (pid <span class="number" style="color: rgb(0, 153, 153);">13334</span>) <span class="number" style="color: rgb(0, 153, 153);">16103</span><span class="keyword" style="font-weight: bold;">s</span>; run: <span class="keyword" style="font-weight: bold;">log</span>: (pid <span class="number" style="color: rgb(0, 153, 153);">4244</span>) <span class="number" style="color: rgb(0, 153, 153);">22211</span><span class="keyword" style="font-weight: bold;">s</span> run: postgresql: (pid <span class="number" style="color: rgb(0, 153, 153);">4153</span>) <span class="number" style="color: rgb(0, 153, 153);">22280</span><span class="keyword" style="font-weight: bold;">s</span>; run: <span class="keyword" style="font-weight: bold;">log</span>: (pid <span class="number" style="color: rgb(0, 153, 153);">4152</span>) <span class="number" style="color: rgb(0, 153, 153);">22280</span><span class="keyword" style="font-weight: bold;">s</span> run: redis: (pid <span class="number" style="color: rgb(0, 153, 153);">4070</span>) <span class="number" style="color: rgb(0, 153, 153);">22291</span><span class="keyword" style="font-weight: bold;">s</span>; run: <span class="keyword" style="font-weight: bold;">log</span>: (pid <span class="number" style="color: rgb(0, 153, 153);">4069</span>) <span class="number" style="color: rgb(0, 153, 153);">22291</span><span class="keyword" style="font-weight: bold;">s</span> run: sidekiq: (pid <span class="number" style="color: rgb(0, 153, 153);">4234</span>) <span class="number" style="color: rgb(0, 153, 153);">22212</span><span class="keyword" style="font-weight: bold;">s</span>; run: <span class="keyword" style="font-weight: bold;">log</span>: (pid <span class="number" style="color: rgb(0, 153, 153);">4233</span>) <span class="number" style="color: rgb(0, 153, 153);">22212</span><span class="keyword" style="font-weight: bold;">s</span> run: unicorn: (pid <span class="number" style="color: rgb(0, 153, 153);">4212</span>) <span class="number" style="color: rgb(0, 153, 153);">22218</span><span class="keyword" style="font-weight: bold;">s</span>; run: <span class="keyword" style="font-weight: bold;">log</span>: (pid <span class="number" style="color: rgb(0, 153, 153);">4211</span>) <span class="number" style="color: rgb(0, 153, 153);">22218</span><span class="keyword" style="font-weight: bold;">s</span>
如果得到与上面相似的结果,那么说明你安装成功。
由于GitLab包自带了Ruby、Rails和PostgreSQL,所以也就不需要象以前那样考虑兼容性的问题了。最后只需要直接登录GitLab所在的服务器,并使用帐号root,密码5iveL!fe来登录GitLab。首次登录GitLab会强行让你重置密码,然后就可以进入GitLab了。
配置邮箱
<span class="gp" style="color: rgb(85, 85, 85);">$ </span>sudo vi /etc/gitlab/gitlab.rb <span class="c" style="color: rgb(153, 153, 136); font-style: italic;"># Change the external_url to the address your users will type in their browser</span> external_url <span class="s1" style="color: rgb(221, 17, 68);">'http://xxhost.com'</span> <span class="c" style="color: rgb(153, 153, 136); font-style: italic;">#Sending application email via SMTP</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_enable'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="nb" style="color: rgb(0, 134, 179);">true </span>gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_address'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"smtp.163.com"</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_port'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> 25 gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_user_name'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"[email protected]"</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_password'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"xxpassword"</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_domain'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"163.com"</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_authentication'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> :login gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_enable_starttls_auto'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="nb" style="color: rgb(0, 134, 179);">true</span>
发送不成功,·sudo gitlab-ctl tail`检查日志报错如下:
<span class="mi" style="color: rgb(0, 153, 153);">2014</span><span class="o" style="font-weight: bold;">-</span><span class="mo" style="color: rgb(0, 153, 153);">07</span><span class="o" style="font-weight: bold;">-</span><span class="mi" style="color: rgb(0, 153, 153);">11_16</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">12</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">08</span><span class="o" style="font-weight: bold;">.</span><span class="mi" style="color: rgb(0, 153, 153);">43945</span> <span class="mi" style="color: rgb(0, 153, 153);">2014</span><span class="o" style="font-weight: bold;">-</span><span class="mo" style="color: rgb(0, 153, 153);">07</span><span class="o" style="font-weight: bold;">-</span><span class="mi" style="color: rgb(0, 153, 153);">11</span><span class="no" style="color: rgb(0, 128, 128);">T16</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">12</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">08</span><span class="n">Z</span> <span class="mi" style="color: rgb(0, 153, 153);">12595</span> <span class="no" style="color: rgb(0, 128, 128);">TID</span><span class="o" style="font-weight: bold;">-</span><span class="n">dxf7c</span> <span class="no" style="color: rgb(0, 128, 128);">Sidekiq</span><span class="o" style="font-weight: bold;">::</span><span class="no" style="color: rgb(0, 128, 128);">Extensions</span><span class="o" style="font-weight: bold;">::</span><span class="no" style="color: rgb(0, 128, 128);">DelayedMailer</span> <span class="no" style="color: rgb(0, 128, 128);">JID</span><span class="o" style="font-weight: bold;">-</span><span class="mo" style="color: rgb(0, 153, 153);">061604</span><span class="n">dc558ce8560b273cbe</span> <span class="no" style="color: rgb(0, 128, 128);">INFO</span><span class="p">:</span> <span class="nb" style="color: rgb(0, 134, 179);">fail</span><span class="p">:</span> <span class="mi" style="color: rgb(0, 153, 153);">0</span><span class="o" style="font-weight: bold;">.</span><span class="mi" style="color: rgb(0, 153, 153);">574</span> <span class="n">sec</span> <span class="mi" style="color: rgb(0, 153, 153);">2014</span><span class="o" style="font-weight: bold;">-</span><span class="mo" style="color: rgb(0, 153, 153);">07</span><span class="o" style="font-weight: bold;">-</span><span class="mi" style="color: rgb(0, 153, 153);">11_16</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">12</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">08</span><span class="o" style="font-weight: bold;">.</span><span class="mi" style="color: rgb(0, 153, 153);">44955</span> <span class="mi" style="color: rgb(0, 153, 153);">2014</span><span class="o" style="font-weight: bold;">-</span><span class="mo" style="color: rgb(0, 153, 153);">07</span><span class="o" style="font-weight: bold;">-</span><span class="mi" style="color: rgb(0, 153, 153);">11</span><span class="no" style="color: rgb(0, 128, 128);">T16</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">12</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">08</span><span class="n">Z</span> <span class="mi" style="color: rgb(0, 153, 153);">12595</span> <span class="no" style="color: rgb(0, 128, 128);">TID</span><span class="o" style="font-weight: bold;">-</span><span class="n">dxf7c</span> <span class="no" style="color: rgb(0, 128, 128);">WARN</span><span class="p">:</span> <span class="p">{</span><span class="s2" style="color: rgb(221, 17, 68);">"retry"</span><span class="o" style="font-weight: bold;">=></span><span class="kp" style="font-weight: bold;">true</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"queue"</span><span class="o" style="font-weight: bold;">=></span><span class="s2" style="color: rgb(221, 17, 68);">"default"</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"class"</span><span class="o" style="font-weight: bold;">=></span><span class="s2" style="color: rgb(221, 17, 68);">"Sidekiq::Extensions::DelayedMailer"</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"args"</span><span class="o" style="font-weight: bold;">=>[</span><span class="s2" style="color: rgb(221, 17, 68);">"---</span><span class="se" style="color: rgb(221, 17, 68);">\n</span><span class="s2" style="color: rgb(221, 17, 68);">- !ruby/class 'Notify'</span><span class="se" style="color: rgb(221, 17, 68);">\n</span><span class="s2" style="color: rgb(221, 17, 68);">- :project_access_granted_email</span><span class="se" style="color: rgb(221, 17, 68);">\n</span><span class="s2" style="color: rgb(221, 17, 68);">- - 4</span><span class="se" style="color: rgb(221, 17, 68);">\n</span><span class="s2" style="color: rgb(221, 17, 68);">"</span><span class="o" style="font-weight: bold;">]</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"jid"</span><span class="o" style="font-weight: bold;">=></span><span class="s2" style="color: rgb(221, 17, 68);">"061604dc558ce8560b273cbe"</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"enqueued_at"</span><span class="o" style="font-weight: bold;">=></span><span class="mi" style="color: rgb(0, 153, 153);">1405094359</span><span class="o" style="font-weight: bold;">.</span><span class="mi" style="color: rgb(0, 153, 153);">354158</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"error_message"</span><span class="o" style="font-weight: bold;">=></span><span class="s2" style="color: rgb(221, 17, 68);">"553 Mail from must equal authorized user</span><span class="se" style="color: rgb(221, 17, 68);">\n</span><span class="s2" style="color: rgb(221, 17, 68);">"</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"error_class"</span><span class="o" style="font-weight: bold;">=></span><span class="s2" style="color: rgb(221, 17, 68);">"Net::SMTPFatalError"</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"failed_at"</span><span class="o" style="font-weight: bold;">=></span><span class="s2" style="color: rgb(221, 17, 68);">"2014-07-11 15:59:28 UTC"</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"retry_count"</span><span class="o" style="font-weight: bold;">=></span><span class="mi" style="color: rgb(0, 153, 153);">5</span><span class="p">,</span> <span class="s2" style="color: rgb(221, 17, 68);">"retried_at"</span><span class="o" style="font-weight: bold;">=></span><span class="mi" style="color: rgb(0, 153, 153);">2014</span><span class="o" style="font-weight: bold;">-</span><span class="mo" style="color: rgb(0, 153, 153);">07</span><span class="o" style="font-weight: bold;">-</span><span class="mi" style="color: rgb(0, 153, 153);">11</span> <span class="mi" style="color: rgb(0, 153, 153);">16</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">12</span><span class="p">:</span><span class="mi" style="color: rgb(0, 153, 153);">08</span> <span class="no" style="color: rgb(0, 128, 128);">UTC</span><span class="p">}</span>
Google大法后,错误码对应解释网易服务器smtp机器要求身份验证帐号和发信帐号必须一致,如果用户在发送邮件时,身份验证帐号和发件人帐号是不同的,因此拒绝发送。
修改gitlab.rb,修改发信人和身份验证帐号一致,163发信OK。
<span class="gp" style="color: rgb(85, 85, 85);">$ </span>sudo vi /etc/gitlab/gitlab.rb <span class="c" style="color: rgb(153, 153, 136); font-style: italic;"># Change the external_url to the address your users will type in their browser</span> external_url <span class="s1" style="color: rgb(221, 17, 68);">'http://xxhost.com'</span> <span class="c" style="color: rgb(153, 153, 136); font-style: italic;">#Sending application email via SMTP</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_enable'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="nb" style="color: rgb(0, 134, 179);">true </span>gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_address'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"smtp.163.com"</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_port'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> 25 gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_user_name'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"[email protected]"</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_password'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"xxpassword"</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_domain'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"163.com"</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_authentication'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> :login gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'smtp_enable_starttls_auto'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="nb" style="color: rgb(0, 134, 179);">true</span> <span class="c" style="color: rgb(153, 153, 136); font-style: italic;">##修改gitlab配置的发信人</span> gitlab_rails[<span class="s1" style="color: rgb(221, 17, 68);">'gitlab_email_from'</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"[email protected]"</span> user[<span class="s2" style="color: rgb(221, 17, 68);">"git_user_email"</span><span class="o" style="font-weight: bold;">]</span> <span class="o" style="font-weight: bold;">=</span> <span class="s2" style="color: rgb(221, 17, 68);">"[email protected]</span>