centos6安裝部署git服務器(gitlab6.4)


環境准備

python版本2.6
git版本 1.8.4.1
ruby版本ruby-2.0.0-p353
gitlab-shell版本 v1.8.0
gitlab版本6.4.3

因centos6系列的python版本是2.6的,已經支持,所以不必升級python版本。
在centos5下面需要升級python版本>2.5

安裝epel的yum源

1 yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

安裝必要的軟件包

1 yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

 

安裝git

因為git需要1.8版本以上,所以需要重新編譯安裝
移除當前git

1 yum remove git

下載1.8.4.1的git並安裝

1 curl --progress https://git-core.googlecode.com/files/git-1.8.4.1.tar.gz | tar xz
2 cd git-1.8.4.1/
3 make prefix=/usr/local all
4 make prefix=/usr/local install
5 ln -fs /usr/local/bin/git* /usr/bin/

安裝ruby環境

01 yum -y remove ruby
02 mkdir /tmp/ruby && cd /tmp/ruby
03 curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
04 cd ruby-2.0.0-p353/
05 ./configure --disable-install-rdoc
06 make && make install
07 gem source -r https://rubygems.org/
08 gem source -a http://ruby.taobao.org/
09 gem install bundler --no-ri --no-rdoc
10 ln -/usr/local/bin/ruby /usr/bin/ruby
11 ln -/usr/local/bin/gem /usr/bin/gem
12 ln -/usr/local/bin/bundle /usr/bin/bundle

添加git帳號並允許sudo

1 useradd --comment 'GitLab' git
2 echo "git ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers

安裝git-shell

01 cd /home/git
02 sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.8.0
03 cd gitlab-shell/
04 sudo -u git -H cp config.yml.example config.yml
05 vim config.yml
06 修改gitlab_url為gitlab的域名
07 gitlab_url: "http://localhost/"
08 修改為
09 gitlab_url: "http://git.linuxyan.com/"
10 #安裝git-shell
11 sudo -u git -H ./bin/install

安裝mysql以及建立gitlab數據庫

01 yum install mysql mysql-devel mysql-server -y
02 /etc/init.d/mysqld start
03 chkconfig mysqld on
04 登錄mysql創建gitab的帳號和數據庫
05 mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
06 mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
07 mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
08  
09 測試是否可以用git帳號登錄數據庫
10  
11 sudo -u git -H mysql -u gitlab --D gitlabhq_production

安裝redis

1 yum -y install redis
2 /etc/init.d/redis start
3 chkconfig redis on

安裝gitlab

01 cd /home/git
02 sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -6-4-stable gitlab
03 cd /home/git/gitlab
04 sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
05  
06 vim config/gitlab.yml
07 修改host為剛才git-shell里面設置的域名
08 ## GitLab settings
09 gitlab:
10 ## Web server settings
11   host: git.linuxyan.com
12   port: 80
13   https: false
14  
15 修改git的path
16 git:
17   bin_path: /usr/local/bin/git
18  
19 給文件夾添加相應的權限
20 chown -R git log/
21 chown -R git tmp/
22 chmod -R u+rwX  log/
23 chmod -R u+rwX  tmp/
24 創建必要的文件夾,以及復制配置文件
25 sudo -u git -H mkdir /home/git/gitlab-satellites
26 sudo -u git -H mkdir tmp/pids/
27 sudo -u git -H mkdir tmp/sockets/
28 sudo chmod -R u+rwX  tmp/pids/
29 sudo chmod -R u+rwX  tmp/sockets/
30 sudo -u git -H mkdir public/uploads
31 sudo chmod -R u+rwX  public/uploads
32 sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
33 sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

設置gitlab的全局帳號

1 sudo -u git -H git config --global user.name "GitLab"
2 sudo -u git -H git config --global user.email "gitlab@localhost"
3 sudo -u git -H git config --global core.autocrlf input

設置數據庫鏈接地址和權限

01 sudo -u git cp config/database.yml.mysql config/database.yml
02 sudo -u git -H vim  config/database.yml
03 修改鏈接數據庫信息
04 production:
05   adapter: mysql2
06   encoding: utf8
07   reconnect: false
08   database: gitlabhq_production
09   pool: 10
10   username: gitlab
11   password: "gitlab"
12   # host: localhost
13   # socket: /tmp/mysql.sock

安裝需要ruby的gems

1 cd /home/git/gitlab
2 vim  Gemfile
3 修改source "https://rubygems.org/"
4 為source "http://ruby.taobao.org/"
5 vim Gemfile.lock
6 修改remote: https://rubygems.org/
7 為remote: http://ruby.taobao.org/
8 安裝
9 sudo -u git -H bundle install --deployment --without development test postgres aws

如果遇到如下錯誤:

1 Could not find modernizr-2.6.2 in any of the sources

則修改:

01 vim Gemfile
02 修改:gem "modernizr",        "2.6.2"
03 為gem "modernizr-rails",  "2.7.1"
04  
05 vim Gemfile.lock
06 修改:modernizr (2.6.2)
07 為:modernizr-rails (2.7.1)
08  
09 修改:modernizr (= 2.6.2)
10 為:modernizr-rails (= 2.7.1)

然后再執行安裝

1 sudo -u git -H bundle install --deployment --without development test postgres aws

過程如下圖:
centos6安裝部署git服務器(gitlab6.4) - 第1張  | ㄨ銷聲匿跡、Linux
centos6安裝部署git服務器(gitlab6.4) - 第2張  | ㄨ銷聲匿跡、Linux

初始化數據庫

1 sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

初始化數據庫之后,會告訴你默認的管理員用戶和密碼:
centos6安裝部署git服務器(gitlab6.4) - 第3張  | ㄨ銷聲匿跡、Linux
centos6安裝部署git服務器(gitlab6.4) - 第4張  | ㄨ銷聲匿跡、Linux

安裝啟動文件以及日志切割文件

1 cp lib/support/init.d/gitlab /etc/init.d/gitlab
2 cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
3 cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

檢測當前環境

1 sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

如下:
centos6安裝部署git服務器(gitlab6.4) - 第5張  | ㄨ銷聲匿跡、Linux

安裝nginx

1 yum -y install nginx

修改配置文件:
vim /etc/nginx/nginx.conf

01 user              root git;
02 worker_processes  2;
03 pid        /var/run/nginx.pid;
04  
05 events {
06     worker_connections  1024;
07 }
08  
09 http {
10     include       /etc/nginx/mime.types;
11     default_type  application/octet-stream;
12  
13     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
14                       '$status $body_bytes_sent "$http_referer" '
15                       '"$http_user_agent" "$http_x_forwarded_for"';
16 # GITLAB
17 # Maintainer: @randx
18 # App Version: 5.0
19  
20 upstream gitlab {
21   server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
22 }
23  
24 server {
25   listen *:80 default_server;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
26   server_name YOUR_SERVER_FQDN;     # e.g., server_name source.example.com;
27   server_tokens off;     # don't show the version number, a security best practice
28   root /home/git/gitlab/public;
29  
30   # Set value of client_max_body_size to at least the value of git.max_size in gitlab.yml
31   client_max_body_size 5m;
32  
33   # individual nginx logs for this gitlab vhost
34   access_log  /var/log/nginx/gitlab_access.log;
35   error_log   /var/log/nginx/gitlab_error.log;
36  
37   location / {
38     # serve static files from defined root folder;.
39     # @gitlab is a named location for the upstream fallback, see below
40     try_files $uri $uri/index.html $uri.html @gitlab;
41   }
42  
43   # if a file, which is not found in the root folder is requested,
44   # then the proxy pass the request to the upsteam (gitlab unicorn)
45   location @gitlab {
46     proxy_read_timeout 300https://github.com/gitlabhq/gitlabhq/issues/694
47     proxy_connect_timeout 300https://github.com/gitlabhq/gitlabhq/issues/694
48     proxy_redirect     off;
49  
50     proxy_set_header   X-Forwarded-Proto $scheme;
51     proxy_set_header   Host              $http_host;
52     proxy_set_header   X-Real-IP         $remote_addr;
53     proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
54  
55     proxy_pass http://gitlab;
56   }
57 }
58  
59 }

更改權限,啟動nginx

1 nginx -t
2 chown -R git.git /var/lib/nginx/
3 /etc/init.d/nginx start

拉取gitlab靜態資源文件

1 sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

啟動gitlab

1 /etc/init.d/gitlab start

檢測各個組件是否正常工作

1 sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

檢測沒有錯誤就表示已經安裝好了gitlab,如圖:

這個時候就可以用瀏覽器打開http://git.linuxyan.com
初始管理員帳號和密碼為:
admin@local.host
5iveL!fe
登錄之后如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM