zoukankan      html  css  js  c++  java
  • GitLab安装说明

    GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用。

    gitlab是基于Ruby on Rails的,安装和配置非常麻烦,不过有傻瓜安装包,https://about.gitlab.com/downloads/,或者,https://bitnami.com/stack/gitlab/installer。但是这两个包都是英文界面的,gitlab把界面提示写在每一个rb文件里了,所以,要用中文版的不能像redmine那样设定一下就行了。
    需要通过源码安装中文版giglab,代码地址:https://gitlab.com/larryli/gitlab,当前最新版为8.5.5。

    由于公司的操作系统普遍采用centos,为统一管理,我们仍在centos上进行安装,官方没有8.5.5在centos上的安装文档,参考Ubuntu安装手册https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md,以及7.0版在centos上的安装手册https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos

    开始之前

    在开始之前请先查看官方的刚需文档: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/requirements.md ,该文档说明了系统,软件和硬件等各方面的需求。详细的了解这些,可以避免碰到很多怪异的问题。

    安装步骤总览

    • 更新仓库源
    • 安装必须的软件包
    • 安装Ruby
    • 安装Go语言
    • 创建系统用户
    • 安装数据库Mysql
    • 安装Redis
    • 安装GitLab
    • 安装Nginx 

    0、更新仓库源

    这个比较简单,安装完成之后记的配置下网络,使其可以在启动时自动连接。而后需要升级系统和安装一些相应的软件和依赖包,以下逐一说明。 
    Tips:如果不能连接国外的网络,经常出现网络错误或者couldn’t not resolve host这样的错误,建议修改dns服务器为8.8.8.8和8.8.4.4。

    a、升级操作系统和安装wget

    $ sudo yum -y update
    	$ sudo yum -y install wget
    

    升级完成后,系统版本是6.7。

    b、增加EPEL安装源

    EPEL,即Extra Packages for Enterprise Linux,这个软件仓库里有很多非常常用的软件,而且是专门针对RHEL设计的,对RHEL标准yum源是一个很好的补充,完全免费使用,由Fedora项目维护,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的yum源。

    下载并安装GPG key

    $ sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
    	$ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    

    检验下是否安装成功

    $ sudo rpm -qa gpg*
    

    安装epel-release-6-8.noarch包

    $ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    

    提示:不要在意x86_64,在i686的机器上一样能使用。

    c、增加PUIAS安装源

    PUIAS Linux是面向桌面和服务器的完整的操作系统,它靠编译Red Hat Enterprise Linux的源代码包来创建。除了这些上游的软件包外,该项目还提供一些其他的软件仓库:“Addons”包含了通常的Red Hat发行中未收入的额外软件包,“Computational”提供专门针对科学计算的软件,“Unsupported”则收入各种各样的测试性软件 包。该发行由美国普林斯顿 大学的高等研究所维护。

    获取/etc/yum.repos.d/PUIAS_6_computational.repo

    $ sudo wget -O /etc/yum.repos.d/PUIAS_6_computational.repo https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/install/centos/PUIAS_6_computational.repo
    

    下载并安装GPG key

    $ sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
    	$ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
    

    检验下是否安装成功

    $ sudo rpm -qa gpg*
    

    Tips:安装完EPEL和PUIAS两个源后,可以检测下:

    $ sudo yum repolist
    

    c、增加REMI安装源

    $ sudo rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
    	$ sudo rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
    

       
    默认地,REMI是禁用的。要检查REMI是否已经成功安装,使用这个命令。你会看到几个REMI仓库,比如remi、remi-php55和remi-php56。

    $ yum repolist disabled | grep remi
    

    从REMI仓库中安装一个包 
    如上所述,最好保持禁用REMI仓库,只有在需要的时候再启用。 
    要搜索或安装REMI仓库中的包,使用这些命令: 
    代码如下:

    $ sudo yum --enablerepo=remi search
    	$ sudo yum --enablerepo=remi install
    

    Note: 安装过程中需要手工编辑某些文件。通过下面命令可以将VIM设置为默认编辑器

    安装vim并设置为默认编辑器(不知都什么原因,没生效)

    sudo yum -y install vim-enhanced
    sudo update-alternatives --set editor /usr/bin/vim.basic
    
    # For reStructuredText markup language support, install required package:
    yum -y install python-docutils
    

    1、安装GitLab的所需依赖包和工具

    a、安装依赖包

    $ su -
    # yum -y groupinstall 'Development Tools'
    # yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel 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 cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs
    

    b、安装git

    确定git版本在2.7.3及以上

    git --version
    

    系统默认版本为1.8.3,版本太老,删除并通过源代码安装

    删除安装的git

    yum -y remove git
    

    安装git依赖包

    $ sudo yum install curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel
    

    下载源码并编译安装 
    mkdir /tmp/git && cd /tmp/git 
    curl --progress https://www.kernel.org/pub/software/scm/git/git-2.8.2.tar.gz | tar xz 
    cd git-2.8.2/ 
    ./configure 
    make 
    make prefix=/usr/local install

    为确保$PATH环境变量生效,需要重新连接后执行git --version

    当编辑文件 config/gitlab.yml 时(第5步), 修改 git -> bin_path 为 /usr/local/bin/git

    c、安装邮件服务器

    接下来我们还要安装一个邮件服务器,官方推荐使用postfix

    yum install -y postfix
    

    接下来选择 'Internet Site' 并回车确定主机名

    2、安装Ruby

    注意:当前支持的Ruby版本为2.1.x. Ruby 2.2 和2.3尚不支持。

    下载并编译:

    su -
    mkdir /tmp/ruby && cd /tmp/ruby
    curl --progress https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.8.tar.gz | tar xz
    cd ruby-2.1.8
    ./configure --disable-install-rdoc
    make
    make prefix=/usr/local install
    

    安装完成后,重新登录终端确保$PATH生效,检测ruby的安装成功与否:

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

    Gitlab的包使用bundler进行依赖关系管理,所以还得安装。如果在国内的用户请先修改Ruby的源服务器

    gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
    gem sources -l
    

    安装bundle:

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

    如果提示sudo: gem: command not found,使用root账号登录执行该命令即可。

    3.安装Go语言支持

    在GitLab8.0以后HTTP请求开始依赖Go编译,所以我们要进行安装,这里要注意Go会区分操作系统位数

    mkdir /tmp/golang && cd /tmp/golang
    
    curl -O --progress https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz
    
    tar -C /usr/local -xzf go1.5.3.linux-amd64.tar.gz
    
    sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
    

    4、创建系统用户

    adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
    

    修改git用户的PATH路径

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

    修改为

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

    5.安装数据库

    注意:因为gitlab需要最低9.1版本,centos默认的8.x版postgreSQL无法支持, 需要添加 PGDG yum库,如果系统已安装postgresql需要先进行卸载:

    yum remove postgresql
    

    安装 pgdg 资源库:

    rpm -Uvh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
    wget https://www.postgresql.org/ftp/source/v9.3.8/postgresql-9.3.8.tar.gz 
    

    安装 postgresql93-server 以及 postgreqsql93-devel 包:

    yum install postgresql93-server postgresql93-devel
    

    可执行文件被安装在 /usr/pgsql-9.3/bin/。 为保证正常执行,需要将该路径添加到 $PATH 环境变量或创建链接。这里我们为gitlab创建链接:

    ln -s /usr/local/postgresql-9.3.8/bin/pg_dump /usr/bin/pg_dump
    ln -s /usr/local/postgresql-9.3.8/bin/pg_restore /usr/bin/pg_restore
    ln -s /usr/local/postgresql-9.3.8/bin/psql /usr/bin/psql
    

    重命名服务脚本为postgresql:

    mv /etc/init.d/{postgresql-9.3,postgresql}
    
    
    ln -s /usr/local/postgresql-9.3.8/bin/psql /usr/bin/psql
     

    初始化数据库:

    service postgresql initdb
    

    启动postgresql服务,并设置开机自动启动:

    service postgresql start
    chkconfig postgresql on
    

    配置数据库用户及密码

    su - postgres
    export PATH=$PATH:/usr/pgsql-9.3/bin/
    psql -d template1
    
    psql (9.4.3)
    Type "help" for help.
    template1=# CREATE USER git CREATEDB;
    CREATE ROLE
    template1=# CREATE DATABASE gitlabhq_production OWNER git;
    CREATE DATABASE
    template1=# q
    exit # exit uid=postgres, return to root
    

    使用 gitlab 用户 (uid=git) 测试连接,检查当前用户:

    whoami
    

    用 git 用户连接Postgres:

    sudo -u git psql -d gitlabhq_production
    

    显示如下提示:

    gitlabhq_production=>
    

    说明已经连接成功,可以通过 q 命令退出

    在 /var/lib/pgsql/9.3/data/pg_hba.conf 中配置认证方式及认证信息:

    host    all             all             127.0.0.1/32            trust
    

    6.安装Redis

    Gitlab要求Redis版本不低于2.8,系统默认安装版本为2.4.1,卸载当前版本并采用remi源安装最新版本:

    卸载当前redis:

    yum -y remove redis
    

    采用remi源安装最新版本:

    yum --enablerepo=remi install redis
    

    设置开机自动启动:

    chkconfig redis on
    Configure redis to use sockets:
    cp /etc/redis.conf /etc/redis.conf.orig
    

    Disable Redis listening on TCP by setting 'port' to 0:

    sed 's/^port .*/port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf
    

    Enable Redis socket for default CentOS path:

    echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf
    echo -e 'unixsocketperm 0770' | sudo tee -a /etc/redis.conf
    

    Create the directory which contains the socket

    mkdir /var/run/redis
    chown redis:redis /var/run/redis
    chmod 755 /var/run/redis
    

    Persist the directory which contains the socket, if applicable

    if [ -d /etc/tmpfiles.d ]; then
        echo 'd  /var/run/redis  0755  redis  redis  10d  -' | sudo tee -a /etc/tmpfiles.d/redis.conf
    fi
    

    Activate the changes to redis.conf:

    service redis restart
    

    Add git to the redis group:

    usermod -aG redis git
    

    7. GitLab

    我们将 GitLab 安装到 "git" 用户的home中:

    cd /home/git
    

    获取源代码

    选择中文版代码地址进行克隆,默认采用master版本,对应gitlab8.5.5

    sudo -u git -H git clone https://gitlab.com/larryli/gitlab.git gitlab
    

    配置gitlab

    进入gitlab安装目录

    cd /home/git/gitlab
    

    复制gitlab配置文件

    sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
    

    Update GitLab config file, follow the directions at top of file

    sudo -u git -H vim config/gitlab.yml
    

    修改 gitlab -> host 为主机域名 
    更新 gitlab -> email_from 为vp_svn@vprisk.com 
    修改 git -> bin_path 为 /usr/local/bin/git

    复制安全文件

    sudo -u git -H cp config/secrets.yml.example config/secrets.yml
    sudo -u git -H chmod 0600 config/secrets.yml
    

    保证 GitLab 对 log/ 和 tmp/ 目录具备写权限

    sudo chown -R git log/
    sudo chown -R git tmp/
    sudo chmod -R u+rwX,go-w log/
    sudo chmod -R u+rwX tmp/
    

    保证 GitLab 对 tmp/pids/ 和 tmp/sockets/ 目录具备写权限

    sudo chmod -R u+rwX tmp/pids/
    sudo chmod -R u+rwX tmp/sockets/
    

    创建 public/uploads/ 目录

    sudo -u git -H mkdir public/uploads/
    

    保证只有 GitLab 用户能够访问 public/uploads/ 目录 
    因此 public/uploads 中的文件通过 gitlab-workhorse 提供服务

    sudo chmod 0700 public/uploads
    

    修改 CI 构建跟踪存储目录权限

    sudo chmod -R u+rwX builds/
    

    修改 CI artifacts 存储目录权限

    sudo chmod -R u+rwX shared/artifacts/
    

    复制并创建 unicorn 配置文件

    sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
    

    查询内核数了

    nproc
    

    如果支持高负载可以启用集群设置 
    将 workers 数据设置为不小于CPU内核数量 
    Ex. change amount of workers to 3 for 2GB RAM server

    sudo -u git -H vim config/unicorn.rb
    

    通过复制 example 创建 Rack attack 配置文件

    sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
    

    为 git 用户配置全局 Git 配置,当使用 web 编辑器进行编辑时使用

    sudo -u git -H git config --global core.autocrlf input
    

    配置 Redis 连接

    sudo -u git -H cp config/resque.yml.example config/resque.yml
    

    Change the Redis socket path if you are not using the default Debian / Ubuntu configuration

    sudo -u git -H vim config/resque.yml
    

    Important Note: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.
    Note: If you want to use HTTPS, see Using HTTPS for the additional steps.

    配置 GitLab 数据库连接配置

    只采用 PostgreSQL 配置信息:

    sudo -u git cp config/database.yml.postgresql config/database.yml
    

    只为 git 用户分配 config/database.yml 的读权限

    sudo -u git -H chmod o-rwx config/database.yml
    

    安装 Gems

    修改 git 用户的Ruby的源服务器

    sudo -u git -H gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
    sudo -u git -H gem sources -l
    sudo -u git -H bundle config mirror.https://rubygems.org https://ruby.taobao.org
    

    PostgreSQL 数据库(不使用mysql)

    sudo -u git -H bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config
    sudo -u git -H bundle install --deployment --without development test mysql aws kerberos
    

    安装 GitLab Shell

    GitLab Shell 是一个 SSH 访问以及仓库管理软件,专门用于 GitLab。

    启动 gitlab-shell 安装任务 (请根据需要替换 REDIS_URL ):

    sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
    

    默认情况下, gitlab-shell 是根据 GitLab 配置信息生成的。 
    可以通过以下命令检查及修改 gitlab-shell :

    sudo -u git -H vim /home/git/gitlab-shell/config.yml
    

    Note: Make sure your hostname can be resolved on the machine itself by either a proper DNS record or an additional line in /etc/hosts ("127.0.0.1 hostname"). This might be necessary for example if you set up GitLab behind a reverse proxy. If the hostname cannot be resolved, the final installation check will fail with "Check GitLab API access: FAILED. code: 401" and pushing commits will be rejected with "[remote rejected] master -> master (hook declined)".

    安装 gitlab-workhorse

    cd /home/git
    sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
    cd gitlab-workhorse
    sudo -u git -H git checkout 0.6.5
    sudo -u git -H make
    

    初始化数据库及高级特性

    进入 Gitlab 安装目录

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

    输入 'yes' 创建数据库表结构

    完成时显示输出 'Administrator account created:'

    默认密码

    login.........root
    password......5iveL!fe
    

    本系统登录后修改为gitlab@2016

    Note: You can set the Administrator/root password and e-mail by supplying them in environmental variables, GITLAB_ROOT_PASSWORD and GITLAB_ROOT_EMAIL respectively, as seen below. If you don't set the password (and it is set to the default one) please wait with exposing GitLab to the public internet until the installation is done and you've logged into the server the first time. During the first login you'll be forced to change the default password.
    sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail
    Secure secrets.yml

    The secrets.yml file stores encryption keys for sessions and secure variables. Backup secrets.yml someplace safe, but don't store it in the same place as your database backups. Otherwise your secrets are exposed if one of your backups is compromised.

    安装启动脚本

    下载启动脚本 (位于 /etc/init.d/gitlab):

    sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
    chkconfig --add gitlab
    

    配置 GitLab 自动运行:

    chkconfig gitlab on
    

    安装 Logrotate

    sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
    

    检查应用状态

    检查 Gitlab 程序及环境是否正确配置:

    sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
    

    编译Assets

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

    启动 GitLab 服务

    sudo service gitlab start
    

    或者

    sudo /etc/init.d/gitlab restart
    

    8. 配置WebServer

    这里官方建议使用nginx,当然如果你对apache足够熟悉也可以改用apache。 
    首先配置nginx 源:

    vim /etc/yum.repos.d/nginx.repo 
    
    1. [nginx]
    2. name=nginx repo
    3. baseurl=http://nginx.org/packages/centos/6/$basearch/
    4. gpgcheck=0
    5. enabled=1
    yum -y  --enablerepo=nginx install nginx
    
    chkconfig nginx on
    

    如果你的机器上没能IPV6地址,一定要注释掉IPV6协议部分

    cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf
    

    添加用户nginx到git组

    usermod -a -G git nginx
    
    chmod g+rx /home/git/
    

    检查配置

    sudo nginx -t
    

    重启nginx:

    sudo service nginx restart
    

    安装完成!

    再次验证应用状态,保证安装过程中没有错过任何步骤,可以通过以下命令验证:

    sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
    

    如果所有检查项均显示为绿色,那么恭喜你完成了 Gitlab 中文版安装!

    转载自:http://blog.csdn.net/huangzhijie3918/article/details/51330425

  • 相关阅读:
    python 去除字符串两端字符串
    python 找到列表中满足某些条件的元素
    python join函数
    Ambiguous mapping. Cannot map "***Controller" been method解决办法
    uflo2安装与配置
    uflo2概述
    Mybatis-plus中的常用注解
    Spring Cloud Eureka配置文件详解 (还没细看)
    idea安装lombok
    PowerDesigner最基础的使用方法入门学习(一)
  • 原文地址:https://www.cnblogs.com/Wolfmanlq/p/5896168.html
Copyright © 2011-2022 走看看