本文章适用于需要自建gitlab代码管理系统,仅供参考

1. 环境准备

安装软件包及版本要求

1. Ubuntu/Debian/CentOS/RHEL
2. ruby 2.4+
3. git 2.7.2+
4. go 1.0.0+
5. redis 3.2+
6. node 8.0+
7. MySQL(5.7+) or PostgreSQ (9.4+)
8. gitlab ce 11-3-stable
9. nignx (1.12.2)

2. 安装所需要软件依赖包

添加EPEL源

# wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-7
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

安装基础软件以及相关依赖包

# rpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest-7.noarch.rpm
# yum groupinstall "Development tools"
# yum install autoconf automake bison expat-devel gcc-c++ zlib-devel mysql-devel \gdbm-devel re2-devel readline-devel ncurses-devel curl-devel libxml2-devel \libxslt-devel openssl-devel libicu-devel rsync python-docutils cmake  -y

3. 安装git (版本为2.18.x)

卸载原有的git包

# sudo yum remove git

安装git所需要的依赖包

# sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel

下载稳定版本的git源码包并安装

# cd /root
# curl --remote-name --location --progress https://www.kernel.org/pub/software/scm/git/git-2.18.0.tar.gz

解压并安装git

# cd /root
# tar xvf git-2.18.0.tar.gz -C /usr/local/src  &&  cd /usr/local/src/git-2.18.0/
# ./configure prefix=/usr/local/git all
# make && make install

设置git命令路径优化

# vim /etc/profile.d/git.sh
内容如下:
export GIT_HOME=/usr/local/git
export PATH=$GIT_HOME/bin:$PATH# source  /etc/profile.d/git.sh

4. 安装ruby (版本为2.4.x)

下载最新稳定版的ruby二进制源码包

# cd /root
# curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.4.tar.gz

编译安装ruby

# cd /root && tar zxvf ruby-2.4.4.tar.gz -C /usr/local/src
# cd /usr/local/src/ruby-2.4.4/
# ./configure  --prefix=/data/apps/ruby --disable-install-rdoc
# make && make install

设置ruby命令路径优化

# sudo vim /etc/profile.d/ruby.sh
内容如下:
export RUBY_HOME=/data/apps/ruby
export PATH=$RUBY_HOME/bin:$PATH# source  /etc/profile.d/ruby.sh

安装bundle命令

# gem install bundler --no-ri --no-rdoc
# ln -sf  /data/apps/ruby/bin/* /usr/local/bin/

5. 安装go (版本为1.10.x)

卸载原有的go命令包

# sudo rm -rf /usr/local/go

下载稳定版的go二进制源码包

# cd /root
# curl --remote-name --progress https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
# sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz
# sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
# rm go1.10.3.linux-amd64.tar.gz

6. 安装node (版本为8.0.x)

安装node.js应用 (这里版本为8.0以上)

# cd /root
# curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
# sudo yum install -y nodejs安装完node后安装yarn
# cd /root
# sudo yum install gcc-c++ make -y
# curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
# sudo yum install yarn -y

7. 安装redis (版本为3.2.x)

yum安装redis服务

# yum install redis -y

配置redis配置文件

# cat > /etc/redis.conf <<EOF
daemonize yes
bind localhost
protected-mode no
port 6379
tcp-backlog 65535
timeout 0
tcp-keepalive 300
pidfile /var/run/redis/redis.pid
unixsocket /var/run/redis/redis.sock
unixsocketperm 770
loglevel notice
logfile "/var/log/redis/redis.log"
databases 32
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir /data/apps/redis/db
EOF

对redis相关目录授权

# mkdir /var/run/redis
# mkdir /data/apps/redis/db -p
# chown -R redis:redis /data/apps/redis
# chown  redis:redis /var/run/redis
# chmod 755 /var/run/redis

8. 安装数据库 (版本为5.7.x)

这里使用的数据库为MySQL 5.7.0以上版本,数据库安装详情请参考https://docs.gitlab.com/ee/install/database_mysql.html

9. 安装nignx (版本为1.12.x)

有关nginx安装这里为yum安装,当然也可以根据自己的选择源码安装

# yum install nignx -y

10. 部署gitlab应用 (版本为11-3 stable版)

10.1 首先创建运行gitlab服务的git用户

# groupadd git
# useradd -g git -c "Gitlab Service" -d /data/apps/git git
# ln -sf /data/apps/git/ /home/git
# sudo usermod -aG git nignx
# sudo usermod -aG redis git

10.2 下载gitlab源码(这里版本为11-3-stable)

# cd /home/git
# sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 11-3-stable gitlab

10.3 修改gitlab相关配置文件并做相应的修改

拷贝gitlab模板并修改相关配置

# cd /home/git/gitlab
# sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# sudo -u git -H vim config/gitlab.yml找到如下行内容
## GitLab settings
gitlab:host: code.mo9.com  修改为你需要访问的域名port: 80 # Set to 443 如果需要https访问,开启HTTPS即可;## Git settingsgit:bin_path: /usr/local/git/bin/git  修改为git的命令执行路径time_zone: 'UTC'   修改为“Asia/Shanghai”

拷贝unicorn模板并编辑配置,修改如下

# sudo -u git -H vim config/unicorn.rb找到如下内容
worker_processes 3  (值修改为服务器的cpu数+1)
listen "127.0.0.1:8080", :tcp_nopush => true (该值为主机的ip)

拷贝database模板并编辑配置

# sudo -u git cp config/database.yml.mysql config/database.yml
# sudo -u git -H chmod o-rwx config/database.yml
# sudo -u git -H vim config/database.yml修改内容如下(此处仅为模板)
#
# PRODUCTION
#
production:adapter: mysql2encoding: utf8collation: utf8_general_cireconnect: falsedatabase: gitlabpool: 10username: rootpassword: "1qaz@WSX"host: rm-bp1lsjz89883fih35.mysql.rds.aliyuncs.com

拷贝resque模板并编辑配置

# sudo -u git -H cp config/resque.yml.example config/resque.yml
# sudo -u git -H vim config/resque.yml修改内容如下(此处仅为参考模板,如果需要配置redis集群请详见官网配置说明)
# If you change this file in a Merge Request, please also create
# a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
#
production:# Redis (single instance)url: unix:/var/run/redis/redis.sock##

拷贝secrets文件模板并授权(注意此文件内容自动生成, 在迁移gitlab需要用到该文件)

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

对gitlab相关目录授权

# sudo chown -R git log/
# sudo chown -R git tmp/
# sudo chmod -R u+rwX,go-w log/
# sudo chmod -R u+rwX tmp/
# sudo chmod -R u+rwX tmp/pids/
# sudo chmod -R u+rwX tmp/sockets/
# sudo -u git -H mkdir public/uploads/
# sudo chmod 0700 public/uploads
# sudo chmod -R u+rwX builds/
# sudo chmod -R u+rwX shared/artifacts/
# sudo chmod -R ug+rwX shared/pages/

拷贝rack_attack.rb文件模板

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

设置git初始参数

# sudo -u git -H git config --global core.autocrlf input
# sudo -u git -H git config --global gc.auto 0
# sudo -u git -H git config --global repack.writeBitmaps true
# sudo -u git -H git config --global receive.advertisePushOptions true

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

由于默认的ruby源地址访问会存在网络访问慢的问题,所以需要更换为国内的ruby源

# cd /home/git/gitlab
# gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
# gem sources -lhttps://gems.ruby-china.com  (确保只有 https://gems.ruby-china.com/)使用git用户修改Gemfile 和 Gemfile.lock
更改 https://rubygems.org/ 为: https://gems.ruby-china.com/

安装gems包

For PostgreSQL (note, the option says "without ... mysql")
# sudo -u git -H bundle install --deployment --without development test mysql aws kerberosOr if you use MySQL (note, the option says "without ... postgres")
# sudo -u git -H bundle install --deployment --without development test postgres aws kerberos上述命令执行完后,结果如下:
Bundle complete! 226 Gemfile dependencies, 321 gems now installed.
Gems in the groups development, test, postgres, aws and kerberos were not installed.
Bundled gems are installed into `./vendor/bundle`

注意:在安装gems过程中,可能会遇到以下错误:

如果提示下面的错误:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
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_64An 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-develAn error occurred while installing mysql2 (0.4.20), and Bundler cannot continue.
Make sure that `gem install mysql2 -v ‘0.4.20’` succeeds before bundling.
#解决办法
# yum install mysql-devel.x86_64
# gem install mysql2 -v '0.4.20An 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-develAn 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_64An error occurred while installing sqlite3 (1.5.14), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v ‘1.5.14’` succeeds before bundling.
# 解决办法
# yum install sqlite-devel.x86_64
# gem install sqlite3 -v '1.5.14'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的安装

10.5 安装gitlab-shell

在实际安装gitlab-shell过程中会存在克隆gitlab-shell仓库网络慢问题,所以我们必须修改gitlab-shell仓库源为国内源:https://git.oschina.net/qiai365/gitlab-shell.git 操作如下:

# cd /home/git/gitlab
# sudo -u git -H vim  /home/git/gitlab/lib/tasks/gitlab/shell.rake
替换掉gitlab-shell官方仓库源即可

10.7 执行安装gitlab-shell脚本

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

编辑gitlab-shell配置文件,并根据实际情况修改

# sudo -u git -H vim /home/git/gitlab-shell/config.yml内容如下:
---
user: git
gitlab_url: http://code.mo9.com/   (修改为gitlab对外访问的域名FQDN)
http_settings:self_signed_cert: false (如果需要开启https访问,修改为ture,并使用ca_file指定)
auth_file: "/data/apps/git/.ssh/authorized_keys"
redis:bin: "/usr/bin/redis-cli"   (该值修改为redis命令路径)namespace: resque:gitlabsocket: "/var/run/redis/redis.sock" (该值修改为redis的sock路径)
log_level: INFO
audit_usernames: false

10.6 安装gitlab-workhorse

# cd /home/git/gitlab
# sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production

10.7 安装gitlab-pages

# cd /home/git
# sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-pages.git
# cd gitlab-pages
# sudo -u git -H git checkout v$(</home/git/gitlab/GITLAB_PAGES_VERSION)
# sudo -u git -H make

10.8 安装gitaly

# cd /home/git/gitlab
# sudo -u git -H bundle exec rake "gitlab:gitaly:install[/home/git/gitaly,/home/git/git-data]" RAILS_ENV=production
# sudo chmod 0700 /home/git/gitlab/tmp/sockets/private
# sudo chown git /home/git/gitlab/tmp/sockets/private

10.9 初始化数据库

# cd /home/git/gitlab
# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=gitlab.com GITLAB_ROOT_EMAIL=admin@mo9.com当看到以下内容,表示已经安装完成
Administrator account created:
login:    root
password: your_passwd
== Seed from /home/git/gitlab/db/fixtures/production/010_settings.rb

10.10 打包前端静态资源文件
编译gettext文件

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

生成gitlab前端静态assets文件

# cd /home/git/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

10.11 初始化gilab服务脚本以及日志切割脚本

# cd /home/git/gitlab
# sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
# sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
# sudo service gitlab start

11. 配置nginx代理

# cd /home/git/gitlab
# sudo cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf
# nginx -t
# service nginx start

如果需要开启https访问,需要更改三个地方的配置文件:

/home/git/gitlab/config/gitlab.yml  开启https,并修改访问域名以及访问端口;
/home/git/gitlab-shell//config.yml  开启https,并修改访问域名添加ssl证书;
/etc/nginx/conf.d/gitlab.conf        开启https,并修改访问域名添加ssl证书;

12. 检查gitlab应用信息以及状态

检查gitlab组件信息

# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production当出现如下信息表示安装无误:
System information
System:     CentOS 7.4.1708
Current User:   git
Using RVM:  no
Ruby Version:   2.4.4p296
Gem Version:    2.6.14.1
Bundler Version:1.16.6
Rake Version:   12.3.1
Redis Version:  3.2.12
Git Version:    2.18.0
Sidekiq Version:5.2.1
Go Version: go1.10.3 linux/amd64GitLab information
Version:    11.4.0-pre
Revision:   0d84dd22872
Directory:  /data/apps/git/gitlab
DB Adapter: mysql2
URL:        http://code.mo9.com
HTTP Clone URL: http://code.mo9.com/some-group/some-project.git
SSH Clone URL:  git@code.mo9.com:some-group/some-project.git
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:GitLab Shell
Version:    8.3.3
Repository storage paths:
- default:  /home/git/repositories
Hooks:      /home/git/gitlab-shell/hooks
Git:        /usr/local/git/bin/git

检查gitlab应用状态

# sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production当出现如下信息时,说明整个gitlab部署成功:
Checking GitLab Shell ...GitLab Shell version >= 8.3.3 ? ... OK (8.3.3)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
Administrator / test ... ok
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Redis available via internal API: OKAccess to /data/apps/git/.ssh/authorized_keys: OK
gitlab-shell self-check successfulChecking GitLab Shell ... FinishedChecking Sidekiq ...Running? ... yes
Number of Sidekiq processes ... 1Checking Sidekiq ... FinishedReply by email is disabled in config/gitlab.yml
Checking LDAP ...LDAP is disabled in config/gitlab.ymlChecking LDAP ... FinishedChecking GitLab ...Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet)
Init script exists? ... yes
Init script up-to-date? ... yes
Projects have namespace: ...
Administrator / test ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.5 ? ... yes (2.4.4)
Git version >= 2.9.5 ? ... yes (2.18.0)
Git user has default SSH configuration? ... yes
Active users: ... 2Checking GitLab ... Finished

至此整个gitlab系统搭建完成,当然如果需要基于https访问可以参考官方文档:

转载于:https://blog.51cto.com/blief/2296409

gitlab版本控制系统源码部署相关推荐

  1. MySQL 源码 需要 什么基础_MySQL 基础之 源码 部署

    源码部署 1. 需要先卸载一些软件 centos7 中需要先卸载 mariadb-libs 软件包 # rpm -e --nodeps mariadb-libs 2. 安装依赖包 yum -y ins ...

  2. Openfire4源码部署到eclipse中并编译

    Openfire4源码部署到eclipse中并编译 概述 Openfire是众所周知的基于xmpp协议的IM开源服务,所有操作,配置,监控,调试等以B/S方式进行展示,非常的方便管理员进行管理.它的强 ...

  3. mondrain配置mysql_mondrian 4.7 源码部署(示例代码)

    mondrian是一个开源的数据分析工程, 网上有关mondrian3.X的源码部署比较多, 有关4.X的部署较少. 目前官方推荐使用的时mondrian3.7的修订版, 可以再github上下载到最 ...

  4. 使用源码部署CITA(Ubuntu18.0.4 | VMware)

    使用源码部署CITA(Ubuntu18.0.4 | VMware) 先挑选一个地方准备用做下载位置(自主选择) 提前进入选择的目录 例: $ cd /home/liubai $ mkdir cita ...

  5. Delphi:程序自己删除自己,适用于任何windows版本(含源码)

    Delphi:程序自己删除自己,适用于任何windows版本(含源码) function Suicide: Boolean; var   sei: TSHELLEXECUTEINFO;   szMod ...

  6. SHOP++源码部署说明:

    2019独角兽企业重金招聘Python工程师标准>>> SHOP++源码部署说明: 1. 安装MyEclipse.Tomcat.MySQL/Oracle/SQL Server 2. ...

  7. QT各版本的源码下载地址

    QT各版本的源码下载地址:http://download.qt.io/archive/qt/ 有时候需要不同的版本,这里记录一下.

  8. drcom linux最新版,Ubuntu高于8.04版本的源码安装drcom

    Ubuntu高于8.04版本的源码安装drcom注意点,这里借用别个的,我的早安装好了,为了方便记忆,把别人的copy过来,方便找用源码安装drcom时候,make报错,9.10和10.04都此问题. ...

  9. 域名授权验证系统v1.0.6开源版本网站源码

    介绍: 域名授权验证系统v1.0.6公益开源版本网站源码几乎所有的程序都能整合使用,包括您的app和计算机程序,支持多程序授权.在线支付.权限分配.内测用户.在线升级.商业广告.工单系统.盗版管理.自 ...

最新文章

  1. [LeetCode]*105.Construct Binary Tree from Preorder and Inorder Traversal
  2. Delphi 调用外部程序并等待其运行结束
  3. 顺序栈实现表达式求值(C语言实现)【栈】
  4. Java开发中使用模拟接口moco响应中文时乱码
  5. 手把手教你插入数学公式,妈妈再也不用担心我写不了论文了
  6. DELL服务器iDRAC相关设置
  7. python中的魔法属性和方法
  8. CSS之Multi-columns的跨列
  9. Spring Mvc Controller返回值、参数绑定、参数校验 (高级二)
  10. 马行走路线的测试用例设计
  11. lay-verify=required 没生效_眼睛一闭一睁,20万没了!|侧翻|交通事故|半挂车|追尾...
  12. java 表头固定_常用的固定表头的几种做法
  13. 诊断某段时间数据库性能抖动问题思路
  14. 提升update执行效率
  15. 数据安全技术专利态势分析
  16. c++实现右下角弹窗
  17. 从零开始学习CANoe(四)—— 设计panel
  18. Maven第7篇:聚合、继承、单继承问题详解
  19. 拜年神器php,Biu神器安卓版
  20. python阴阳师自动狗粮脚本_用Python实现阴阳师自动抽卡

热门文章

  1. centos7上使用chrony自动同步时间
  2. ebs 选择excel输出 后缀 html,Oracle EBS XML报表中数字的处理(Excel输出)
  3. cobol和java区别,COBOL语法和文法(1)
  4. Eclipse .class文件中文乱码
  5. 获取进程的信息 linux,如何获取进程信息
  6. java e.getmessage() null,浅谈Java异常的Exception e中的egetMessage()和toString()方法的区别...
  7. 计算机教学教育评价和实践手册,教育教学实践评价手册(听课记录表三)
  8. 集群环境下_Docker环境下秒建Redis集群,连SpringBoot也整上了!
  9. 句子分类_Bert做新闻标题文本分类
  10. python h5s文件 压缩_如何用python解压zip压缩文件