CentOS 6.5 安装Gitlab 7.12.2

官网环境要求

参见: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源

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

2.添加PUIAS源

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
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
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
rpm -qa gpg*
#显示gpg-pubkey-41a40948-4ce19266

3.查看源列表,验证

输入如下命令:

yum repolist

结果如下:

repo id                                                               repo name                                                                                                   status
PUIAS_6_computational                                                 PUIAS computational Base 6 - x86_64                                                                          2,678
base                                                                  CentOS-6 - Base                                                                                              6,575
epel                                                                  Extra Packages for Enterprise Linux 6 - x86_64                                                              11,775
extras                                                                CentOS-6 - Extras                                                                                               3510
updates                                                               CentOS-6 - Updates                                                                                             254
repolist: 21,327

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

yum-config-manager --enable epel --enable PUIAS_6_computational

三、Install the required tools for GitLab

1.利用yum安装依赖包

yum -y update
yum -y groupinstall ‘Development Tools‘
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:

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

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

vim /etc/sudoers

最后添加

git     ALL=(ALL)       NOPASSWORD: ALL

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

登陆MySQL,输入密码

mysql -u root -p

创建Gitlab数据库用户git:

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

五、配置服务

1.配置MySQL

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

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

重启mysql服务

service mysqld restart

2.配置redis

Make sure redis is started on boot:

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 0775‘ | sudo tee -a /etc/redis.conf

Activate the changes to redis.conf:

service redis restart

Add git to the redis group:

usermod -aG redis git

 六、安装Gitlab

切换到git用户

su - git

设置不验证SSL

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

1.克隆Gitlab

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

或克隆中文版Gitlab

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

2.配置Gitlab

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

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

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

3. Configure GitLab DB settings

cp config/database.yml.mysql config/database.yml
# MySQL and remote PostgreSQL only:
# Update username/password in config/database.yml.
# You only need to adapt the production settings (first part).
# If you followed the database guide then please do as follows:
# Change ‘secure password‘ with the value you have given to $password
# You can keep the double quotes around the password
vim config/database.yml
修改为正确的用户名和密码
分别修改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.

cd /home/git/gitlab
# Or for MySQL (note, the option says "without ... postgres")
修改为淘宝的ruby源
vim Gemfile
修改为
source ‘https://ruby.taobao.org/‘

bundle install --deployment --without development test postgres aws
这一步的时间会等很久

5.Install GitLab shell

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

cd /home/git/gitlabbundle 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用户

yum -y install nodejs

配置/home/git/gitlab/Gemfile

vim /home/git/gitlab/Gemfile
#末尾添加
gem ‘execjs‘
gem ‘therubyracer‘
cd /home/git/gitlabbundle install --no-deployment

验证:

bundle show execjs
bundle show therubyracer

切回git用户,再次执行

cd /home/git/gitlabbundle 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接口

# By default, the gitlab-shell config is generated from your main GitLab config.
# You can review (and modify) the gitlab-shell config as follows:
vim /home/git/gitlab-shell/config.yml

# Ensure the correct SELinux contexts are set
# Read http://wiki.centos.org/HowTos/Network/SecuringSSH
restorecon -Rv /home/git/.ssh

6.Initialize Database and Activate Advanced Features

cd /home/git/gitlab/
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管理员的密码,则执行这一句,否则执行上一句

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用户

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

8.Set up logrotate

切换到root用户

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

9.Check Application Status

Check if GitLab and its environment are configured correctly:

切回git用户

cd /home/git/gitlab
bundle exec rake gitlab:env:info RAILS_ENV=production
#Compile assets
bundle exec rake assets:precompile RAILS_ENV=production

切回root,执行

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:

rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpmyum update
yum -y install nginx
chkconfig nginx on

使用SSl
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

不使用SSL
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.

vim /etc/nginx/conf.d/gitlab.conf
去掉listen后面的default_server,修改为正确的端口号
去掉 listen [::]:
修改server_name 为本机的IP地址

修改client_max_body_size 256m;
否则当推送较多数据到 gitlab 上时,会由于数据过大,而出现错误
fatal: The remote end hung up unexpectedly fatal: The remote end hung up unexpectedly error: RPC failed; result=22, HTTP code = 413

Add nginx user to git group:

usermod -a -G git nginx

Finally start nginx with:

service nginx start

Test Configuration

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

nginx -t

八、Double-check Application Status

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

su - git
cd /home/git/gitlab
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:

root
5iveL!fe

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

十、后期维护

1.Upgrade GitLab Shell

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

su - git
cd /home/git/gitlab-shell
git fetch
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用户

cd /home/git/gitlab; sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production; sudo service gitlab stop; 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; cd /home/git/gitlab-shell; sudo -u git -H git fetch; sudo -u git -H git checkout v`cat /home/git/gitlab/GITLAB_SHELL_VERSION`; cd /home/git/gitlab; exit; sudo service gitlab start; sudo service nginx restart; sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

3.Upgrade /etc/init.d/gitlab

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

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

4.Gitlab源代码更新

cd /home/git/gitlab/

git fetch origin
git merge origin/7-5-zh

#重启 gitlab
service gitlab restart

十一、Gitlab 备份

官网的备份说明

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

查看备份设置

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

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

执行备份

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

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

重新启动

sudo service gitlab start
sudo service nginx restart

还原

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

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

sudo service gitlab stop
cd /home/git/gitlab/
sudo -u git -H bundle exec rake gitlab:backup:restore BACKUP=timestamp_of_backup RAILS_ENV=production
sudo service gitlab start
sudo service nginx restart
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

设置自动备份

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

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

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

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

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

每天凌晨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.

重新启动

sudo service gitlab start;
sudo service nginx restart;
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

时间: 2024-08-30 08:04:57

CentOS 6.5 安装Gitlab 7.12.2的相关文章

CentOS源码安装GitLab汉化版

示例环境: 软件 版本 CentOS 6.5 x86_64 Git 2.6.2 Ruby 2.2.3 Node.js 4.2.1 Redis 3.0.5 MariaDB 10.0.21 GitLab 8.0.5汉化版 GitLab Shell 2.6.6 Nginx 1.8.0 Go 1.5.1 Gitlab-git-http-server 0.2.14 一.修改Yum源为阿里云提高下载速度 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.

CentOS源码安装GitLab汉化版第2版

软件版本: CentOS 7.2 Git 2.12.0 Ruby 2.3.3 Node.js 6.10.1 Redis 3.2.8 MariaDB 10.1.20 GitLab 8.8.5汉化版 GitLab Shell 2.7.2 Nginx 1.10.3 Go 1.8 GitLab-Workhorse 0.7.1 一.安装依赖 yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel op

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

GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用. 官方只提供了Debian/Ubuntu系统下的安装说明文档,如果需要在centos下安装,可以参考这篇:https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos,笔者依照这篇文章的说明,成功的在centos系统上安装了gitlab,分享一下自己的安装过程和碰到的问题

centos 6.5安装GitLab安装

1.安装操作系统 a.安装wget(系统版本是6.5) #yum -y install wget b.增加EPEL安装源 EPEL,即Extra Packages for Enterprise Linux,这个软件仓库里有很多非常常用的软件,而且是专门针对RHEL设计的,对RHEL标准yum源是一个很好的补充,完全免费使用,由 Fedora项目维护,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的 yum源. 下载并安装GP

【GitLab】CentOS 6.5 安装GitLab 搭建自己的Github

前言: 使用Github,免费的公开仓库可以用来开源一些代码,可是写一个项目的时候,并不想开源,在Github创建私有仓库还需要交保护费,所以我就想到了要不要自己搭一个Git服务器. 一开始,我直接yum安装了git,通过简单的配置可以通过[email protected]:/git/*.git,这样SSH的方式push和pull代码.可是,我还想通过http的方式,于是又通过安装apache实现了通过http的方式进行操作.现在又遇到了问题,就是怎么在线浏览我的代码,然后又是一通搜索,找到了g

CentOS 7.2 安装 Docker 1.12.3 版

1.强大的官方文档 https://docs.docker.com/engine/installation/linux/centos/ 2.按步骤来,先更新yum源,这里用163的源 yum install -y wget cd /etc/yum.repos.d wget http://mirrors.163.com/.help/CentOS7-Base-163.repo /usr/bin/yum clean all /usr/bin/yum makecache 其他系统自带的源可以保留,也可以

centos 6.4x64 安装gitlab

gitlab是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用. 一.环境 系统:CentOS 6.4x64最小化安装 IP:192.168.3.71 二.安装yum源 安装epel源 [[email protected] ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm Retrievin

Centos系列编译安装php7+nginx1.12及搭建自己的wordpress博客

脚本方式安装,快速简单.复制到编写软件放大字体,这里字体太小. 安装完nginx+php看个人需要数据库搭建位置. 数据库安装完成创建数据库及授权(5.7方式) 5.7数据库初始密码查看 systemctl mysqld start [[email protected] ~]# grep "password" /var/log/mysqld.log 2017-06-04T01:29:39.687228Z 1 [Note] A temporary password is generate

CentOS 7.0 安装 mysql-5.7.12 (一)

1 下载 官网下载 选择社区免费版 平台 linux genitic 版本 64位,我的虚拟机是64位 2 安装 上传压缩包,并解压至合适位置, 我的目录 basedir :  /home/mysql/mysql-5.7.12 ,即放在用户mysql 目录下 tar -zxvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz mv mysql-5.7.12-linux-glibc2.5-x86_64 /home/mysql mv mysql-5.7.12-li