官网环境要求

参见:https://github.com/gitlabhq/gitlabhq

GitLab is a Ruby on Rails application that runs on the following software:

  • Ubuntu/Debian/CentOS/RHEL
  • Ruby (MRI) 2.1
  • Git 1.7.10+
  • Redis 2.0+
  • MySQL or PostgreSQL

For more information please see the architecture documentation.

##########################################

关闭防火墙,关闭SELinux

一、安装采用环境

  • CentOS 6.5 x86_64
  • Ruby 2.1.7
  • Git 2.4.8
  • Redis 2.4.10
  • MySQL 5.6.26
  • GitLab 7.12.2
  • GitLab Shell 2.6.2
  • Nginx   1.8.0
  • Gem   2.2.5
  • Bundler 1.10.6

二、系统添加EPEL、PUIAS源

1.添加EPEL源

  1. wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL- https://www.fedoraproject.org/static/0608B895.txt --no-check-certificate
  1. rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  1. rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  1. rpm -qa gpg*
  1. #显示gpg-pubkey-41a40948-4ce19266

2.添加PUIAS源

  1. 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 --no-check-certificate
  2. 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
  3. rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
  4. rpm -qa gpg*
  5. #显示gpg-pubkey-41a40948-4ce19266

3.查看源列表,验证

输入如下命令:

  1. yum repolist

结果如下:

  1. repo id repo name status
  2. PUIAS_6_computational PUIAS computational Base - x86_64 ,
  3. base CentOS- - Base ,
  4. epel Extra Packages for Enterprise Linux - x86_64 ,
  5. extras CentOS- - Extras
  6. updates CentOS- - Updates
  7. repolist: ,

If you can't see them listed, use the folowing command (from yum-utils package) to enable them:

  1. yum-config-manager --enable epel --enable PUIAS_6_computational

三、Install the required tools for GitLab

1.利用yum安装依赖包

  1. yum -y update
  2. yum -y groupinstall 'Development Tools'
  3. 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 libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs python-devel logwatch logrotate perl-Time-HiRes libcom_err-devel.x86_64

2.源码安装Git

参见:http://www.cnblogs.com/jim-hwg/p/4748008.html

3.源码安装Ruby

参见:http://www.cnblogs.com/jim-hwg/p/4746977.html

4.源码安装MySQL

参见:http://www.cnblogs.com/jim-hwg/p/4747165.html

四、创建用户

1.创建一个Gitlab系统用户git:

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

为了方便添加git用户拥有root权限 [sudoers文件默认没有写权限需要强制保存:wq!]
使用root用户执行下述命令

  1. vim /etc/sudoers

最后添加

  1. git ALL=(ALL) NOPASSWORD: ALL

2.创建一个Gitlab数据库用户并赋权

登陆MySQL,输入密码

  1. mysql -u root -p

创建Gitlab数据库用户git:

  1. CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
    #替换$password设定自己的密码
  2. CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  3. GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
  4. quit

五、配置服务

1.配置MySQL

配置MySQL max_allowed_packet的大小,避免POST太大的内容导致出现500错误,例如GitLab 发出MergeRequest的时候返回500错误。

  1. vim /etc/my.cnf
  2. #在mysqld中添加max_allowed_packet,调整值,加大为一个合适的数字即可。
  3. [mysqld]
  4. max_allowed_packet=512M

重启mysql服务

  1. service mysqld restart

2.配置redis

Make sure redis is started on boot:

  1. chkconfig redis on

Configure redis to use sockets:

  1. cp /etc/redis.conf /etc/redis.conf.orig

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

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

Enable Redis socket for default CentOS path:

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

Activate the changes to redis.conf:

  1. service redis restart

Add git to the redis group:

  1. usermod -aG redis git

 六、安装Gitlab

切换到git用户

  1. su - git

设置不验证SSL

  1. vim /home/git/.bash_profile
  2. export GIT_SSL_NO_VERIFY=

1.克隆Gitlab

  1. git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-12-stable gitlab

或克隆中文版Gitlab

  1. git clone https://gitlab.com/larryli/gitlab.git -b 7-12-zh gitlab

2.配置Gitlab

  1. cd gitlab
  2. cp config/gitlab.yml.example config/gitlab.yml

配置config/gitlab.yml,配置Gitlab服务的端口,IP

  1. vim config/gitlab.yml
  2. host: 10.149.153.81
  3. port:
  4. email_from: gitlab@example.com
  5. email_enabled: false
  6. default_theme:
  1. mkdir /home/git/gitlab-satellites
  2. chmod /home/git/gitlab-satellites
  3. cp config/unicorn.rb.example config/unicorn.rb
  1. 配置config/unicorn.rb,配置Ruby提供的服务端口,IP
  1. # Find number of cores
  2. #优化系统参数/etc/security/limits.conf
  3. # Enable cluster mode if you expect to have a high load instance
  4. # Ex. change amount of workers to for 2GB RAM server
  5. # Set the number of workers to at least the number of cores
  6. vim config/unicorn.rb
  7. worker_processes # Set the number of workers to at least the number of core
    listen "127.0.0.1:8081", :tcp_nopush => true        #注意端口,避免冲突
  1. cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
    git config --global user.name "GitLab"
    git config --global user.email "gitlab@example.com"
    git config --global core.autocrlf input
    cp config/resque.yml.example config/resque.yml
  1. 配置config/resque.yml
    #如果不使用默认的端口,则需要配置

3. Configure GitLab DB settings

  1. cp config/database.yml.mysql config/database.yml
  2. # MySQL and remote PostgreSQL only:
  3. # Update username/password in config/database.yml.
  4. # You only need to adapt the production settings (first part).
  5. # If you followed the database guide then please do as follows:
  6. # Change 'secure password' with the value you have given to $password
  7. # You can keep the double quotes around the password
  8. vim config/database.yml
  9. 修改为正确的用户名和密码
  10. 分别修改git用户和root用户
    chmod o-rwx config/database.yml

4.Install Gems

Note: As of bundler 1.5.2, you can invoke bundle install -jN
(where N the number of your processor cores) and enjoy the parallel gems installation with measurable
difference in completion time (~60% faster). Check the number of your cores with nproc.
For more information check this post.
First make sure you have bundler >= 1.5.2 (run bundle -v) as it addresses some issues
that were fixed in 1.5.2.

  1. cd /home/git/gitlab
  2. # Or for MySQL (note, the option says "without ... postgres")
  3. 修改为淘宝的ruby
  4. vim Gemfile
  5. 修改为
  6. source 'https://ruby.taobao.org/'
  7.  
  8. bundle install --deployment --without development test postgres aws
  9. 这一步的时间会等很久

5.Install GitLab shell

GitLab Shell is an SSH access and repository management software developed specially for GitLab.

  1. cd /home/git/gitlab
    bundle exec rake gitlab:shell:install[v2.6.2] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

报错:ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

处理:切换到root用户

  1. yum -y install nodejs

配置/home/git/gitlab/Gemfile

  1. vim /home/git/gitlab/Gemfile
  2. #末尾添加
  3. gem 'execjs'
  4. gem 'therubyracer'
  1. cd /home/git/gitlab
    bundle install --no-deployment

验证:

  1. bundle show execjs
  2. bundle show therubyracer

切回git用户,再次执行

  1. cd /home/git/gitlab
    bundle exec rake gitlab:shell:install[v2.6.2] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

配置/home/git/gitlab-shell/config.yml,配置gitlab-shell要调用的API接口

  1. # By default, the gitlab-shell config is generated from your main GitLab config.
  2. # You can review (and modify) the gitlab-shell config as follows:
  3. vim /home/git/gitlab-shell/config.yml
  4.  
  5. # Ensure the correct SELinux contexts are set
  6. # Read http://wiki.centos.org/HowTos/Network/SecuringSSH
  7. restorecon -Rv /home/git/.ssh

6.Initialize Database and Activate Advanced Features

  1. cd /home/git/gitlab/
  2. bundle exec rake gitlab:setup RAILS_ENV=production

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

Note: You can set the Administrator password by supplying it in environmental variable GITLAB_ROOT_PASSWORD, eg.:

如果要修改gitlab管理员的密码,则执行这一句,否则执行上一句

  1. bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword

7.Install Init Script

Download the init script (will be /etc/init.d/gitlab):

切换到root用户

  1. wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn --no-check-certificate
  2. chmod +x /etc/init.d/gitlab
  3. chkconfig --add gitlab
  4. chkconfig gitlab on

8.Set up logrotate

切换到root用户

  1. cd /home/git/gitlab
  2. cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

9.Check Application Status

Check if GitLab and its environment are configured correctly:

切回git用户

  1. cd /home/git/gitlab
  2. bundle exec rake gitlab:env:info RAILS_ENV=production
  3. #Compile assets
  4. bundle exec rake assets:precompile RAILS_ENV=production

切回root,执行

  1. service gitlab start

七、Configure the web server

Use either Nginx or Apache, not both. Official installation guide recommends nginx.

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:

  1. rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    yum update
  2. yum -y install nginx
  3. chkconfig nginx on
  4.  
  5. 使用SSl
  6. wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl --no-check-certificate
  7.  
  8. 不使用SSL
  9. wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab --no-check-certificate

最后加上--no-check-certificate不检查证书,这里不使用SSL

Edit /etc/nginx/conf.d/gitlab.conf and replace git.example.com with your FQDN. Make sure to read the comments in order to properly set up SSL.

  1. vim /etc/nginx/conf.d/gitlab.conf
  2. 去掉listen后面的default_server,修改为正确的端口号
  3. 去掉 listen [::]:
  4. 修改server_name 为本机的IP地址
  5.  
  6. 修改client_max_body_size 256m;
  7. 否则当推送较多数据到 gitlab 上时,会由于数据过大,而出现错误
  8. fatal: The remote end hung up unexpectedly fatal: The remote end hung up unexpectedly error: RPC failed; result=, HTTP code =

Add nginx user to git group:

  1. usermod -a -G git nginx

Finally start nginx with:

  1. service nginx start

Test Configuration

Validate your gitlab or gitlab-ssl Nginx config file with the following command:

  1. nginx -t

八、Double-check Application Status

To make sure you didn't miss anything run a more thorough check with:

  1. su - git
  2. cd /home/git/gitlab
  3. bundle exec rake gitlab:check RAILS_ENV=production

九、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:

  1. root
  2. 5iveL!fe

#####################以上即完成了Gitlab的搭建################################

十、后期维护

1.Upgrade GitLab Shell

GitLab Shell might be outdated, running the commands below ensures you're using a compatible version:

  1. su - git
  2. cd /home/git/gitlab-shell
  3. git fetch
  4. git checkout v`cat /home/git/gitlab/GITLAB_SHELL_VERSION`

2.Upgrade GitLab

One line upgrade command
You've read through the entire guide and probably already did all the steps one by one.

Here is a one line command with step 1 to 5 for the next time you upgrade:

切换到git用户

  1. cd /home/git/gitlab; \
  2. sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production; \
  3. sudo service gitlab stop; \
  4. if [ -f bin/upgrade.rb ]; then sudo -u git -H ruby bin/upgrade.rb -y; else sudo -u git -H ruby script/upgrade.rb -y; fi; \
  5. cd /home/git/gitlab-shell; \
  6. sudo -u git -H git fetch; \
  7. sudo -u git -H git checkout v`cat /home/git/gitlab/GITLAB_SHELL_VERSION`; \
  8. cd /home/git/gitlab; \
  9. exit; \
  10. sudo service gitlab start; \
  11. sudo service nginx restart; sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

3.Upgrade /etc/init.d/gitlab

  1. wget https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
  2. mv gitlab-unicorn gitlab
  3. cp -f gitlab /etc/init.d/gitlab
  4. rm gitlab

复制完后,要删除/etc/init.d/gitlab.swap文件

4.Gitlab源代码更新

  1. cd /home/git/gitlab/
  2.  
  3. git fetch origin
  4. git merge origin/--zh
  5.  
  6. #重启 gitlab
  7. service gitlab restart

十一、Gitlab 备份

官网的备份说明

https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/backup_restore.md

查看备份设置

  1. vim /home/git/gitlab/config/gitlab.yml

检查Backup Settings设置项
默认情况下,备份文件是存放在/home/git/gitlab/tmp/backups/

执行备份

  1. sudo service gitlab stop # 先停止Gitlab,可以不暂停
  2. cd /home/git/gitlab/
  3. sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

执行完成后,会在/home/git/gitlab/tmp/backups/目录下创建一个备份俄文件,以时间戳_gitlab_backup命名如 1417040627_gitlab_backup.tar

重新启动

  1. sudo service gitlab start
  2. sudo service nginx restart

还原

需要给其他用户配置读写执行的权限

  1. chmod o+wrx /home/git/.ssh/authorized_keys.lock

否则会出现如下错误,是由于没有权限
/home/git/gitlab-shell/lib/gitlab_keys.rb:101:in
`initialize': Permission denied @ rb_sysopen -
/home/git/.ssh/authorized_keys.lock (Errno::EACCES)

需要使用 git 用户来执行,否则会没有权限操作 git 目录下的文件,timestamp_of_backup为时间戳如 1417040627

  1. sudo service gitlab stop
  2. cd /home/git/gitlab/
  3. sudo -u git -H bundle exec rake gitlab:backup:restore BACKUP=timestamp_of_backup RAILS_ENV=production
  4. sudo service gitlab start
  5. sudo service nginx restart
  6. sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

设置自动备份

  1. sudo service gitlab stop;
  2. cd /home/git/gitlab;
  3. sudo -u git -H editor config/gitlab.yml; # Enable keep_time in the backup section to automatically delete old backups

keep_time参数默认是604800(单位是秒),因此会保留最近7天内的备份

  1. sudo -u git crontab -e # Edit the crontab for the git user

将如下内容添加到文件末尾

  1. # Create a full backup of the GitLab repositories and SQL database every day at 2am
  2. * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=

每天凌晨2点自动备份

The CRON=1 environment setting tells the backup script to suppress all progress output if there are no errors. This is recommended to reduce cron spam.

重新启动

  1. sudo service gitlab start;
  2. sudo service nginx restart;
  3. sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production;

参考链接:http://www.cnblogs.com/restran/p/4411133.html

     http://blog.csdn.net/ypjyangpeijun/article/details/20468043

CentOS 6.5 安装Gitlab 7.12.2的更多相关文章

  1. centos 7.4 安装gitlab

    centos 7.4 安装gitlab #curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/scrip ...

  2. centos 6.5安装GitLab全过程和问题记录

    GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用. 官方只提供了Debian/Ubuntu系统下的安 ...

  3. centos 7 一键安装gitlab

    # cat /etc/redhat-release CentOS release 6.5 (Final) # strings /lib64/libc.so.6 |grep GLIBC_ 首先升级 如果 ...

  4. Centos 6 搭建安装 Gitlab

    官方安装教程 gitlab / gitlab-ce 官网下载:https://www.gitlab.cc/downloads 官网安装说明:https://doc.gitlab.cc/ce/insta ...

  5. 在CentOS 7上安装GitLab

    网上安装gitlab的方法有一堆,由于墙的原因,没有一个能安装成功,最后终于在中文版官网上面找到了RPM包可以下载,进行一键安装: 中文官网地址:http://www.gitlab.cc/ 下载地址为 ...

  6. 在 CentOS 7 上安装 GitLab

    1. 安装和配置必要的依赖库 sudo yum install -y curl policycoreutils-python openssh-server # the commands below w ...

  7. CentOS 7.2 安装 Docker 1.12.3 版

    本文出自http://www.cnblogs.com/scoter2008 1.强大的官方文档 https://docs.docker.com/engine/installation/linux/ce ...

  8. centos 6.5 安装 cx_Oracle 5.12 步骤 ,使用oracle instantclient12.1

    新建sh文件 内容如下: 以su用户执行这个文件 #!/bin/bash # INSTALL ORACLE INSTANT CLIENT # ############################# ...

  9. (转)CentOS下一键安装GitLab

    [环境准备]OS: CentOS 6.3 x86_64 [安装要求]如果有条件,提供一台全新的Server(仅仅只安装了一些系统的软件包),可以直接使用一键安装脚本(gitlab-install-el ...

随机推荐

  1. easyui missingMessage

    <input class="easyui-textbox" type="text" name="username" style=&qu ...

  2. shell用法 (cat << EOF)

    下面的语句会创建不存在的secure.config,如果存在直接追加,然后把多行内容: [database]        password = gerrit 写入文件secure.config ca ...

  3. Apache 配置:是否显示文件列表

    Apache 配置:是否显示文件列表 进入虚拟主机配置文件 显示文件列表的话 options Indexes FollowSymLinks 不显示文件列表的话 options FollowSymLin ...

  4. Vue 过滤器filters

    1.示例代码 采用vue单文件组件,使用moment插件格式化日期 <template> <div> <h1>{{date | dateFormat}}</h ...

  5. INSTALL_FAILED_OLDER_SDK

    Uploading file local path: /Users/Rubert/Android/workspace/MyApplication/app/build/outputs/apk/app-d ...

  6. android:numColumns="auto_fit" 失效问题

    GridView 设置此属性无效:android:numColumns="auto_fit" ,请确认已经设置过 android:columnWidth="*dp&quo ...

  7. python--web项目

    zope:一个容器项目Plone:一个基于zope的工作流和内容管理项目trac:一个项目管理(任务指派.bug追踪项目,可以和subversion集成)moinmoin:一个强力的weiki系统

  8. Rabbitmq消息队列(二) Hello World! 模拟简单发送接收

    1.简介 RabbitMQ是消息代理:它接受和转发消息.你可以把它当作一个邮局:当你把你要邮寄的邮件放在信箱里时,你可以肯定Postman先生最终会把邮件送到你的收件人那里.在这个比喻中,Rabbit ...

  9. 当你输入一个网址/点击一个链接,发生了什么?(以www.baidu.com为例)

    >>>点击网址后,应用层的DNS协议会将网址解析为IP地址: DNS查找过程: 浏览器会检查缓存中有没有这个域名对应的解析过的IP地址,如果缓存中有,这个解析过程就将结束. 如果用户 ...

  10. hdu 4821 字符串hash+map判重 String (长春市赛区I题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4821 昨晚卡了非常久,開始TLE,然后优化了之后,由于几个地方变量写混.一直狂WA.搞得我昨晚都失眠了,,. 这 ...