Gitlab CE 8.1.3 安装手册汉化版

来源:互联网 发布:sketch有没有windows版 编辑:程序博客网 时间:2024/05/16 05:36

GGitlab CE 8.1.3 安装手册汉化版

  • Gitlab的安装过程主要包括以下组件的配置:
    • 安装软件包及解决依赖项
    • Ruby环境
    • Go
    • 系统用户
    • 数据库(Mysql/Postgresql)
    • Redis
    • Gitlab-CE
    • Nginx
    • 非必要条件:点击链接加入群【GitLab交流群】

    1.安装软件包及解决依赖项

    Debian系统默认是没有sudo的.确保你的系统已经更新到最新状态,并安装sudo.

    #run as root!apt-get update -yapt-get upgrade -yapt-get install sudo -y
    • 安装系统必要的软件包:
    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

    如果你要用Kerberos来验证用户,需要另外安装libkrb5-dev:

    sudo apt-get install libkrb5-dev

    如果你不知道Kerberos是干嘛使得,就不用安装上面的libkrb5-dev了.

    • 安装git
    # 安装Gitsudo apt-get install -y git-core#检查git的版本,确保git版本不小于1.7.10git --version

    如果系统包里的git版本过旧,可以删除系统自带的,然后用源码编译最新的git.

    # 删除gitsudo apt-get remove git-core# 安装依赖sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential#下载并编译源码cd /tmpcurl -L --progress https://www.kernel.org/pub/software/scm/git/git-2.4.3.tar.gz | tar xzcd git-2.4.3/./configuremake prefix=/usr/local all# 安装到/usr/local/bin目录sudo make prefix=/usr/local install# 当编辑config/gitlab.yml(step 5),修改git路径为/usr/local/bin/git

    注意:为了让Gitlab拥有发送通知邮件的功能,你需要安装一个邮件服务.在Debian系统上默认自带一个exim4的附件,但是Ubuntu上并没有附带这个.Ubuntu上我们可以安装Postfix来发送邮件.

    sudo apt-get install -y postfix

    然后选择Internet Site回车后再确认下主机名.

    2.Ruby环境

    在Gitlab生产环境使用Ruby版本管理工具RVM,rbenv或者chruby常常会带来很多疑难杂症.比如Gitlab-shell版本管理器调用OpenSSH的功能以防止越过ssh对仓库进行pull和push操作.而前面提到的三个版本管理器不支持这样的功能,所以我们强烈建议大家按照下面的方式来安装Ruby.

    如果系统上存在旧的Ruby1.8,先删除掉:

    sudo apt-get remove ruby1.8

    下载Ruby源码,编译安装:

    mkdir /tmp/ruby && cd /tmp/ruby# 这里替换官方文档的下载地址为ruby.taobao.com提供的镜像地址curl -O --progress https://ruby.taobao.org/mirrors/ruby/ruby-2.2.2.tar.gz tar xzf ruby-2.2.2.tar.gzcd ruby-2.2.2./configure --disable-install-rdocmakesudo make install

    国内使用Ruby的Gem和Bundler必须要做的事情:

    # 修改gem安装源为淘宝源$ sudo gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/$ sudo  gem sources -l*** CURRENT SOURCES ***https://ruby.taobao.org

    安装Bundler Gem:

    sudo gem install bundler --no-ri --no-rdoc# 修改bundler的源为淘宝源 注:下面一句因为系统还未创建git用户,需要先执行“4.系统用户”的指令后才可以继续sudo -u git -H bundle config mirror.https://rubygems.org https://ruby.taobao.org

    3.Go

    从Gitlab8.0开始,Git的HTTP请求由gitlab-git-http-server来处理.我们需要Go编译器来安装gitlab-git-http-server.下面一系列的指令都将假定你用的是64位的Linux系统.你也可以在GoLang官方网站下载其他平台的Go编译器.

    #注:下面地址有问题,下载后会是个空包。可以访问https://golang.org/dl/这个网站,手动下载相应版本的go
    #另外需要注意的是,去上面那个网站下载时候要注意先查看一下自己机器是32位还是64位Ubuntu,具体方法可以用$uname -a 查看

    mkdir /tmp/go && cd /tmp/gocurl -O --progress http://www.golangtc.com/static/go/go1.5.1/go1.5.1.linux-amd64.tar.gz echo '46eecd290d8803887dec718c691cc243f2175fe0  go1.5.1.linux-amd64.tar.gz' | shasum -c - && \  sudo tar -C /usr/local -xzf go1.5.1.linux-amd64.tar.gzsudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/rm go1.5.1.linux-amd64.tar.gz
  • 4.系统用户

    为GitLab创建一个名为git的用户:

    sudo adduser --disabled-login --gecos 'GitLab' git

    5.数据库

    Gitlab官方建议我们用PostgreSQL数据库.如果喜欢用Mysql请前往Gitlab使用Mysql数据库的安装说明.

    注意:Gitlab使用的部分扩展插件需要PostgreSQL版本至少为9.1.

    # 安装数据库软件包sudo apt-get install -y postgresql postgresql-client libpq-dev# 使用系统用户postgres登录到PostgreSQL,目标数据库为template1sudo -u postgres psql -d template1# 为Gitlab创建一个用户# 不要输入 'template1=#', 这是PostgreSQL的提示符template1=# CREATE USER git CREATEDB;# 创建Gitlab生产环境数据库并赋予git用户属主权限template1=# CREATE DATABASE gitlabhq_production OWNER git;# 退出数据库会话template1=# \q# 用git用户测试下是否能登录刚才创建的数据库sudo -u git -H psql -d gitlabhq_production# 退出数据库会话gitlabhq_production> \q

    6.Redis

    sudo apt-get install redis-server# 配置redis使用socket来监听sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig# 把'post'设置为0以禁止监听TCP端口sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf# Enable Redis socket for default Debian / Ubuntu pathecho 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf# 给redis用户组的所有成员授权echo 'unixsocketperm 770' | sudo tee -a /etc/redis/redis.conf# 创建存放socket的目录mkdir /var/run/redissudo chown redis:redis /var/run/redissudo chmod 755 /var/run/redis# Persist the directory which contains the socket, if applicableif [ -d /etc/tmpfiles.d ]; then  echo 'd  /var/run/redis  0755  redis  redis  10d  -' | sudo tee -a /etc/tmpfiles.d/redis.conffi# 应用新的 redis.confsudo service redis-server restart# 把git用户加入redis组sudo usermod -aG redis git<code class="language-bash hljs"></code>

    7.Gitlab(重头戏来了)

    # 我们将gitlab安装到git用户的HOME目录cd /home/git

    克隆Gitlab源码

    # 克隆GIT@OSC上的Gitlab源码sudo -u git -H git clone http://git.oschina.net/qiai365/gitlab-ce.git -b 8-1-stable gitlab

    如果你想体验最新的非稳定版,你也可以克隆master分支,但是不赞同在生产服务器上使用master分支.

    配置Gitlab

    # 进入Gitlab安装目录cd /home/git/gitlab# 创建Gitlab主配置文件'gitlab.yml'sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml# 更新配置文件sudo -u git -H vim config/gitlab.yml# 创建 secrets 配置文件sudo -u git -H cp config/secrets.yml.example config/secrets.ymlsudo -u git -H chmod 0600 config/secrets.yml# 修改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/# 修改 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 -p public/uploadssudo chmod -R u+rwX  public/uploads# 修改CI编译和存储目录的权限sudo chmod -R u+rwX builds/# 创建 Unicorn 配置文件sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb# 查询CPU核心数nproc# 如果你想搭建一个高负载的Gitlab实例,可启用集群模式.# 修改'worker_processes'参数,至少要跟cpu核心数一样.# 举例:为2G RAM的服务器修改workers数量为3sudo -u git -H vim config/unicorn.rb# 创建Rack attack 配置文件sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb# Configure Git global settings for git user, used when editing via web editorsudo -u git -H git config --global core.autocrlf input# 配置 Redis 选项sudo -u git -H cp config/resque.yml.example config/resque.yml# 如果之前修改过redis socket的路径,在这个配置文件里面修改为当前的路径.sudo -u git -H vim config/resque.yml

    重要提示: 一定要按照你自己的情况修改gitlab.ymlunicorn.rb

    修改Gitlab 数据库设置

    # 此命令仅针对PostgreSQl:sudo -u git cp config/database.yml.postgresql config/database.yml# 此命令仅针对MySQL:sudo -u git cp config/database.yml.mysql config/database.yml# 以下修改针对MySQL和远程PostgreSQL:# 修改username/password.# 生产环境只需要修改第一部分即可.# 修改'secure password' 为你设置的密码# 密码字段可以使用"双引号" sudo -u git -H editor config/database.yml# PostgreSQL MySQL都适用:# 修改database.yml的权限,确保git用户可以读取该文件.sudo -u git -H chmod o-rwx config/database.yml

    安装Gems

    这个步骤是很多新手头疼的问题,不过你只要严格按照本文关于Ruby环境的搭建来做.还是可以保证你顺利的安装下来的.

    Note: 自bundler1.5.2起,你可以使用bundle install -jN(N就是cpu核心数)安装Gems,速度比之前要快大约60%.详细的内容可以点此处查看.不过首先要确保你的bundler版本>=1.5.2(运行bundle -v查看).

    # PostgreSQL 环境sudo -u git -H bundle install --deployment --without development test mysql aws kerberos# MySQL 环境sudo -u git -H bundle install --deployment --without development test postgres aws kerberos

    Note:如果想使用kerberos来验证用户,在--with-out选项里面排除kerberos

    安装GitLab Shell

    GitLab Shell是专为GitLab开发的ssh访问和仓库管理的软件.

    # 运行安装gitlab shell的任务 (根据自己的redis安装情况修改`REDIS_URL`),这里如果你事先没有clone gitlab-shell的仓库,就会自动clone官方的仓库进行安装:sudo -u git -H bundle exec rake gitlab:shell:install[v2.6.6] 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-git-http-server

    cd /home/gitsudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-git-http-server.gitcd gitlab-git-http-serversudo -u git -H git checkout 0.3.0sudo -u git -H make

    初始化数据库,激活高级特性

    # 进入Gitlab安装目录cd /home/git/gitlabsudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production#  输入 'yes' 来创建数据库表.#  初始化完成后,会显示 'Administrator account created:',这里会输出默认账号和密码Administrator account created:login.........rootpassword......5iveL!fe

    Note:你也可以设置环境变量GITLAB_ROOT_PASSWORD,这样在初始数据库的时候就会使用你指定的密码,否则就是上面的默认密码.

    sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword

    安全设置 secrets.yml

    secrets.yml文件为每个会话和安全变量存储密钥.把这个文件备份到别的地方,但是不要和数据库备份放在一块,否则你的数据库备份损坏会导致这个文件丢失.

    安装Gitlab启动脚本

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

    设置Gitlab为开机自启动

    sudo update-rc.d gitlab defaults 21

    配置Logrotate

    sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/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# orsudo /etc/init.d/gitlab restart

0 0