gitlab 6.5 on centos 6.4

前段时间开始研究起来gitlab这东西了,不用多说,就开始折腾,最后在自己的vps上做了个,中间出过很多问题,请教了磊哥,这里特别感谢,总结的文档是按照Markdown格式写的,放到这里就成这样了,估计我没有改博客园的编辑器,另外博客园的Markdown编辑器和我mac下的MOU呈现的效果不太一样,所以强烈建议博客园出个Linux下客户端写博客app吧,在mac下太不方便了,文档参照官方文档,修改了部分东西

### 参考链接:

    http://dl528888.blog.51cto.com/ 磊哥的博客

    http://www.01happy.com/centos-6-5-install-gitlab/ 快乐编程

    https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md 官方文档关于centos上的安装

## gitlab 6.5 on centos 6.4
##### step1:system environment

    Distribution      : CentOS 6.4 minimal
    GitLab version    : 6.0 - 6.6
    Web Server        : Nginx
    Init system       : sysvinit
    Database          : MySQL
    Additional Notes  : In order to get a proper Ruby setup we build it from source

##### step2:before installing

    1. 关闭selinx
    2. 时间同步

##### step3:The GitLab installation consists of setting up the following components:

    Install the base operating system (CentOS 6.5 Minimal) and Packages / Dependencies
    Ruby
    System Users
    GitLab shell
    Database
    GitLab
    Web server
    Firewall

## 1、Installing the operating system (CentOS 6.5 Minimal)
> 略...

## 2、step1:Updating and adding basic software and services
##### Add Fedora epel repository

    rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    wget -/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt
    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

##### Add PUIAS Computational repository

    # vim /etc/yum.repos.d/PUIAS_6_computational.repo
    [PUIAS_6_computational]
    name=PUIAS computational Base $releasever - $basearch
    mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
    #baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias

    #下载公钥
    wget -/etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

    #验证
    yum repolist

##### Install the required tools for GitLab

    yum -y update
    yum -y groupinstall 'Development Tools'
    yum -y install vim-enhanced readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git patch  python-docutils

##### 配置redis
> 配置redis使其在开机时启动:

    chkconfig redis on
    service redis start

##### 配置邮件服务器
> 这部分没有配置

## 2、install ruby
##### Download Ruby and compile it:

    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 --prefix=/usr/local/
    make
    make install
    echo $?

##### Install the Bundler Gem:

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

    #verify
    gem list --local | grep bundler

##### Logout and login again for the $PATH to take effect. Check that ruby is properly installed with:

    which ruby
    # /usr/local/bin/ruby
    ruby -v
    # ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]   

## 3、System Users
##### Create a git user for Gitlab:

    adduser --system --shell /sbin/nologin --comment 'GitLab' --create-home --home-dir /home/git/ git

##### and append /usr/local/bin like so:
> 这部分可选,如果以git用户身份登录的话,这部分也可以不配置

    Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

## 4、GitLab shell
> GitLab Shell is a ssh access and repository management application developed specifically for GitLab.  

> 这部分要登录git用户    

    #login git user
    su - git

    # Go to home directory
    cd /home/git

    # Clone gitlab shell
    git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.8.0
    cd gitlab-shell
    cp config.yml.example config.yml

    # Edit config and replace gitlab_url
    # with something like 'http://domain.com/'
    vim config.yml

    # Do setup
    /usr/local/bin/ruby ./bin/install

    #更改gitlab-shell.log属主和组。我在后面检查的时候报了这个错误,如果检查的时候没有这个报错,那么就可以忽略这一步
    Running /home/git/gitlab-shell/bin/check
    /usr/local/lib/ruby/2.0.0/logger.rb:594:in `initialize': Permission denied - /home/git/gitlab-shell/gitlab-shell.log (Errno::EACCES)
        from /usr/local/lib/ruby/2.0.0/logger.rb:594:in `open'

        from /usr/local/lib/ruby/2.0.0/logger.rb:594:in `open_logfile'
        from /usr/local/lib/ruby/2.0.0/logger.rb:551:in `initialize'

        from /usr/local/lib/ruby/2.0.0/logger.rb:318:in `new'
        from /usr/local/lib/ruby/2.0.0/logger.rb:318:in `initialize'

        from /home/git/gitlab-shell/lib/gitlab_logger.rb:15:in `new'
        from /home/git/gitlab-shell/lib/gitlab_logger.rb:15:in `<top (required)>'

        from /home/git/gitlab-shell/lib/gitlab_net.rb:6:in `require_relative'
        from /home/git/gitlab-shell/lib/gitlab_net.rb:6:in `<top (required)>'

        from /home/git/gitlab-shell/bin/check:4:in `require_relative'
        from /home/git/gitlab-shell/bin/check:4:in `<main>'

    gitlab-shell self-check failed
    
    #解决办法
    su -
    chown git.git gitlab-shell.log

## 5、Database
### install MySQL
##### Install mysql and enable the mysqld service to start on boot:
> 这部分必须是在root用户权限才能安装

    #root user
    yum install -y mysql-server mysql-devel
    chkconfig mysqld on
    service mysqld start

##### Secure MySQL by entering a root password and say "Yes" to all questions:

    /usr/bin/mysql_secure_installation


##### Create a new user and database for GitLab:

    # Login to MySQL
    mysql -u root -p

    # Type the database root password
    # Create a user for GitLab. (change supersecret to a real password)
    CREATE USER 'git'@'localhost' IDENTIFIED BY 'git连接mysql口令';

    # Create the GitLab production database
    CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

    # Grant the GitLab user necessary permissopns on the table.
    GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';

    # Quit the database session
    \q

##### Try connecting to the new database with the new user:

    mysql -u git --D gitlabhq_production
    # Type the password you replaced supersecret with earlier
    # Quit the database session
    \q


## 6、GitLab

    # We'll install GitLab into home directory of the user "git"
    su - git

##### Clone the Source

    # Clone GitLab repository
    git clone https://gitlab.com/gitlab-org/gitlab-ce.git -6-5-stable gitlab

##### configure it


    cd /home/git/gitlab

    # Copy the example GitLab config
    cp config/gitlab.yml.example config/gitlab.yml

    # Make sure to change "localhost" to the fully-qualified domain name of your
    # host serving GitLab where necessary
    #
    # If you installed Git from source, change the git bin_path to /usr/local/bin/git
    vim config/gitlab.yml

    # Make sure GitLab can write to the log/ and tmp/ directories
    chown -R git log/
    chown -R git tmp/
    chmod -R u+rwX  log/
    chmod -R u+rwX  tmp/


    # Create directory for satellites
    mkdir /home/git/gitlab-satellites

    # Create directories for sockets/pids and make sure GitLab can write to them
    mkdir tmp/pids/
    mkdir tmp/sockets/
    chmod -R u+rwX  tmp/pids/
    chmod -R u+rwX  tmp/sockets/

    # Create public/uploads directory otherwise backup will fail
    mkdir public/uploads
    chmod -R u+rwX  public/uploads

    # Copy the example Unicorn config
    cp config/unicorn.rb.example config/unicorn.rb

    # Enable cluster mode if you expect to have a high load instance
    # Ex. change amount of workers to 3 for 2GB RAM server
    vim config/unicorn.rb

    # Copy the example Rack attack config
    cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

    # Configure Git global settings for git user, useful when editing via web
    # Edit user.email according to what is set in gitlab.yml
    git config --global user.name "GitLab"
    git config --global user.email "gitlab@localhost"
    git config --global core.autocrlf input

##### Important Note: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.
##### Configure GitLab DB settings

    # For MySQL
    cp config/database.yml{.mysql,}

    # Make sure to update username/password in config/database.yml.
    # You only need to adapt the production settings (first part).
    # If you followed the database guide then please do as follows:
    # Change 'secure password' with the value you have given to $password
    # You can keep the double quotes around the password
    vim config/database.yml

    #配置应该看起来如下,username和password确保正确即可
    # PRODUCTION
    #
    production:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: gitlabhq_production
      pool: 10
      username: git
      password: "刚才mysql中设置的口令"
      # host: localhost
      # socket: /tmp/mysql.sock
   
    #make sure git user can read & write only
    chmod o-rwx config/database.yml

##### Install Gems

    #as root!    
    gem install charlock_holmes --version '0.6.9.4'

    #as git user!
    su - git
    cd /home/git/gitlab

    # For MySQL (note, the option says "without ... postgres")
    bundle install --deployment --without development test postgres aws
    //这里将会为选定的数据库安装上相应的组件,由于亚马逊上的ruby源对于国内来说可能不太稳定,如果国内安装的话不妨考虑切换成淘宝的ruby源,会快很多

##### Initialize Database and Activate Advanced Features

    su - git

    cd gitlab/
    bundle exec rake gitlab:setup RAILS_ENV=production

    # Type 'yes' to create the database tables.
    # When done you see 'Administrator account created:'
    #Type 'yes' to create the database. When done you see 'Administrator account created:'

    #这部分结尾会生成一个默认管理员账号和密码,第一次登录就是用这个登录
    admin@local.host
    5iveL!fe


##### Install Init Script  

    #as root!!!
    #Download the init script (will be /etc/init.d/gitlab):
    su -
    wget -/etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
    chmod +/etc/init.d/gitlab
    chkconfig --add gitlab


    #Make GitLab start on boot:
    chkconfig gitlab on

##### Set up logrotate


    #as root
    cd /home/git/gitlab
    cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

##### Check Application Status
> 可以查看到系统、Ruby、GitLab和GitLab Shell的版本和其他信息。

    #Check if GitLab and its environment are configured correctly:
    bundle exec rake gitlab:env:info RAILS_ENV=production
   
##### Start your GitLab instance:

    #as root    

    service gitlab start

##### 查看更加详细的信息

    bundle exec rake gitlab:check RAILS_ENV=production

    Init script up-to-date? ... no  
    Try fixing it:  
    Redownload the init script  
    For more information see:  
    doc/install/installation.md in section "Install Init Script"  
    Please fix the error above and rerun the checks.  
    但是官方给的解释就是可以忽略这个信息
    //除了上面这个报错信息以外,其他的信息务必通过,直到没有问题为止

##### Compile assets

    bundle exec rake assets:precompile RAILS_ENV=production
    
## 7、Configure the web server
### nginx
> You will need a new version of nginx otherwise you might encounter an issue like this. To do so, follow the instructions provided by the nginx wiki and then install nginx with:
   
    yum update
    yum -y install nginx
    chkconfig nginx on
    
> Edit /etc/nginx/conf.d/gitlab and replace git.example.com with your FQDN. Make sure to read the comments in order to properly set up ssl.

    #Download an example site config:
    curl --output /etc/nginx/conf.d/gitlab https://raw.github.com/gitlabhq/gitlabhq/master/lib/support/nginx/gitlab

    #Make sure to edit the config file to match your setup:
    # **YOUR_SERVER_FQDN** to the fully-qualified
    # domain name of your host serving GitLab. Also, replace
    # the 'listen' line with the following:
    #   listen 80 default_server;         # e.g., listen 192.168.1.1:80;
    vim /etc/nginx/conf.d/gitlab
    cd /etc/nginx/conf.d
    mv default.conf default.conf.bak
    mv gitlab default.conf

##### Add nginx user to git group:

    usermod --G git nginx
    chmod g+rx /home/git/
    
##### Finally start nginx with:

    service nginx start
    
## 8、Configure the firewall
> Poke an iptables hole so users can access the web server (http and https ports) and ssh.

    lokkit -s http -s https -s ssh

> Restart the service for the changes to take effect:

    service iptables restart
    
## Double-check Application Status
> 这部分都是官方的解释信息,上面也已经介绍过了。
> To make sure you didn't miss anything run a more thorough check with:

    cd /home/git/gitlab
    sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
    
> Now, the output will complain that your init script is not up-to-date as follows:

    Init script up-to-date? ... no
      Try fixing it:
      Redownload the init script
      For more information see:
      doc/install/installation.md in section "Install Init Script"
      Please fix the error above and rerun the checks.

> Do not mind about that error if you are sure that you have downloaded the up-to-date file from https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn and saved it to /etc/init.d/gitlab.

> If all other items are green, then congratulations on successfully installing GitLab! However there are still a few steps left.

## initial Login
> Visit YOUR_SERVER in your web browser for your first GitLab login. The setup has created an admin account for you. You can use it to log in:

    admin@local.host
    5iveL!fe

##### Important Note: 
Please go over to your profile page and immediately change the password, so nobody can access your GitLab by using this login information later on.

##### Enjoy!

 

转载于:https://my.oschina.net/songmingming/blog/226450

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值