设为首页 收藏本站
查看: 691|回复: 0

[经验分享] 部署自己的gitlab服务器

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-4-6 09:00:22 | 显示全部楼层 |阅读模式
本文系统:centos 6.5 x64
ip: 172.16.162.130
1
2
3
4
5
GitLab         8.0.5
GitLab         Shell2.6.6
GitLab         APIv3
Ruby           2.2.3p173
Rails          4.1.12



1、安装依赖包

1
[iyunv@vm1 ~]# yum install gcc* libicu* -y



2、安装git程序,因为系统自带版本太低

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@vm1 ~]# mkdir /opt/src /opt/soft
[iyunv@vm1 src]# pwd
/opt/src
[iyunv@vm1 src]# ls
git-2.6.2.tar.xz
[iyunv@vm1 src]# tar xf git-2.6.2.tar.xz
[iyunv@vm1 src]# cd git-2.6.2
[iyunv@vm1 git-2.6.2]# ./configure --prefix=/opt/soft/git --with-curl --with-expat
[iyunv@vm1 git-2.6.2]#  make && make install
[iyunv@vm1 git-2.6.2]# echo 'export PATH=/opt/soft/git/bin:$PATH' >> /etc/profile
[iyunv@vm1 git-2.6.2]# source /etc/profile
[iyunv@vm1 git-2.6.2]# git --version
git version 2.6.2
[iyunv@vm1 git-2.6.2]#



2、安装ruby

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@vm1 src]# tar xf ruby-2.2.3.tar.gz
[iyunv@vm1 src]# cd ruby-2.2.3
[iyunv@vm1 ruby-2.2.3]# ./configure --prefix=/opt/soft/ruby --disable-install-rdoc
[iyunv@vm1 ruby-2.2.3]# make && make install
[iyunv@vm1 ruby-2.2.3]# echo 'export PATH=/opt/soft/ruby/bin:$PATH' >> /etc/profile
[iyunv@vm1 ruby-2.2.3]# source /etc/profile  
[iyunv@vm1 ruby-2.2.3]# gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
https://ruby.taobao.org/ added to sources
https://rubygems.org/ removed from sources
[iyunv@vm1 ruby-2.2.3]# gem install bundler --no-ri --no-rdoc
Fetching: bundler-1.11.2.gem (100%)
Successfully installed bundler-1.11.2
1 gem installed
[iyunv@vm1 ruby-2.2.3]#



3、安装nodejs
1
2
3
[iyunv@vm1 src]# tar zxf node-v4.2.2-linux-x64.tar.gz
[iyunv@vm1 src]# mv node-v4.2.2-linux-x64 /opt/soft/nodejs
[iyunv@vm1 src]# echo 'export PATH=/opt/soft/nodejs/bin:$PATH' >> /etc/profile



4、安装go

1
2
3
4
5
6
7
8
[iyunv@vm1 src]# tar xf go1.5.1.linux-amd64.tar
[iyunv@vm1 src]# mv go /opt/soft/
[iyunv@vm1 src]# echo 'export GOROOT=/opt/soft/go' >> /etc/profile
[iyunv@vm1 src]# echo 'export GOARCH=amd64' >> /etc/profile
[iyunv@vm1 src]# echo 'export GOOS=linux' >> /etc/profile
[iyunv@vm1 src]# echo 'export GOBIN=$GOROOT/bin' >> /etc/profile
[iyunv@vm1 src]# echo 'export GOPATH=/opt/soft/go/code/go' >> /etc/profile
[iyunv@vm1 src]# echo 'export PATH=$GOBIN:$PATH' >> /etc/profile



5、安装redis

1
2
3
[iyunv@vm1 ~]# yum install redis -y
[iyunv@vm1 ~]# /etc/init.d/redis start
启动 :[确定]



6、安装mysql

1
2
3
4
5
[iyunv@vm1 ~]# yum install mysql-server -y
[iyunv@vm1 ~]# /etc/init.d/mysqld start
[iyunv@node1 ~]# mysql
mysql> create database gitlab;
mysql> grant all privileges on gitlab.* to gitlab@'localhost' identified by 'gitlab';



7、安装gitlab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[iyunv@node1 ~]# useradd -d /opt/git git
[iyunv@node1 ~]# chmod 755 /opt/git
[iyunv@node1 ~]# su - git
[git@node1 ~]$ pwd
/opt/git
[git@node1 ~]$ git clone https://gitlab.com/larryli/gitlab.git -b 8-0-zh gitlab
正克隆到 'gitlab'...
remote: Counting objects: 214761, done.
remote: Compressing objects: 100% (45405/45405), done.
remote: Total 214761 (delta 166493), reused 214623 (delta 166408)
接收对象中: 100% (214761/214761), 111.36 MiB | 74.00 KiB/s, 完成.
处理 delta 中: 100% (166493/166493), 完成.
检查连接... 完成。
[git@node1 ~]$ cd gitlab/
[git@node1 gitlab]$ cp config/gitlab.yml.example config/gitlab.yml
[git@node1 gitlab]$ cp config/secrets.yml.example config/secrets.yml
[git@node1 gitlab]$ cp config/unicorn.rb.example config/unicorn.rb
[git@node1 gitlab]$ cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
[git@node1 gitlab]$ cp config/resque.yml.example config/resque.yml
[git@node1 gitlab]$ cp config/database.yml.mysql config/database.yml
[git@node1 gitlab]$ mkdir /opt/git/gitlab-satellites/



8、修改配置文件,因为默认是在 git 账号下的 home 目录,我们这里是在 /opt/git
  • 修改 gitlab.yml 配置,将行host: localhost 修改为本机IP地址或者域名
  • 修改 gitlab.yml ,配置git路径行 bin_path: /usr/bin/git 为 bin_path: /opt/soft/git/bin/git

1
2
3
4
5
6
[git@node1 gitlab]$ grep home config/gitlab.yml
    path: /home/git/gitlab-satellites/
    path: /home/git/gitlab-shell/
    repos_path: /home/git/repositories/
    hooks_path: /home/git/gitlab-shell/hooks/
    secret_file: /home/git/gitlab/.gitlab_shell_secret



分别修改为 /opt 下,并且创建相应目录
1
[git@node1 gitlab]$ mkdir -p  /opt/git/gitlab-satellites /opt/git/gitlab-shell /opt/git/repositories /opt/git/gitlab-shell/hooks/



1
2
3
4
5
6
7
[git@node1 gitlab]$ grep home config/unicorn.rb
working_directory "/home/git/gitlab" # available in 0.94.0+
listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 1024
pid "/home/git/gitlab/tmp/pids/unicorn.pid"
stderr_path "/home/git/gitlab/log/unicorn.stderr.log"
stdout_path "/home/git/gitlab/log/unicorn.stdout.log"
[git@node1 gitlab]$



9、修改Redis相关配置 config/resque.yml 文件 production: unix:/var/run/redis/redis.sock 为 production: redis://172.16.162.130:6379

     数据库配置:
1
2
3
4
5
6
7
8
9
10
11
production:
  adapter: mysql2
  encoding: utf8
  collation: utf8_general_ci
  reconnect: false
  database: gitlab
  pool: 10
  username: gitlab
  password: "gitlab"
  # host: localhost
  # socket: /tmp/mysql.sock



10、修改 Gemfile 首行内容 source "https://rubygems.org"  修改为 source "https://ruby.taobao.org"。
安装mysql包
1
[git@node1 gitlab]$ bundle install --deployment --without development test postgres aws kerberos



当出现下面问题时:
1
2
3
4
5
6
7
Installing timers 4.0.4
An error occurred while installing charlock_holmes (0.6.9.4), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v '0.6.9.4'` succeeds before bundling.
[git@node1 gitlab]$ gem install charlock_holmes -v '0.6.9.4'
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/M ... -0.6.9.4.gemspec.rz)
[git@node1 gitlab]$



先安装下面的 rpm 包,然后再执行上面的命令

1
2
3
4
5
[iyunv@node1 src]# rpm -vhi libicu-devel-4.2.1-9.1.el6_2.x86_64.rpm
warning: libicu-devel-4.2.1-9.1.el6_2.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
Preparing...                ########################################### [100%]
   1:libicu-devel           ########################################### [100%]
[iyunv@node1 src]#



当出现下面的问题时:

1
2
3
4
Installing nokogiri 1.6.6.2 with native extensions
An error occurred while installing rugged (0.22.2), and Bundler cannot continue.
Make sure that `gem install rugged -v '0.22.2'` succeeds before bundling.
[git@node1 gitlab]$



先安装下面的 rpm 包,然后再执行上面的命令
1
[iyunv@node1 src]# yum install cmake -y



11、安装 gitlab-shell
1
[git@node1 gitlab]$ bundle exec rake gitlab:shell:install[v2.6.6] REDIS_URL=redis://172.16.162.130:6379 RAILS_ENV=production



当出现如下报错:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[git@node1 gitlab]$   bundle exec rake gitlab:shell:install[v2.6.6] REDIS_URL=redis://172.16.162.130:6379 RAILS_ENV=production
WARNING: This version of GitLab depends on gitlab-shell 2.6.5, but you're running Unknown. Please update gitlab-shell.
Missing `db_key_base` for 'production' environment. The secrets will be generated and stored in `config/secrets.yml`
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /opt/git/.ssh/environment
/opt/git/gitlab/lib/tasks/gitlab/shell.rake:73:in `initialize'
/opt/git/gitlab/lib/tasks/gitlab/shell.rake:73:in `open'
/opt/git/gitlab/lib/tasks/gitlab/shell.rake:73:in `block (3 levels) in <top (required)>'
Tasks: TOP => gitlab:shell:install
(See full trace by running task with --trace)
[git@node1 gitlab]$



安装如下处理:
1
[git@node1 ~]$ mkdir /opt/git/.ssh



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[git@node1 gitlab]$ bundle exec rake gitlab:shell:install[v2.6.6] REDIS_URL=redis://172.16.162.130:6379 RAILS_ENV=production
WARNING: This version of GitLab depends on gitlab-shell 2.6.5, but you're running Unknown. Please update gitlab-shell.
正克隆到 '/opt/git/gitlab-shell'...
remote: Counting objects: 2558, done.
remote: Compressing objects: 100% (895/895), done.
remote: Total 2558 (delta 1607), reused 2501 (delta 1571)
接收对象中: 100% (2558/2558), 360.62 KiB | 241.00 KiB/s, 完成.
处理 delta 中: 100% (1607/1607), 完成.
检查连接... 完成。
HEAD 现在位于 cdaa9ae Merge branch 'bump_2.6.6' into 'master'
mkdir -p /opt/git/repositories/: OK
mkdir -p /opt/git/.ssh: OK
chmod 700 /opt/git/.ssh: OK
touch /opt/git/.ssh/authorized_keys: OK
chmod 600 /opt/git/.ssh/authorized_keys: OK
chmod ug+rwX,o-rwx /opt/git/repositories/: OK
[git@node1 gitlab]$



12、安装gitlab-git-http-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[git@node1 ~]$ git clone https://gitlab.com/gitlab-org/gitlab-git-http-server.git -b 0.2.14
正克隆到 'gitlab-git-http-server'...
remote: Counting objects: 418, done.
remote: Compressing objects: 100% (169/169), done.
remote: Total 418 (delta 214), reused 417 (delta 213)
接收对象中: 100% (418/418), 63.16 KiB | 0 bytes/s, 完成.
处理 delta 中: 100% (214/214), 完成.
检查连接... 完成。
Note: checking out '7c63f08f7051348e56b903fc0bbefcfed398fc1c'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
  git checkout -b <new-branch-name>
[git@node1 ~]$



1
2
3
4
5
6
7
8
[git@node1 ~]$ cd gitlab-git-http-server/
[git@node1 gitlab-git-http-server]$ ls
githandler.go  LICENSE  main.go  main_test.go  Makefile  README.md  support  test
[git@node1 gitlab-git-http-server]$ make
go build -ldflags "-X main.Version 0.2.14-20160405.151430" -o gitlab-git-http-server
# _/opt/git/gitlab-git-http-server
link: warning: option -X main.Version 0.2.14-20160405.151430 may not work in future releases; use -X main.Version=0.2.14-20160405.151430
[git@node1 gitlab-git-http-server]$



13、初始化数据库并激活高级功能  (lansgg123为 web管理员root的密码)
1
2
[git@node1 gitlab-git-http-server]$ cd ~/gitlab
[git@node1 gitlab]$ bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=lansgg123



14、复制启动脚本等内容:
1
2
3
4
[iyunv@node1 git]# cp gitlab/lib/support/init.d/gitlab /etc/init.d/   
[iyunv@node1 git]# cp gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/
[iyunv@node1 git]# su - git
[git@node1 ~]$ cd gitlab



检查下应用信息状态:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[git@node1 gitlab]$ bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System:         RedHatEnterpriseServer 6.5
Current User:   git
Using RVM:      no
Ruby Version:   2.2.3p173
Gem Version:    2.4.5.1
Bundler Version:1.11.2
Rake Version:   10.4.2
Sidekiq Version:3.3.0
GitLab information
Version:        8.0.5
Revision:       a6659af
Directory:      /opt/git/gitlab
DB Adapter:     mysql2
URL:            http://172.16.162.130
HTTP Clone URL: http://172.16.162.130/some-group/some-project.git
SSH Clone URL:  git@172.16.162.130:some-group/some-project.git
Using LDAP:     no
Using Omniauth: no
GitLab Shell
Version:        2.6.6
Repositories:   /opt/git/repositories/
Hooks:          /opt/git/gitlab-shell/hooks/
Git:            /opt/soft/git/bin/git
[git@node1 gitlab]$



编译静态文件
[git@node1 gitlab]$ bundle exec rake assets:precompile RAILS_ENV=production
15、安装nginx

nginx 安装 --> 传送门
16、编辑配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
[iyunv@node1 conf]# pwd
/opt/soft/nginx/conf
[iyunv@node1 conf]# cat nginx.conf
user  nginx nginx;
worker_processes  auto;
  
error_log  logs/error.log error;
  
pid        logs/nginx.pid;
worker_rlimit_nofile    65536;
  
events
{
    use epoll;
    accept_mutex off;
    worker_connections  65536;
}
  
http
{
    include       mime.types;
    default_type  text/html;
  
    charset UTF-8;
    server_names_hash_bucket_size   128;
    client_header_buffer_size       4k;
    large_client_header_buffers  4 32k;
    client_max_body_size            20m;
  
    open_file_cache max=65536  inactive=60s;
    open_file_cache_valid      80s;
    open_file_cache_min_uses   1;
  
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
  
    access_log  logs/access.log  main;
  
    sendfile    on;
    server_tokens off;
  
    keepalive_timeout  60;
  
    gzip  on;
    gzip_min_length 1k;
    gzip_buffers  4   64k;
    gzip_http_version   1.1;
    gzip_comp_level 2;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  
    upstream gitlab
    {
        server unix:/opt/git/gitlab/tmp/sockets/gitlab.socket fail_timeout=0;
    }
  
    upstream gitlab-git-http-server
    {
        server unix:/opt/git/gitlab/tmp/sockets/gitlab-git-http-server.socket fail_timeout=0;
    }
  
    server {
        listen      80;
        server_name _;
        root        /opt/git/gitlab/public;
  
        location /
        {
            try_files $uri $uri/index.html $uri.html @gitlab;
        }
  
        location /uploads/
        {
            proxy_read_timeout      300;
            proxy_connect_timeout   300;
            proxy_redirect          off;
            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_set_header    X-Forwarded-Proto   $scheme;
            proxy_set_header    X-Frame-Options     SAMEORIGIN;
            proxy_pass http://gitlab;
        }
  
        location @gitlab
        {
            proxy_read_timeout      300;
            proxy_connect_timeout   300;
            proxy_redirect          off;
            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_set_header    X-Forwarded-Proto   $scheme;
            proxy_set_header    X-Frame-Options     SAMEORIGIN;
            proxy_pass http://gitlab;
        }
  
        location ~ [-\/\w\.]+\.git\/
        {
            proxy_read_timeout      300;
            proxy_connect_timeout   300;
            proxy_redirect          off;
            proxy_buffering off;
            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_set_header    X-Forwarded-Proto   $scheme;
            proxy_pass http://gitlab-git-http-server;
        }
  
        location ~ ^/(assets)/
        {
            root /opt/git/gitlab/public;
            gzip_static on;
            expires max;
            add_header Cache-Control public;
        }
  
        error_page 502 /502.html;
    }
}



17、启动服务,测试:

1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@node1 sbin]# ./nginx
[iyunv@node1 sbin]# pwd
/opt/soft/nginx/sbin
[iyunv@node1 sbin]#
[iyunv@node1 sbin]# /etc/init.d/gitlab start
Starting GitLab Unicorn
Starting GitLab Sidekiq
Starting gitlab-git-http-server
The GitLab Unicorn web server with pid 10956 is running.
The GitLab Sidekiq job dispatcher with pid 11004 is running.
The gitlab-git-http-server with pid 10987 is running.
GitLab and all its components are up and running.
[iyunv@node1 sbin]#



启动gitlab前,要修改gitlab的启动程序。 (下面两行)
1
2
app_user="git"
app_root="/opt/$app_user/gitlab"



访问地址:http://172.16.162.130/
wKioL1cDinGDR_C-AAMrE5fWsp8825.jpg
18、smtp邮件设置,比如用户注册,验证、找回密码、提交等邮件发送设置。

1
2
[git@node1 gitlab]$ vim config/environments/production.rb
  config.action_mailer.delivery_method = :smtp



1
2
3
4
5
6
7
8
9
10
11
12
13
[git@node1 gitlab]$ cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb
[git@node1 gitlab]$ vim config/initializers/smtp_settings.rb

if Gitlab::Application.config.action_mailer.delivery_method == :smtp
  ActionMailer::Base.smtp_settings = {
    address: "smtp.domain.com",
    port: 587,
    user_name: "mail_username",
    password: "mail_password",
    domain: "domain.com",
    authentication: 'plain',
    enable_starttls_auto: true
  }end



Tip: 如果没用smtp没有开加密连接的话 enable_starttls_auto 的值应该配置为 false
这里需要注意一个问题, 如果你的smtp服务器做了权限限制,只能以登陆账户的邮件帐号发邮件的话,还需要修改一处地方
编辑 config/gitlab.yml 找到下面两个字段将内容改成你的邮件帐户地址:
1
2
3
    email_from: xxx@xx.com
    email_display_name: GitLab
    email_reply_to: noreply@example.com



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-200249-1-1.html 上篇帖子: Linux环境下,git push到github时出现的一个问题 下篇帖子: CentOS 6 编译安装Git 2.8.1 服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表