开放原子开发者工作坊 GitLab CE 9-3-stable源码安装手册(Centos6/REHL6)

GitLab CE 9-3-stable源码安装手册(Centos6/REHL6)

官方文档:https://docs.gitlab.com/ee/install/installation.html推荐使用yum安装:https://blog.51cto.com/qiangsh/1945313概述本帖针对Centos6/REHL6系统Gitlab的安装过程主要包括以下组件的配置:关闭selinux...

官方文档:https://docs.gitlab.com/ee/install/installation.html

推荐使用yum安装:https://blog.51cto.com/qiangsh/1945313

概述

本帖针对Centos6/REHL6系统Gitlab的安装过程主要包括以下组件的配置:

  • 关闭selinux

# 修改/etc/selinux/config 文件
 将SELINUX=enforcing改为SELINUX=disabled ,然后重启电脑
 # sestatus -v 查看selinux状态
 SELinux status:     disabled     #说明已关闭selinux
  • GitLab软件包 

  • 所有GitLab软件包都会发布到我们的软件包服务器上,并且可以下载。我们维持五个回购:

  • GitLab EE:适用于官方企业版版本

  • GitLab CE:用于官方Community Edition版本

  • Unstable:适用于发布候选版和其他不稳定版本

  • Nighty Builds:每晚制作

  • 安装软件包及版本要求

  • Ubuntu/Debian/CentOS/RHEL**

  • ruby 2.0+

  • git 1.7.10+

  • redis 2.0+

    MySQL or PostgreSQ


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

添加EPEL源:

wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-6
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
# 安装`epel-release-latest-6.noarch.rpm`包,启用EPEL
rpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest-6.noarch.rpm
yum groupinstall "Development tools"
yum install autoconf automake bison build-essential byacc checkinstall cmake cpio crontabs curl curl-devel db4-devel expat-devel gcc-c++ gdbm-devel gettext gettext-devel glibc-devel libcurl4-openssl-dev libexpat1-dev libffi libffi-dev libffi-devel libgdbm-dev libicu libicu-dev libicu-devel libkrb5-dev libncurses5-dev libreadline-dev libssl-dev libtool libxml2 libxml2-dev libxml2-devel libxslt libxslt-dev libxslt-devel libyaml libyaml-dev libyaml-devel libz-dev logrotate logwatch make ncurses-devel openssh-server openssl-devel patch pcre-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-Time-HiRes pkg-config postfix python-devel python-docutils readline readline-devel sqlite-devel sudo system-config-firewall-tui tcl-devel vim wget zlib1g-dev zlib-devel

安装git(不建议升级到最新版本,会报错)
如果已经用yum安装过git,并且版本低于2.7.4,要先卸载掉旧的版本

yum remove git

使用源码编译安装git

mkdir /tmp/git && cd /tmp/git
curl -O --progress https://www.kernel.org/pub/software/scm/git/git-2.8.5.tar.gz
tar zxvf git-2.8.5.tar.gz
cd git-2.8.5
./configure
make prefix=/usr/local all
# 安装到/usr/local/bin
sudo make prefix=/usr/local install
# 验证git版本号
git --version
#创建软连接
ln -s /usr/local/bin/git /usr/bin/git

2.添加系统用户

我们添加一个用来管理运行Gitlab的用户git

adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
# 修改git用户的环境变量PATH,以root用户运行
visudo
# 找到下面一行
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
#修改为
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

3.安装ruby环境

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

Note: The current supported Ruby (MRI) version is 2.3.x. GitLab 9.0 dropped

support for Ruby 2.1.x.

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

yum remove ruby
  1. 下载Ruby源码,编译安装:

mkdir /data/package
# 这里替换官方文档的下载地址为mirrors.ustc.edu.cn提供的镜像地址
curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.7.tar.gz
tar zxvf ruby-2.3.7.tar.gz
cd ruby-2.3.7
./configure --disable-install-rdoc
make
sudo make install
安装完成后,重新登录终端确保$PATH生效,检测ruby的安装成功与否:
ruby -v
ln -s /usr/local/bin/ruby /usr/bin/ruby
  1. 国内使用Ruby的Gem和Bundler必须要做的事情:

# 修改git用户gem安装源为淘宝
sudo -u git -H gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/  
# 确保git用户当前gems源为淘宝
sudo -u git -H gem sources -l
*** CURRENT SOURCES ***

备:gems源中科大: https://gems.ruby-china.org/
  1. 安装bundle包(root用户)

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

4.安装GO

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

#删除旧的文件夹
sudo rm -rf /usr/local/go

cd /data/package
curl --remote-name --progress https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
tar -C /usr/local/ -xzf go1.8.3.linux-amd64.tar.gz
sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/

#验证go是否安装正确
# go version
go version go1.8.3 linux/amd64

5.安装Node

因为 GitLab 9.X.X, GitLab 需要使用node >= v4.3.0 编译javascript 资产和 yarn >= v0.17.0 to 管理 javascript 

的依赖.在许多发行版的官方套件库提供的版本已经过时了,所以我们需要通过以下命令安装: 

Node安装文档:https://blog.51cto.com/qiangsh/2095944

# install yarn
npm install -g yarn

#验证安装情况
yarn --version

6.安装数据库

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

6-1.安装数据库-mysql

安装mysql数据库,设置数据库管理员密码

#下载yum仓库文件:
wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
#下载完成后将Yum库导入到你的本地:
sudo yum localinstall mysql-community-release-el6-*.noarch.rpm   
#安装MySQLServer:
yum install mysql-server mysql-devel mysql-client libmysqlclient-dev
#启动mysql服务
/etc/init.d/mysqld start
#MySQL安全配置向导
mysql_secure_installation    
---------------------------------------------------------------------------------
  Enter current password for root (enter for none):  <–初次运行直接回车
  Set root password? [Y/n]   <– 是否设置root用户密码,输入y并回车或直接回车
  Remove anonymous users? [Y/n]   <– 是否删除匿名用户,生产环境建议删除,所以直接回车
  Disallow root login remotely? [Y/n]  <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
  Remove test database and access to it? [Y/n]   <– 是否删除test数据库,直接回车
  Reload privilege tables now? [Y/n]   <– 是否重新加载权限表,直接回车

创建新用户和数据库给gitlab使用

# 登录数据库
$ mysql -u root -p
# 输入root密码
# 为gitlab创建使用用户
mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitlab账号的密码';
# 创建gitlaba使用的数据库
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# 给予gitlab用户权限
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost' IDENTIFIED BY 'gitpasswd';
# 刷新权限
mysql> flush privileges;
# 查看创建的用户
mysql> select user,host,password from mysql.user;

#测试新建的用户能否登陆mysql

mysql -u git -p -h localhost
mysql> show databases;
+---------------------+
| Database            |
+---------------------+
| information_schema  |
| gitlabhq_production |
+---------------------+
2 rows in set (0.00 sec)

6-2.安装数据库-postgresql

配置postgresql安装源:https://wiki.postgresql.org/wiki/YUM_Installation#Configure_your_YUM_repository

# 修改/etc/yum.repos.d/CentOS-Base.repo,在[base]和[update]段落添加下面的配置
exclude=postgresql*
# 安装postgresql源
yum localinstall http://mirrors.ustc.edu.cn/postgresql/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm
# 安装postgresql
yum install postgresql95-server postgresql95-devel postgresql95-contrib
# 默认情况下,postgresql的数据库文件存放在
/var/lib/pgsql/9.5/data

# 初始化
mv /etc/init.d/{postgresql-9.5,postgresql}
service postgresql initdb
# 启动postgresql
service postgresql start
# 配置postgresql自启动
chkconfig postgresql on

# 为Gitlab创建一个用户,用户名为git
cd /home
sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;"
#创建pg_trgm扩展 (required for GitLab 8.6+):
sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
# 创建Gitlab生产环境数据库并赋予git用户属主权限
sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;"
# 用git用户测试下是否能登录刚才创建的数据库
sudo -u git -H psql -d gitlabhq_production
#检查是否启用 pg_trgm 扩展:
SELECT true AS enabled
FROM pg_available_extensions
WHERE name = 'pg_trgm'
AND installed_version IS NOT NULL;
如果启用了扩展,这将产生以下输出:
 enabled
---------
 t
(1 row)
# 退出数据库会话
gitlabhq_production> \q

# 创建pg_config的软连接
ln -s /usr/pgsql-9.5/bin/pg_config /usr/bin/pg_config

7.Redis

版本要求: redis版本不低于2.8.

添加redis用户和组

groupadd redis && useradd -g redis redis -s /sbin/nologin
  1. 编译安装redis

mkdir /tmp/redis && cd /tmp/redis
curl -O --progress http://download.redis.io/releases/redis-3.2.9.tar.gz
tar zxvf redis-3.2.9.tar.gz
mv redis-3.2.9 /usr/local/redis
cd /usr/local/redis
make && make install
mkdir -p /etc/redis
cp redis.conf /etc/redis/
  1. 修改redis配置

sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.bak
# 让redis以socket方式启动
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf
#给所有成员或redis组赋予权限
echo 'unixsocketperm 770' | sudo tee -a /etc/redis/redis.conf
# 启动守护进程
sed -i 's/daemonize no/daemonize yes/g' /etc/redis/redis.conf

# 创建存放socket的目录
mkdir /var/run/redis
sudo chown redis:redis /var/run/redis
sudo 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

# 把git用户加入redis组
sudo usermod -aG redis git
  1. 启动Redis

# 下载redis init 脚本
curl -L http://packages.gitlab.cc/install/init-script/redis/cenots6/redis-server -o /etc/init.d/redis
chmod +x /etc/init.d/redis
# 启动redis服务
service redis start
# 将redis加入自启动
chkconfig redis on
# 查看redis进程是否启动
ps aux |grep redis
root      3404  0.0  0.0 103320   888 pts/2    S+   18:00   0:00 grep redis
root      6198  0.5  0.1 137764 10028 ?        Ssl  10:29   2:20 /usr/local/bin/redis-server 127.0.0.1:6379

8.安装GitLab-CE

# 我们将gitlab安装到git用户的HOME目录
cd /home/git
克隆gitlab-ce源码
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 9-3-stable gitlab

Note: 你可以修改9-3-stable为master,这样就可以体验到最新的版本,但是生产环境不要用master分支哦

配置GitLab-CE
# 进入gitlab目录
cd /home/git/gitlab

# 复制gitlab.yml(Gitlab的主配置文件)
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

# 修改gitlab.yml
sudo -u git -H vim config/gitlab.yml
    host: gitlab.xxx.com  ####修改第32行 为你的域名或者ip
    port: 80
    https: false

# 复制 secrets 文件
sudo -u git -H cp config/secrets.yml.example config/secrets.yml
sudo -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 public/uploads/

# 修改 public/uploads/ 文件夹权限,只有git用户有访问权限
sudo chmod 0700 public/uploads

# 修改 CI build traces are stored 文件夹的权限
sudo chmod -R u+rwX builds/

# 修改shared/artifacts/文件夹的权限
sudo chmod -R u+rwX shared/artifacts/

# 修改shared/pages/文件夹的权限
sudo chmod -R ug+rwX shared/pages/

# 复制 Unicorn 配置文件
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

# 查询CPU核心数
nproc

# 如果你想搭建一个高负载的Gitlab实例,可启用集群模式.
# 修改'worker_processes'参数,至少要跟cpu核心数一样.
# 修改监听地址和端口,要和下文 gitlab-shell/config.yml 中配置一致
sudo -u git -H vim config/unicorn.rb
    worker_processes 3
    listen "your_IP:8080", :tcp_nopush => true

# 复制Rack attack 配置文件
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

# 为 git 用户配置用户和邮件
sudo -u git -H git config --global user.name "Gitlab"
sudo -u git -H git config --global user.email "gitlab@your_domain_name"
 
# 'autocrlf' 需要Web编辑器
sudo -u git -H git config --global core.autocrlf input

# 禁止 'git gc --auto' 因为需要时 GitLab 已经运行 'git gc'
sudo -u git -H git config --global gc.auto 0

# Enable packfile bitmaps
sudo -u git -H git config --global repack.writeBitmaps true

# Enable push options
sudo -u git -H git config --global receive.advertisePushOptions true

# 复制 Redis 连接配置文件
sudo -u git -H cp config/resque.yml.example config/resque.yml

# 如果之前修改过redis socket的路径,在这个配置文件里面修改为当前的路径.
sudo -u git -H vim config/resque.yml
-------------------------------------
development: redis://127.0.0.1:6379
test: redis://127.0.0.1:6379
production: unix:/var/run/redis/redis.sock

要说明:确保编辑gitlab.yml与unicorn.rb中设置一致。

注意:如果您想使用HTTPS,请参阅使用HTTPS获取其他步骤。

修改GitLab DB 设置

# 仅限于Mysql:
sudo -u git cp config/database.yml.mysql config/database.yml
# 仅限于PostgreSQl:
###sudo -u git cp config/database.yml.postgresql config/database.yml

# 以下修改针对MySQL和远程PostgreSQL,修改username/password.
# 修改'secure password' 为你设置的密码,没单独设置则不改 
sudo -u git -H vim config/database.yml
production:
  adapter: mysql2
  encoding: utf8
  collation: utf8_general_ci
  reconnect: false
  database: gitlabhq_production
  pool: 10
  username: git
  password: "gitpasswd"   #修改此处为你设置的密码
  # host: localhost
  # socket: /tmp/mysql.sock
  socket: /var/lib/mysql/mysql.sock

# 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查看).

# 进入gitlab目录
cd /home/git/gitlab

gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
# 修改 Gemfile 和 Gemfile.lock
vim Gemfile(Gemfile.lock文件也要改,不然报错)
更改
https://rubygems.org/ 
为:  
https://ruby.taobao.org/
# 确保只有 https://ruby.taobao.org/
gem sources -l
    https://ruby.taobao.org/

# 升级gem
gem update --system
gem -v 

####一定要注意选择自己用的数据库的命令
# 如果使用 MySQL,执行下面的命令 (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws kerberos

# PostgreSQL (note, the option says "without ... mysql")
###sudo -u git -H bundle install --deployment --without development test mysql aws kerberos

笔记: 如果你想去用 Kerberos 做用户认证, 然后在--without选项中省略Kerberos
--------------------------------------------------------------------------------------------
如果提示下面的错误:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
error occurred while installing charlock_holmes (0.7.3), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v ‘0.7.3’` succeeds before bundling.
brew install icu4c or apt-get install libicu-dev
解决办法:
# yum install libicu.x86_64  libicu-devel.x86_64

An error occurred while installing rugged (0.25.1.1), and Bundler cannot continue.
Make sure that `gem install rugged -v '0.25.1.1'` succeeds before bundling.
解决办法:
# yum install cmake
# gem install rugged -v '0.25.1.1'

ERROR:  Could not find a valid gem 'charlock_holmes' (= 0.6.9.4), here is why:
          Unable to download data from https://rubygems.org/ - Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/charlock_holmes-0.6.9.4.gemspec.rz)
ERROR:  Possible alternatives: charlock_holmes
解决办法:
#yum install libicu-devel

An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue.
Make sure that `gem install mysql2 -v ‘0.3.20’` succeeds before bundling.
#解决办法
# yum install mysql-community-devel.x86_64
# gem install mysql2 -v '0.3.20

An error occurred while installing re2 (1.0.0), and Bundler cannot continue.
Make sure that `gem install re2 -v '1.0.0'` succeeds before bundling.
#解决办法
# yum install -y re2-devel

An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v ‘0.18.4’` succeeds before bundling.
#解决办法
# gem install pg -v '0.18.4'
# yum install postgresql-devel.x86_64

An error occurred while installing sqlite3 (1.3.13), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v ‘1.3.13’` succeeds before bundling.
# 解决办法
# yum install sqlite-devel.x86_64
# gem install sqlite3 -v '1.3.13'

Bundler::GemRequireError: There was an error while trying to load the gem ‘coffee-rails’.
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
#解决办法:因为execjs需要javascript的支持
#参考这里:NodeJs的安装

--------------------------------------------------------------------------------------------
----------以下不需要设置,草稿---------------------------
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
----------以上不需要设置,草稿---------------------------
安装Gitlab-shell

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

# 修改gitlab 安装 gitlab-shell的rake任务脚本
sudo -u git -H sed -i 's/https:\/\/gitlab.com\/gitlab-org\/gitlab-shell.git/https:\/\/git.oschina.net\/qiai365\/gitlab-shell.git/g'  /home/git/gitlab/lib/tasks/gitlab/shell.rake
 
# 运行安装gitlab shell的任务 (根据自己的redis安装情况修改`REDIS_URL`),这里如果你事先没有clone gitlab-shell的仓库,就会自动clone官方的仓库进行安装:
sudo -u git -H mkdir -p /home/git/repositories
sudo chmod -R ug+rwX,o-rwx /home/git/repositories
sudo chmod -R ug-s /home/git/repositories
sudo find /home/git/repositories -type d -print0 | sudo xargs -0 chmod g+s

# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
sudo -u git -H bundle exec rake gitlab:shell:install[v5.1.1] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true

# 默认情况下,gitlab-shell的配置是根据Gitlab的配置生产的.
# 你可以运行下面的命令查看和修改gitlab-shell的配置,
# 监听端口要和/home/git/gitlab/config/unicorn.rb中配置一致
sudo -u git -H vim /home/git/gitlab-shell/config.yml
---
user: git
gitlab_url:  https://localhost:8080/   #使用https 
http_settings:
  self_signed_cert: true       #如果gitlab_url为https,修改成true
repos_path: "/home/git/repositories/"
auth_file: "/home/git/.ssh/authorized_keys"
redis:
  bin: "/usr/bin/redis-cli"
  namespace: resque:gitlab
  socket: "/var/run/redis/redis.sock"
log_level: INFO
audit_usernames: false

注意:如果您想使用HTTPS,请参阅使用HTTPS获取其他步骤。

注意:请确保您的主机名可以通过适当的DNS记录或/ etc / hosts中的附加行(“127.0.0.1 hostname”)在机器上解析。例如,如果您将GitLab设置在反向代理之后,这可能是必需的。如果主机名无法解析,最终安装检查将会失败,并显示“Check GitLab API access:FAILED。code:401”,推送提交将被拒绝,并显示“[remote rejected] master - > master(hook refused)”。

注意:禁用RubyGems可以大大减少GitLab Shell应用程序的启动时间。这可以通过几种方式来完成:

安装成功如图所示:

0_1460111626143_gitlab-shell-install.png
安装gitlab-workhorse
#GitLab-Workhorse 使用 GNU Make. 下面的命令将GitLab-Workhorse 安装在推荐的位置 /home/git/gitlab-workhorse .
cd /home/git/gitlab
sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production
#你可以通过提供它作为一个额外的参数来指定一个不同的Git仓库:
sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse,https://example.com/gitlab-workhorse.git]" RAILS_ENV=production
------------------以下为旧安装方法------------------------------------------------
#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
------------------以上为旧安装方法------------------------------------------------
初始化数据库,激活高级特性
cd /home/git/gitlab

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

# 输入 'yes' 以创建数据库表

# 当看到以下内容,表示已经安装完成
Administrator account created:
login:    root
password: your_passwd
== Seed from /home/git/gitlab/db/fixtures/production/010_settings.rb

Note: 你能通过提供环境变量设置 Administrator/root 密码和邮箱, 分别为GITLAB_ROOT_PASSWORD 和 GITLAB_ROOT_EMAIL , 如下所示。如果你不能设置密码(它被设置为默认的) 请等待曝光gitlab到公共互联网直到安装完成和你已经登录到服务器的第一时间。 在第一次登录时,您将被迫更改默认密码。.

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail
安全设置 secrets.yml

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

安装Gitlab init脚本
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

#复制下面这个配置文件,如果你的gitlab不是安装在/home/git/gitlab目录,根据自己情况修改这个文件。

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

设置GItlab为自启动

chkconfig gitlab on
安装Gitaly
# 取用 Gitaly 源 用Git和Go一起编译
sudo -u git -H bundle exec rake "gitlab:gitaly:install[/home/git/gitaly]" RAILS_ENV=production
你可以通过提供它作为一个额外的参数来指定一个不同的Git仓库:
sudo -u git -H bundle exec rake "gitlab:gitaly:install[/home/git/gitaly,https://example.com/gitaly.git]" RAILS_ENV=production
接下来, 确保gitaly配置:
# 限制 Gitaly sockets访问
sudo chmod 0700 /home/git/gitlab/tmp/sockets/private
sudo chown git /home/git/gitlab/tmp/sockets/private

# 如果你正在用non-default 设置 你必须升级config.toml
cd /home/git/gitaly
sudo -u git -H vim config.toml

For more information about configuring Gitaly see doc/administration/gitaly.

设置Logrotate
cd /home/git/gitlab
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检查GitLab环境配置
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

效果如图

0_1460180421690_gitlab-check-env.png

 
编译GetText PO文件
sudo -u git -H bundle exec rake gettext:compile RAILS_ENV=production
 
生成GitLab前端资源
sudo -u git -H yarn install --production --pure-lockfile    #我这步失败了,先略过
sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production NODE_ENV=production
通过修改/home/git/gitlab/config/unicorn.rb的listen端口,然后重启gitlab服务,就可以直接访问服务器ip加端口来访问gitlab了
启动GitLab
sudo service gitlab start
# 或者
sudo /etc/init.d/gitlab restart
再检查一次Gitlab的所有组件
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
# 如果上面的检查有错误,按照提示修复下,再重启GitLab即可
ERR!测试页面发现页面加载不正常
#查看日志信息:
[root@localhost /home/git/gitlab]#tail -f /data/git/gitlab/log/production.log
Processing by RootController#index as HTML
Completed 200 OK in 14125ms (Views: 10108.5ms | ActiveRecord: 2021.7ms)
Started GET "/assets/webpack/webpack_runtime.ec49ef50bd580f1196e6.bundle.js" for 192.168.137.1 at 2017-08-20 18:24:48 +0800
Processing by ApplicationController#route_not_found as JS
  Parameters: {"unmatched_route"=>"assets/webpack/webpack_runtime.ec49ef50bd580f1196e6.bundle"}
Started GET "/assets/application-898ebef5c8f2218228603404f2aad91aa380408797ddc6050f4893b61bee9616.css" for 192.168.137.1 at 2017-08-20 18:24:54 +0800
Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.
Completed 422 Unprocessable Entity in 2698ms (ActiveRecord: 100.1ms)

#解决方法:
1、编辑/home/git/gitlab/config/environments/production.rb ,将 config.serve_static_files = false 替换为 true:
  config.serve_static_files = true
2、然后重启下GITLAB
sudo /etc/init.d/gitlab restart

8.安装Nginx

Note: Nginx is the officially supported web server for GitLab. If you cannot or do not want to use Nginx as your web server, have a look at the GitLab recipes.

mkdir /tmp/nginx && cd /tmp/nginx
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum install nginx

# 站点配置,复制示例站点配置
cd /home/git/gitlab
sudo cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf


# 编辑配置文件。如果其他用户安装Git,修改gitlab路径
sudo vim /etc/nginx/nginx.conf
user  git;   #修改为git用户
----------------------------------------------------------------------------
sudo vim /etc/nginx/conf.d/gitlab.conf
    server_name YOUR_SERVER_FQDN;       #修改你的域名地址
    listen 80 default_server;  
    
#检查nginx配置
sudo nginx -t
#启动nginx
sudo service nginx restart

恭喜,安装完成!

自定义SSH连接 

如果您在非标准端口上运行SSH,则必须更改GitLab用户的SSH配置。

# Add to /home/git/.ssh/confighost localhost          # Give your setup a name (here: override localhost)
    user git            # Your remote git user
    port 2222           # Your port number
    hostname 127.0.0.1; # Your server name or IP

您还需要改变相应的选项(例如ssh_userssh_hostadmin_uri中)config\gitlab.yml的文件。

 
 

初始登录 

访问您的Web浏览器中的YOUR_SERVER以获取第一次GitLab登录。

如果您在安装过程中提供root密码,则会重定向到密码重置屏幕以提供初始管理员帐户的密码。输入您想要的密码,然后您将被重定向回登录屏幕。

默认帐户的用户名是root。提供您之前创建的密码并登录。登录后,您可以根据需要更改用户名。

请享用!

您可以使用sudo service gitlab startsudo service gitlab stop启动和停止GitLab。

高级设置提示 

参考:https://bbs.gitlab.cc/topic/35/gitlab-ce-8-7-%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85%E6%89%8B%E5%86%8C-centos6-rehl6/2

https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐

  • 浏览量 313
  • 收藏 0
  • 0

所有评论(0)

查看更多评论 
已为社区贡献2条内容