centos6.7 install gitlab7.13.5_zh


声明:本章内容由本章发布,其中感谢豆豆师兄,和郭师兄的鼎力相助才安装完成,如有看不懂的地方,那就看不懂吧!
请在下方留言,或者加群讨论!

##  环境
```
OS          : CentOS 6.6 X86_64
GitLab Version  : 7.13.5_zh
Web Server  : Nginx
DataBase    : MySQL
Author          : Yxn
Data        : 2015-08-21 12:03:07



#/etc/init.d/iptables stop
# setenforce 0

## 简介
翻译于官方文档 [Install/CentOS]("https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/install/centos") 此篇没有关于SSL、防火墙、SElinux、PgSQL(PostgreSQL)、Apache的安装配置,官方文档中包含SElinx、防火墙、SSL、PgSQL、Apache的配置。
由于GitLab为英文版本,所以选择了[GitLab 中文版本]("https://gitlab.com/larryli/gitlab")。可能由于某些地区连接过慢,这里提供了一个国内的镜像版本库[GitLab 中文版本]("http://git.oschina.net/Yxnt/gitlab")
以上翻译为个人翻译,如有问题请邮箱联系或者留言。谢谢!


### bug提交
如果你发现有BUG请提交于 [Issue]("https://gitlab.com/gitlab-org/gitlab-ce/issues")

### 配置大纲
- - - 
此篇安装文档的步骤如下:
1. 安装基本的操作系统(CentOS 6.6 x86_64)以及一些依赖的程序包
2. Ruby
3. System Users
4. DataBase(MySQL)
5. Redis
6. GitLab
7. Web Server (Nginx)
---------

**提示:** 安装方式随自己心情,不想用 `YUM` 就用编译,开心就好。
## 1. 安装基本的操作系统

在这里操作系统的安装并不做任何演示操作,因为既然能看到这篇文章那么至少你是一个运维人员了,如果你连系统都不会装那就到这就可以结束了。

**注意:** 保证开机自动连接网路,毕竟是放在公司使用的谁也不希望重启一下就连接不到了。
1,#### 添加EPEL源
从[fedoraproject][keys]下载GPG key并且安装在系统中


    wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt
    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6


查看Key是否安装成功:


    rpm -qa gpg*
    gpg-pubkey-0608b895-4bd22942

   
在系统中安装epel源


   

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

   
**提示:** 也可以自己配置repo文件,看自己心情。


#### 添加PUIAS源
这段说明不会翻译 - -。

下载 PUIAS repo文件

 

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 

   
接下来下载并安装gpg key



 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

   
查看源是否添加成功



yum repolist
repo id                      repo name                                              status
PUIAS_6_computational        PUIAS computational Base 6 - x86_64                     2,678
epel                         Extra Packages for Enterprise Linux 6 - x86_64         11,772

如果没有看到如上内容,则使用下面的命令来启用它们(需要安装yum-utils包)
yum-config-manager --enable epel --enable PUIAS_6_computational

 2,#### 为GitLab安装一些必须的包

 yum update  # 其实这一步可以不需要的

yum -y groupinstall 'Development Tools'
yum -y install 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 logwatch logrotate perl-Time-HiRes git cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs

 
  3,**Note:** 配置默认的编辑器

 # 安装vim并且设置为默认的编辑器

yum -y install vim-enhanced
update-alternatives --set editor /usr/bin/vim.basic
ln -s /usr/bin/vim /usr/bin/editor
# reStructuredText markup语法支持,需要安装依赖包:
yum install -y python-docutils

4,#### 可选:使用源码安装git
确认Git的版本>=1.7.10,如果低于此版本需要进行安装

    git --version
移除git

yum -y remove git

安装git编译所需要的包
yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel

下载并解压它
mkdir /tmp/git && cd /tmp/git
curl --progress https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.gz | tar xz
cd git-2.1.3/
./configure
make
make prefix=/usr/local install


确认你的git路径,需要在后面编辑`config/gitlab.yml`时使用,

5,## 2.Ruby
如果系统中Ruby的版本是2.0以前的那么请移除,GitLab只支持Ruby 2.0+版本


yum remove ruby


### 下载并编译


mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz
cd ruby-2.1.2
./configure --disable-install-rdoc
make
make prefix=/usr/local install


### 安装Bundler Gem
由于`http://rubygems.org`已被墙,这里替换源为`http://ruby.taobao.org`
   
    # 添加淘宝源并且移除官方源

sudo git 
gem sources -a http://ruby.taobao.org
gem sources -r https://rubygems.org/

    
    # 安装Bundler
gem install bundler -v'1.5.2' --no-doc


检查ruby版本


ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

   
6,## 3. System Users
为GitLab创建用户
 
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git


编辑sudoers文件,将ruby的程序路径添加到PATH中,使git用户作为root来使用gem命令


 visudo
# 搜索如下行
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
# 追加/usr/local/bin
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

保存并退出


7,## 4. DataBase
这里使用的是MariaDB,我用的是yum安装的自己配置的yum源(由于当时做实验的时候已经凌晨1点了为了赶快做完去睡觉)还是那句:用什么包随心情,开心就好
### 配置yum源

vim /etc/yum.repos.d/mariadb.repo
# 增加如下内容:
[mariadb]
name=mariadb
baseurl=http://mirrors.aliyun.com/mariadb/mariadb-5.5.45/yum/centos6-amd64/
gpgcheck=0
### 安装MariaDB
yum install MariaDB MariaDB-devel
    也可以使用编译安装,可以看本博客中Mariadb
#### 连接数据库并创建用户
mysql -u root 
创建数据库
CREATE USER 'git1'@'10.215.50.3' IDENTIFIED BY 'gitpassword'; 
确定你的innode引擎支持长索引
SET storage_engine=INNODB;
创建数据库
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

尝试使用新用户连接gitlab数据库
sudo -u git -H mysql -u git -pgitpassword -D gitlabhq_production

8,## 5. Redis

开机启动redis
chkconfig redis on
配置Redis使用sockets
cp /etc/redis.conf /etc/redis.conf.orig

关闭Redis 监听于TCP
sed 's/^port .*/port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf

在CentOS上启用Redis socket
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf
echo -e 'unixsocketperm 0770' | sudo tee -a /etc/redis.conf

设置socket目录属主(组)为redis
chown redis:redis /var/run/redis
chmod 755 /var/run/redis

将git用户添加至redis组
usermod -aG redis git

启动redis服务
service redis start

 
9, 6. GitLab


克隆源码
cd /home/git/
sudo -u git -H git clone http://git.oschina.net/Yxnt/gitlab
配置gitlab
进入Gitlab安装目录
cd /home/git/gitlab
复制gitlab的模板文-件

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
编辑gitlab配置文件

sudo -u git -H editor config/gitlab.yml

访问地址
host:10.1.13.5
port:80
https: false # 关闭https



 ====================我是分割线=================================
创建satellites目录

sudo -u git -H mkdir /home/git/gitlab-satellites
chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
确认gitlab可以写入tmp/pids、tmp/sockets以及public/uploads/目录

chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
chmod -R u+rwX public/uploads
复制Unicorn配置文件

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
复制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 "example@example.com"
sudo -u git -H git config --global core.autocrlf input
配置Redis连接设置

sudo -u git -H cp config/resque.yml.example config/resque.yml
sudo -u git -H editor config/resque.yml

更改配置

development: unix:/var/run/redis/redis.sock

配置Gitlab 数据库设置

MySQL Only

sudo -u git cp config/database.yml.mysql config/database.yml
确定database.yml文件只为git用户可读
sudo -u git -H chmod o-rwx config/database.yml

   
10,### 安装Gems


 

cd /home/git/gitlab
gem sources --add https://rubygems.org --remove https://ruby.taobao.org
bundle config mirror.https://rubygems.org https://ruby.taobao.org
gem install rails -V 
sudo -u git -H bundle install --deployment --without development test postgres aws
sudo -u git -H bundle install --deployment --without development test postgres aws

安装gitlab-shell
sudo -u git -H bundle exec rake gitlab:shell:install[v2.6.3] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

配置gitlab-shell
sudo -u git -H editor /home/git/gitlab-shell/config.yml
gitlab_url: http://10.1.13.5

   
11,### 初始化数据并且激活高级特性

这里会提示输入yes/no,输入yes即可
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

设置管理员密码,其中newpassword替换成你的密码
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=gitpassword

安装启动脚本
wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab

 

开机启动 Gitlab
chkconfig gitlab on
设置日志滚动
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检查应用程序状态
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
[git@gitlab gitlab]$ bundle exec rake gitlab:env:info RAILS_ENV=production

System information
System: CentOS 6.7
Current User: git
Using RVM: no
Ruby Version: 2.1.2p95
Gem Version: 2.2.2
Bundler Version:1.5.2
Rake Version: 10.4.2
Sidekiq Version:3.3.0

GitLab information
Version: 7.13.5
Revision: 851306a
Directory: /home/git/gitlab
DB Adapter: mysql2
URL: http://10.215.50.3
HTTP Clone URL: http://10.215.50.3/some-project.git
SSH Clone URL: git@10.215.50.3:some-project.git
Using LDAP: no
Using Omniauth: no

GitLab Shell
Version: 2.6.3
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git
[git@gitlab gitlab]$

 

启动gitlab
service gitlab start


7.Web Server

### 安装nginx

我这里是编译的,细节不在批示,可在本站搜索nginx编译安装


./configure --prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--user=nginx \
--group=nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_mp4_module \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi


  

如果你用的是install,则可以使用一下范式

配置nginx
wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab
wget -O /etc/nginx/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab
修改代理服务器
[root@gitlab nginx]# sed -ie "38s/.*/server\ localhost:8080;/g" /etc/nginx/gitlab.conf
[root@gitlab nginx]# sed -ie "s/YOUR_SERVER_FQDN/`hostname`/g" /etc/nginx/gitlab.conf
[root@gitlab nginx]# sed -ie "52d" /etc/nginx/gitlab.conf
[root@gitlab nginx]# usermod -a -G git nginx
[root@gitlab nginx]# chmod g+rx /home/git/
[root@gitlab nginx]# service nginx start

upstream gitlab {
server localhost:8080;
}

修改server_name
server_name www.baidu.com;

如果你是编译的请复制一下内容到nginx.conf,请自行修改配置文件中的编译文件路径


user              root git;
worker_processes  2;
pid       /var/run/nginx/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#GITLAB

Maintainer: @randx

App Version: 5.0

upstream gitlab {
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com;
server_tokens off; # don't show the version number, a security best practice
root /home/git/gitlab/public;

Set value of client_max_body_size to at least the value of git.max_size in gitlab.yml

client_max_body_size 5m;

individual nginx logs for this gitlab vhost

access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;

location / {

serve static files from defined root folder;.

@gitlab is a named location for the upstream fallback, see below

try_files $uri $uri/index.html $uri.html @gitlab;
}

if a file, which is not found in the root folder is requested,

then the proxy pass the request to the upsteam (gitlab unicorn)

location @gitlab {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;

proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://gitlab;
}
}
}




# 添加nginx到git组
usermod -a -G git nginx
chmod g+rx /home/git/

启动nginx

service nginx start


 

##附录(发送邮件配置),未经测试,请斟酌使用
### 复制gitlab自带的模板
cd /home/git/gitlab
sudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb
### 替换邮箱
sudo -u git -H vim config/initializers/smtp_settings.rb

if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.163.com", ## 发信地址
port: 25, ## 发信端口
user_name: "wpgitlab", ## 用户名
password: "123456", ## 密码
domain: "163.com", ## 域
authentication: :plain,
enable_starttls_auto: true
}
end

修改gitlab.yml

cd /home/git/gitlab
sudo -u git -H vim config/gitlab.yml

email_from: wpgit@163.com 这里的邮箱配置和上面的一样



 
## 结束语
yum安装可能是有点影响智商了,如果你被领导用刀夹着脖子的话那就还是用吧。

邮件内容未测试,请自行测试

由于文章的代码高亮问题,可下载此文章链接:gitlab文档下载

2 分享

您可以选择一种方式赞助本站

支付宝扫码赞助

支付宝扫码赞助

日期: 2015-11-22分类: 持续集成

标签: GitLab

发表评论