CentOS6.5安裝gitlab

GitLab,是一個利用 Ruby on Rails 開發的開源應用程序,實現一個自託管的Git項目倉庫,可通過Web界面進行訪問公開的或者私人項目。

它擁有與Github類似的功能,能夠瀏覽源代碼,管理缺陷和註釋。可以管理團隊對倉庫的訪問,它非常易於瀏覽提交過的版本並提供一個文件歷史庫。團隊成員可以利用內置的簡單聊天程序(Wall)進行交流。它還提供一個代碼片段收集功能可以輕鬆實現代碼複用,便於日後有需要的時候進行查找。

開源項目地址:https://github.com/gitlabhq/gitlabhq

# Distribution      : CentOS 6.5 Minimal
# GitLab version    : 7.4.5
# GitLab-shell      : 2.0.1
# Ruby version      : ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
# Gem version       : 2.2.2
# Redis-server      : Redis server version 2.4.10 (00000000:0)
# Web Server        : Nginx/1.0.15
# Database          : MySQL/5.5.40

一,安裝源和依賴包

cd /usr/local/src
#增epel源,如果你是i686系統,請把x86_64修改下。
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
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

#確認是否安裝成功
rpm -qa gpg*
gpg-pubkey-0608b895-4bd22942

#增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
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
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * PUIAS_6_computational: www.puias.princeton.edu
 * epel: ftp.sjtu.edu.cn
倉庫標識                                                                  倉庫名稱                                                                                           狀態
PUIAS_6_computational                                                     PUIAS computational Base 6 - x86_64                                                                 2,638
base                                                                      CentOS-6 - Base - 163.com                                                                           6,518
*epel                                                                     Extra Packages for Enterprise Linux 6 - x86_64                                                     11,148
extras                                                                    CentOS-6 - Extras - 163.com                                                                            36
updates                                                                   CentOS-6 - Updates - 163.com                                                                          727
repolist: 21,067

如果此列表中沒有epel和PUIAS_6_computational,請執行以下命令

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


二,安裝依賴包

yum -y 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


安裝郵件服務

postfix或者sendmail,官網上安裝是postfix,本人默認就裝來sendmail,所以此步驟省略


三,安裝git

默認centos的git版本是1.7.10,所以要先刪除,然後再下載源碼安裝

yum remove git -y

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

完成後驗證

which git
/usr/local/bin/git

git --version
git version 2.1.3


四,安裝ruby

ruby版本需要2.0+,所以先卸載系統已存在的

yum remove ruby
#如果是源碼安裝的
cd (your-ruby-source-path) && make uninstall

mkdir /tmp/ruby && cd /tmp/ruby

curl --progress ang.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 install bundler --no-doc

完成後驗證

which ruby
/usr/local/bin/ruby

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

五,創建系統用戶

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

增加/usr/local/bin

visudo
#修改以下內容
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

六,安裝mysql

官網給出兩個選擇,mysql、postgreSQL,我使用的mysql

centos默認會安裝5.1版本的mysql,所以要源碼安裝,此步驟掠過。。。

#mysql的版本至少5.5.14或更新
mysql --version
mysql  Ver 14.14 Distrib 5.5.40, for Linux (x86_64) using readline 5.1

創建數據庫用戶並授權

mysql -u root -p

mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitpwd';

mysql> show variables like "%engine";
+------------------------+--------+
| Variable_name          | Value  |
+------------------------+--------+
| default_storage_engine | InnoDB |
| storage_engine         | InnoDB |
+------------------------+--------+
2 rows in set (0.01 sec)

#如果不是InnoDB引擎,需執行下面命令
mysql> SET storage_engine=INNODB;

創建數據庫

mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

給用戶授權

mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';

測試是否能夠成功登錄

mysql -ugit -pgitpwd -D gitlabhq_production
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.5.40-log Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \q


七,配置redis

chkconfig redis on

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

#修改監聽端口
sed 's/^port .*/port 0/' /etc/redis.conf.orig |tee /etc/redis.conf

#增加內容
echo 'unixsocket /var/run/redis/redis.sock' |tee -a /etc/redis.conf

echo -e 'unixsocketperm 0770' |tee -a /etc/redis.conf

創建目錄改權限

mkdir /var/run/redis

chown redis:redis /var/run/redis

chmod 755 /var/run/redis

啓動服務

service redis restart

附加git到redis組

usermod -aG redis git


八,安裝gitlab

cd /home/git

#下載源碼
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-4-stable gitlab

修改配置

cd gitLab/

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

sudo -u git -H vim config/gitlab.yml
gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: localhost
    port: 80
    https: false

修改目錄權限

chown -R git log/
chown -R git tmp/
chmod -R u+rwX log/
chmod -R u+rwX tmp/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
chmod -R u+rwX  public/uploads

創建目錄

sudo -u git -H mkdir /home/git/gitlab-satellites
chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

編輯配置文件unicorn.rb

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

#查看系統核心數
nproc
4

#編輯配置
sudo -u git -H vim config/unicorn.rb
worker_processes 4

拷貝配置文件rack_attack.rb

sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

定義全局的用戶和郵箱

sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "[email protected]"
sudo -u git -H git config --global core.autocrlf input

編輯連接redis配置

#拷貝配置
sudo -u git -H cp config/resque.yml.example config/resque.yml

#連接redis配置,默認配置,未修改
sudo -u git -H vim config/resque.yml


九,配置gitlab數據庫文件

sudo -u git cp config/database.yml.mysql config/database.yml

#編輯配置文件
sudo -u git -H vim config/database.yml
production:
  adapter: mysql2
  encoding: utf8
  collation: utf8_general_ci
  reconnect: false
  database: gitlabhq_production
  pool: 10
  username: git
  password: "gitpwd"
  host: localhost
  socket: /var/lib/mysql/mysql.sock

#修改文件權限,只有git用戶可讀
sudo -u git -H chmod o-rwx config/database.yml


十,安裝gem

cd /home/git/gitLab

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



十一,安裝gitlab-shell

官網上給的gitlab-shell版本是2.1.0,後面會有問題(本地到遠程不能連接),網上查找問題是版本問題,需要gitlab-shell的版本是2.0.1

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

#編輯配置
sudo -u git -H vim /home/git/gitlab-shell/config.yml
---
user: git
gitlab_url: https://localhost/
http_settings:
  self_signed_cert: true
repos_path: "/home/git/repositories/"
auth_file: "/home/git/.ssh/authorized_keys"
redis:
  bin: "/usr/bin/redis-cli"
  namespace: resque:gitlab
  socket: "/var/run/redis/redis.sock"
log_level: INFO
audit_usernames: false


十二,初始化數據庫

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

#可以設置管理員密碼(此步驟可省略。。。)
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword


十三,下載服務腳本

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

chkconfig gitlab on

#設置logrotate
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

#檢測應用狀態
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

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

#啓動服務
service gitlab start


十四,配置web服務

#本人使用的nginx
yum -y install nginx

chkconfig nginx on

wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl

添加nginx用戶到git組

usermod -a -G git nginx

chmod g+rx /home/git/

修改配置,修改server_name

vim /etc/nginx/conf.d/gitlab.conf

啓動服務

service nginx start

#訪問登錄
#用戶名:root
#密碼:5iveL!fe

wKiom1TZfRmyryHIAAPrlBltQwM355.jpg


############問題故障解決##########

#===============================

#問題一

#===============================

su - git -c "cd gitlab/;bundle install --deployment --without development test postgres puma aws"

#報錯信息:
	Fetching source index from https://rubygems.org/
	Retrying source fetch due to error (2/3): Bundler::HTTPError Could not fetch specs from https://rubygems.org/
	Retrying source fetch due to error (3/3): Bundler::HTTPError Could not fetch specs from https://rubygems.org/
	Could not find gitlab-grack-2.0.0.pre in any of the sources


#解決辦法:
#移除源
	su - git -c "gem sources --remove https://rubygems.org/"
	https://rubygems.org/ removed from sources
	#添加源
	su - git -c "gem sources -a https://ruby.taobao.org/"
	https://ruby.taobao.org/ added to sources
	#查看源
	su - git -c "gem sources -l"
	*** CURRENT SOURCES ***

	
#繼續執行
bundle install --deployment --without development test postgres puma was
#報錯信息:
	Gem::RemoteFetcher::UnknownHostError: no such name (https://rubygems.org/gems/net-scp-1.1.2.gem)
	An error occurred while installing net-scp (1.1.2), and Bundler cannot continue.
	Make sure that `gem install net-scp -v '1.1.2'` succeeds before bundling.
#解決辦法:
	gem install net-scp -v '1.1.2'

#報錯信息:
	Gem::RemoteFetcher::FetchError: Errno::ETIMEDOUT: Connection timed out - connect(2) for "rubygems.global.ssl.fastly.net" port 443 (https://rubygems.org/gems/httparty-0.13.0.gem)
	An error occurred while installing httparty (0.13.0), and Bundler cannot continue.
	Make sure that `gem install httparty -v '0.13.0'` succeeds before bundling."

#解決辦法:
	gem install httparty -v '0.13.0'

#如果有以下提示,無需理會,繼續運行安裝命令,直到安裝完成爲止。
	Could not fetch specs from https://rubygems.org/

#================================

#問題二

#================================

#報錯信息:
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
	This will create the necessary database tables and seed the database.
	You will lose any previous data stored in the database.
	Do you want to continue (yes/no)? yes

	Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "collation"=>"utf8_general_ci", "reconnect"=>false, "database"=>"gitlabhq_production", "pool"=>10, "username"=>"git", "password"=>"gitpwd"}, {:charset=>"utf8", :collation=>"utf8_general_ci"}
	(If you set the charset manually, make sure you have a matching collation)
	-- enable_extension("plpgsql")
	rake aborted!
	Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
#解決辦法:
vim config/database.yml
	#mysql.sock的位置指定,默認在/tmp目錄下
	socket: /var/lib/mysql/mysql.sock

#============================

#問題三

#============================

#報錯信息:
	Running /home/git/gitlab-shell/bin/check
	Check GitLab API access: /home/git/gitlab-shell/lib/gitlab_net.rb:122:in `read': No such file or directory @ rb_sysopen - /home/git/gitlab-shell/.gitlab_shell_secret (Errno::ENOENT)
		from /home/git/gitlab-shell/lib/gitlab_net.rb:122:in `secret_token'
		from /home/git/gitlab-shell/lib/gitlab_net.rb:79:in `get'
		from /home/git/gitlab-shell/lib/gitlab_net.rb:39:in `check'
		from /home/git/gitlab-shell/bin/check:11:in `<main>''

#之前提到過的,由於gitlab-shell版本問題導致,按照我安裝的版本應該沒什麼問題。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章