设为首页 收藏本站
查看: 868|回复: 0

[经验分享] Ubuntu之Gitlab安装

[复制链接]

尚未签到

发表于 2018-1-10 16:54:56 | 显示全部楼层 |阅读模式
前提

安装

安装依赖包
  Needed to compile Ruby and native extensions to Ruby gems
$ sudo apt-get install vim # editor  
$ 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 python-docutils pkg-config cmake nodejs

安装Git
$ sudo apt-get install -y git git-core gitweb git-review  

  
# Make sure Git is version 1.7.10 or higher, for example 1.7.12 or 2.0.0
  
$ git --version

安装配置Ruby
  Ruby的版本可以通过浏览http://cache.ruby-lang.org/pub/ruby/来查到

下载安装Ruby
# Remove the old Ruby 1.8 if present  
$ sudo apt-get remove ruby1.8
  

  
$ mkdir /tmp/ruby && cd /tmp/ruby
  
$ curl -L --progress http://cache.ruby-lang.org/pub/ruby/ruby-2.2.2.tar.gz | tar xz
  
$ cd ruby-2.2.2
  
$ ./configure --disable-install-rdoc
  
$ make
  
$ sudo make install

配置Ruby
  修改Gem源指向taobao
  
https://rubygems.org/在国内被墙着
$ gem source -r https://rubygems.org/  
$ gem source -a http://ruby.taobao.org/

安装 Bundel 命令
$ sudo gem install bundler --no-ri --no-rdoc
为 Gitlab 创建一个 git 用户
  接下来Gitlab安装都用这个账户
$ sudo adduser --disabled-login --gecos 'GitLab' git
Gitlab Shell
  用来 ssh 访问仓库的管理软件

下载 Gitlab Shell
$ 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

  /etc/hosts里修改gitlab.zjc.com指向本机IP或者配置DNS

  

$ sudo -u git -H vim /home/git/gitlab-shell/config.ymlgitlab_url: "http://gitlab.zjc.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 数据库并授权用户访问
  下面代码中gitlabuser, gitlabpass为gitlabdb分配给的用户的用户名和密码,用户可以自行设置,但是在下面用到的地方要记得修改
$ sudo mysql -uroot -p  
$ > create database gitlabdb;

  
$ > grant all on gitlabdb.* to 'gitlabuser'@'localhost'>
GitLab

下载 GitLab 源代码,并切换到最新的分支上
$ cd /home/git  
$ sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
  
$ cd gitlab
  
# 切换到的最新稳定版号可以通过浏览器浏览`https://github.com/gitlabhq/gitlabhq`,点击branch获得
  
$ sudo -u git -H git checkout 7-13-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.zjc.com
  
email_from: gitlab@zjc.com
  
email_reply_to: noreply@zjc.com
  


相关目录-权限
# Make sure GitLab can write to the log/ and tmp/ directories  
$ sudo chown -R git log/
  
$ sudo chown -R git tmp/
  
$ sudo chmod -R u+rwX,go-w log/
  
$ sudo chmod -R u+rwX tmp/
  

  
# Create directory for satellites
  
$ sudo -u git -H mkdir /home/git/gitlab-satellites
  
$ sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
  

  
# Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
  
$ sudo chmod -R u+rwX tmp/pids/
  
$ sudo chmod -R u+rwX tmp/sockets/
  

  
# Make sure GitLab can write to the public/uploads/ directory
  
$ sudo chmod -R u+rwX  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.zjc.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 部分,注意这里用到的gitlabdb表的用户名和密码production:  adapter: mysql2  encoding: utf8  collation: utf8_general_ci  reconnect: false  database: gitlabdb  pool: 10  username: gitlabuser  password: "gitlabpass"  host: localhost  socket: /var/run/mysqld/mysqld.sock  

设置 GitLab 使用指定邮箱发送邮件
  

$ cd /home/git/gitlab/$ sudo -u git -H vim config/environments/production.rb修改 :sendmail 为 :smtpconfig.action_mailer.delivery_method = :smtp$ sudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb$ sudo -u git -H vim config/initializers/smtp_settings.rb如果邮件服务器配置为[Ubuntu之邮件服务器 ](http://blog.csdn.net/stwstw0123/article/details/47130293),则要求用户名应该为gitlab这样的形式如果邮件服务器配置为[Ubuntu之邮件服务器(Postfix, Dovecot, MySql)](http://blog.csdn.net/stwstw0123/article/details/47373183) ,则要求用户名应该为gitlab@vzjc.com这样的形式如果是其他邮件服务器,请查看服务器说明地址、端口、密码等请根据实际情况配置Gitlab::Application.config.action_mailer.delivery_method = :smtp  ActionMailer::Base.smtp_settings = {    address: "mail.zjc.com",    port: 587,    user_name: "gitlab",    password: "111111",    domain: "zjc.com",    authentication: :plain,    enable_starttls_auto: true,    openssl_verify_mode: 'none' # See ActionMailer documentation for other possible options  }  

安装 gem

修改 Gemfile 文件中源指向为 taobao
  

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

安装必须的依赖项
$ cd /home/git/gitlab/  
$ sudo -u git -H bundle install --deployment --without development test postgres aws kerberos

初始化数据库并激活高级功能
$ cd /home/git/gitlab/  
$ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

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


设置 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=productionENV=productionSystem informationSystem:                Ubuntu 14.04Current User:  gitUsing RVM:     noRuby Version:  2.1.6p336Gem Version:   2.2.3Bundler Version:1.10.6Rake Version:  10.4.2Sidekiq Version:3.3.0GitLab informationVersion:       7.12.2Revision:      30bffd5Directory:     /home/git/gitlabDB Adapter:    mysql2URL:           http://gitlab.zjc.comHTTP Clone URL:        http://gitlab.zjc.com/some-project.gitSSH Clone URL: git@gitlab.zjc.com:some-project.gitUsing LDAP:    noUsing Omniauth:        noGitLab ShellVersion:       2.6.3Repositories:  /home/git/repositories/Hooks:         /home/git/gitlab-shell/hooks/Git:           /usr/bin/git  

启动 GitLab 服务
  

$ sudo /etc/init.d/gitlab restart  

最后编译一下
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
安装配置Nginx

安装Nginx
  安装方法查看本博客 Ubuntu下安装Nginx、PHP

配置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/gitlabserver {  listen 0.0.0.0:80;  listen [::]:80;  server_name gitlab.zjc.com;[...] location /uploads/ {   [...]   proxy_pass http://gitlab.zjc.com:8081; }[...] location @gitlab {   [...]   proxy_pass http://gitlab.zjc.com:8081; }  

重启Nginx
$ sudo /etc/init.d/nginx restart  
# or
  
$ sudo service nginx restart

访问
  

用浏览器访问: `http://gitlab.zjc.com`用户名:root密码:5iveL!fe  

Gitlab账户配置
  接下来做几件事儿


  • Gitlab用root登录
  •   root用户配置,修改邮箱为admin@zjc.com

      admin为主机上的账户,修改邮箱后会向此账户发送邮件,点击邮件里的验证,邮箱就算是彻底修改过来了


  --- 以下为具体项目配置,请暂时忽略
# 创建admin账户  
$ sudo adduser admin
  
$ sudo passwd admin


  •   root添加SSH密钥

      用root登录Gitlab,更新密钥为ssh-rsa  *** admin@zjc.com形式, 公钥根据下面代码得到,要根据实际配置

    $ ssh-keygen -C admin@zjc.com  
    $ cat ~/.ssh/id_rsa.pub

DSC0001.jpg

  
DSC0002.jpg


  •   Gitlab创建用户ur

      创建后也需要向ur@zjc.com发送一封邮件,验证邮箱后才能登录


  • 为用户ur更新SSH公钥
  • 登录root,创建Group名字为DevGroup
  • DevGroup下创建项目TestProject
  •   让ur加入DevGroup组,角色为Reporter

  •   ur用户clone Test
      
    git地址可以以ur登录Gitab后在TestProject项目下看到
      

      
    zjc@zjc:~$ su - ur
      
    Password:
      
    ur@zjc:~$ git clone git@gitlab.zjc.com:DevGroup/TestProject.git
      
    Cloning into 'TestProject'...
      
    The authenticity of host 'gitlab.zjc.com (192.168.31.102)' can't be established.
      
    ECDSA key fingerprint is 46:7e:15:9a:92:44:dd:ef:a5:58:ca:9d:c7:f2:ba:25.
      
    Are you sure you want to continue connecting (yes/no)? yes
      
    Warning: Permanently added 'gitlab.zjc.com,192.168.31.102' (ECDSA) to the list of known hosts.
      
    warning: You appear to have cloned an empty repository.
      
    Checking connectivity... done.
      


  •   配置ur的git信息,如果已经登录ur就不需要执行su - ur这一步
    $ su - ur  
    $ git config --global user.name 'ur'
      
    $ git config --global user.email 'ur@zjc.com'

  •   测试ur的reporter权限,如果已经登录ur就不需要执行su - ur这一步
      

      
    $ su - ur
      
    $ cd TestProject
      
    $ touch testfile
      
    $ git add testfile
      
    $ git commit testfile -m 'ur add testfile'
      
    $ git push
      
    ...
      
    Please make sure you have the correct access rights
      
    and the repository exists.
      

      


参考:

  http://longgeek.com/2013/12/26/ci-system-structures-ii-gitlab-installation/
  
https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md
  
http://my.oschina.net/u/1158620/blog/289191


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-433622-1-1.html 上篇帖子: 卸载gitlab 下篇帖子: CentOS 7 安装配置 Gitlab
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表