天天看點

CentOS6.4 安裝gitlab

一、環境

    安裝過程參考的是http://charlie928.blog.51cto.com/3741218/1613257

    一些故障處理參考文章http://4gamers.cn/blog/2014/07/15/setup-gitlab-on-aliyun-ubuntu/

    gitlab的安裝說明https://github.com/lubia/gitlab-recipes/tree/master/install/centos

    系統:CentOS6.4最小化安裝

    IP:192.168.3.45

二、增加yum源

    增加epel源

[root@gitlab ~]#  rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm     Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm     warning: /var/tmp/rpm-tmp.YSifux: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY     Preparing...                ########################################### [100%]        1:epel-release           ########################################### [100%]     [root@gitlab ~]# sed -i 's@#b@b@g' /etc/yum.repos.d/epel.repo      [root@gitlab ~]# sed  -i 's@mirrorlist@#mirrorlist@g' /etc/yum.repos.d/epel.repo      

    安裝淘寶源

[root@gitlab ~]#  wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo      

    需要配置本地hosts解析,後面會用到

192.168.3.45 www.gitlab.com      

三、安裝更新包

[root@gitlab ~]# yum -y update     [root@gitlab ~]# yum -y groupinstall 'Development Tools'     [root@gitlab ~]# 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  cmake libcom_err-devel.i686 libcom_err-devel.x86_64  perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker nodejs      

四、安裝git

    删除系統預設的git,使用源碼安裝git

[root@gitlab ~]# git --version     git version 1.7.1     [root@gitlab ~]# yum remove git -y     #下載下傳源碼安裝包     [root@gitlab ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.gz     [root@gitlab ~]# tar xf git-2.1.3.tar.gz      [root@gitlab ~]# cd git-2.1.3     [root@gitlab git-2.1.3]# ./configure      [root@gitlab git-2.1.3]# make && make prefix=/usr/local install     [root@gitlab git-2.1.3]# ln -s /usr/local/bin/git /usr/bin/     [root@gitlab git-2.1.3]# git --version     git version 2.1.3      

五、安裝ruby環境

    删除系統自帶的ruby環境,確定ruby是2.0以上的版本

[root@gitlab ~]# yum remove ruby -y     #下載下傳ruby安裝包,最少2.0以上     [root@gitlab ~]# wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.2.tar.gz     [root@gitlab ~]# tar xf ruby-2.1.2.tar.gz      [root@gitlab ~]# cd ruby-2.1.2     [root@gitlab ruby-2.1.2]#./configure --prefix=/usr/local/      [root@gitlab ruby-2.1.2]# make && make install      

    安裝bundler

[root@gitlab ruby-2.1.2]# gem install bundler --no-doc     ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:               Unable to download data from https://rubygems.org/ - Errno::ECONNRESET: Connection reset by peer - SSL_connect (     #解決如下     [root@gitlab ruby-2.1.2]# gem sources --remove https://rubygems.org/     https://rubygems.org/ removed from sources     [root@gitlab ruby-2.1.2]# gem sources -a https://ruby.taobao.org/     https://ruby.taobao.org/ added to sources     [root@gitlab ruby-2.1.2]# gem sources -l     *** CURRENT SOURCES ***     https://ruby.taobao.org/     #重新安裝bundler     [root@gitlab ruby-2.1.2]# gem install bundler --no-doc     Fetching: bundler-1.9.9.gem (100%)     Successfully installed bundler-1.9.9     1 gem installed      

六、建立git使用者

[root@gitlab ~]# adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git      

七、安裝mysql,這裡選擇源碼安裝mysql-5.5-37,使用安裝腳本進行安裝

    腳本内容如下

#!/bin/bash     DATADIR='/data/mysql/data'     VERSION='mysql-5.5.37'     export LANG=zh_CN.UTF-8     #Source function library.     . /etc/init.d/functions     #camke install mysql5.5.X     install_mysql(){             read -p "please input a password for root: " PASSWD             if [ ! -d $DATADIR ];then                     mkdir -p $DATADIR             fi             yum install cmake make gcc-c++ bison-devel ncurses-devel -y             id mysql &>/dev/null             if [ $? -ne 0 ];then                     useradd mysql -s /sbin/nologin -M             fi             #useradd mysql -s /sbin/nologin -M             #change datadir owner to mysql             chown -R mysql.mysql $DATADIR             cd             #wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.38.tar.gz             tar xf $VERSION.tar.gz             cd $VERSION             cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/$VERSION \             -DMYSQL_DATADIR=$DATADIR \             -DMYSQL_UNIX_ADDR=$DATADIR/mysql.sock \             -DDEFAULT_CHARSET=utf8 \             -DDEFAULT_COLLATION=utf8_general_ci \             -DENABLED_LOCAL_INFILE=ON \             -DWITH_INNOBASE_STORAGE_ENGINE=1 \             -DWITH_FEDERATED_STORAGE_ENGINE=1 \             -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \             -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \             -DWITHOUT_PARTITION_STORAGE_ENGINE=1             make && make install             if [ $? -ne 0 ];then                     action "install mysql is failed"  /bin/false                     exit $?             fi             sleep 2             #link             ln -s /usr/local/$VERSION/ /usr/local/mysql             ln -s /usr/local/mysql/bin/* /usr/bin/             #copy config and start file             /bin/cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf             cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld             chmod 700 /etc/init.d/mysqld             #init mysql             /usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql --datadir=$DATADIR --user=mysql             if [ $? -ne 0 ];then                     action "install mysql is failed"  /bin/false                     exit $?             fi             #check mysql             /etc/init.d/mysqld start             if [ $? -ne 0 ];then                     action "mysql start is failed"  /bin/false                     exit $?             fi             chkconfig --add mysqld             chkconfig mysqld on             /usr/local/mysql/bin/mysql -e "update mysql.user set password=password('$PASSWD') where host='localhost' and user='root';"             /usr/local/mysql/bin/mysql -e "update mysql.user set password=password('$PASSWD') where host='127.0.0.1' and user='root';"             /usr/local/mysql/bin/mysql -e "delete from mysql.user where password='';"             /usr/local/mysql/bin/mysql -e "flush privileges;"             #/usr/local/mysql/bin/mysql -e "select version();" >/dev/null 2>&1             if [ $? -eq 0 ];then                     echo "+---------------------------+"                     echo "+------mysql安裝完成--------+"                     echo "+---------------------------+"             fi             #/etc/init.d/mysqld stop     }     install_mysql      

    檢視mysql安裝結果

[root@gitlab ~]# mysql --version     mysql  Ver 14.14 Distrib 5.5.37, for Linux (x86_64) using  EditLine wrapper      

    建立資料庫并授權

[root@gitlab ~]# mysql -u root -p -h 127.0.0.1     Enter password:         #這裡的密碼是我的安裝腳本中提供的密碼     Welcome to the MySQL monitor.  Commands end with ; or \g.     Your MySQL connection id is 6     Server version: 5.5.37 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> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;     Query OK, 1 row affected (0.00 sec)     mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost' IDENTIFIED BY 'gitpasswd';     Query OK, 0 rows affected (0.00 sec)     mysql> flush privileges;     Query OK, 0 rows affected (0.01 sec)     mysql> select user,host,password from mysql.user;     +------+-----------+-------------------------------------------+     | user | host      | password                                  |     +------+-----------+-------------------------------------------+     | root | localhost | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB |     | root | 127.0.0.1 | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB |     | git  | localhost | *6EA0EDE421A05E610ADBFC5D47B93B6E06C6216F |     +------+-----------+-------------------------------------------+     3 rows in set (0.00 sec)      

    測試建立的使用者能否登陸mysql

[root@gitlab ~]# mysql -u git -p -h localhost     Enter password:         #這裡的密碼是上文中給定的gitpasswd     Welcome to the MySQL monitor.  Commands end with ; or \g.     Your MySQL connection id is 8     Server version: 5.5.37 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> show databases;     +---------------------+     | Database            |     +---------------------+     | information_schema  |     | gitlabhq_production |     | test                |     +---------------------+     3 rows in set (0.00 sec)      

八、配置redis

[root@gitlab ~]# chkconfig redis on     [root@gitlab ~]# /etc/init.d/redis start     Starting redis-server:                                     [  OK  ]     [root@gitlab ~]# netstat -anpt |grep redis     tcp        0      0 127.0.0.1:6379              0.0.0.0:*                   LISTEN      8755/redis-server      

九、安裝gitlab

[root@gitlab ~]# cd /home/git/     [root@gitlab git]# sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-4-stable gitlab     Cloning into 'gitlab'...     remote: Counting objects: 127971, done.     remote: Compressing objects: 100% (32073/32073), done.     remote: Total 127971 (delta 97845), reused 123442 (delta 94050)     Receiving objects: 100% (127971/127971), 81.35 MiB | 1.63 MiB/s, done.     Resolving deltas: 100% (97845/97845), done.     Checking connectivity... done.     #修改配置檔案     [root@gitlab git]# cd gitlab/     [root@gitlab gitlab]# sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml     #下面這條指令可以不用操作,保持預設即可     [root@gitlab gitlab]# sudo -u git -H vim config/gitlab.yml     gitlab:         ## Web server settings (note: host is the FQDN, do not include http://)         host:  www.gitlab.com  #這裡設定的域名是為後面的postfix使用的,在後文中的gitlab.conf站點配置檔案中也是使用的這個域名,普通使用者通路gitlab使用這個域名         port: 80         https: false     #修改相應的目錄權限     [root@gitlab gitlab]# chown -R git log/     [root@gitlab gitlab]# chown -R git tmp/     [root@gitlab gitlab]# chmod -R u+rwX log/     [root@gitlab gitlab]# chmod -R u+rwX tmp/     [root@gitlab gitlab]# chmod -R u+rwX tmp/pids/     [root@gitlab gitlab]# chmod -R u+rwX tmp/sockets/     [root@gitlab gitlab]# chmod -R u+rwX  public/uploads     #建立目錄     [root@gitlab gitlab]# sudo -u git -H mkdir /home/git/gitlab-satellites     [root@gitlab gitlab]# chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites     編輯配置檔案unicorn.rb     [root@gitlab gitlab]# sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb     [root@gitlab gitlab]# nproc     1     [root@gitlab gitlab]# sudo -u git -H vim config/unicorn.rb     worker_processes 1     #複制配置檔案rack_attack.rb     [root@gitlab gitlab]# sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb     #定義全局的使用者和郵箱     [root@gitlab gitlab]# sudo -u git -H git config --global user.name "GitLab"     [root@gitlab gitlab]# sudo -u git -H git config --global user.email "[email protected]"     [root@gitlab gitlab]# sudo -u git -H git config --global core.autocrlf input     #編輯連接配接redis的配置     [root@gitlab gitlab]# sudo -u git -H cp config/resque.yml.example config/resque.yml     [root@gitlab gitlab]# sudo -u git -H vim config/resque.yml     development: redis://localhost:6379     test: redis://localhost:6379     production: unix:/var/run/redis/redis.sock      

十、編輯gitlab資料庫檔案

[root@gitlab gitlab]# sudo -u git cp config/database.yml.mysql config/database.yml     [root@gitlab gitlab]# 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: "gitpasswd"     #修改資料庫檔案權限     [root@gitlab gitlab]# sudo -u git -H chmod o-rwx config/database.yml      

十一、安裝gem

#添加淘寶的ruby源     [root@gitlab gitlab]# sudo -u git vim Gemfile     source "http://ruby.taobao.org"  #将第一行修改成taobao的源     [root@gitlab gitlab]# cd /home/git/gitlab     [root@gitlab gitlab]# ln -s /usr/local/bin/bundle /usr/bin/     [root@gitlab gitlab]# sudo -u git -H bundle install --deployment --without development test postgres aws      

十二、安裝gitlab-shell

[root@gitlab gitlab]# ln -s /usr/local/bin/ruby /usr/bin/ruby     [root@gitlab gitlab]# sudo -u git -H bundle exec rake gitlab:shell:install[v2.0.1] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production     git clone 'https://gitlab.com/gitlab-org/gitlab-shell.git' '/home/git/gitlab-shell/'     Cloning into '/home/git/gitlab-shell'...     remote: Counting objects: 2118, done.     remote: Compressing objects: 100% (1639/1639), done.     remote: Total 2118 (delta 1301), reused 710 (delta 400)     Receiving objects: 100% (2118/2118), 306.39 KiB | 177.00 KiB/s, done.     Resolving deltas: 100% (1301/1301), done.     Checking connectivity... done.     git reset --hard $(git describe v2.0.1 || git describe origin/v2.0.1) || git fetch origin && git reset --hard $(git describe v2.0.1 || git describe origin/v2.0.1)     HEAD is now at a3b5445 Fix bug when changes to post-receive worker was not dumped properly     HEAD is now at a3b5445 Fix bug when changes to post-receive worker was not dumped properly     bin/install     mkdir -p /home/git/repositories/: OK     mkdir -p /home/git/.ssh: OK     chmod 700 /home/git/.ssh: OK     touch /home/git/.ssh/authorized_keys: OK     chmod 600 /home/git/.ssh/authorized_keys: OK     chmod -R ug+rwX,o-rwx /home/git/repositories/: OK     find /home/git/repositories/ -type d -exec chmod g+s {} ;: OK     #gitlab-shell配置檔案内容     [root@gitlab gitlab]# sudo -u git -H vim /home/git/gitlab-shell/config.yml     ---     user: git     gitlab_url:  https://localhost/   #使用https      http_settings:       self_signed_cert: true            #修改成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      

十三、初始化資料庫

[root@gitlab gitlab]# 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            #輸入yes      

十四、下載下傳服務腳本

[root@gitlab gitlab]# wget -O /etc/init.d/gitlab  https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn     #配置gitlab的啟動級别     [root@gitlab gitlab]# chmod +x /etc/init.d/gitlab      [root@gitlab gitlab]# chkconfig --add gitlab     [root@gitlab gitlab]# chkconfig gitlab on      #配置logrotate     [root@gitlab gitlab]# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab     #檢測gitlab的應用支援狀态,并配置     [root@gitlab gitlab]# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production     System information     System:		     Current User:	git     Using RVM:	no     Ruby Version:	2.1.2p95     Gem Version:	2.2.2     Bundler Version:1.9.7     Rake Version:	10.3.2     Sidekiq Version:2.17.0     GitLab information     Version:	7.4.5     Revision:	19d572e     Directory:	/home/git/gitlab     DB Adapter:	mysql2     URL:		http://localhost     HTTP Clone URL:	http://localhost/some-project.git     SSH Clone URL:	git@localhost:some-project.git     Using LDAP:	no     Using Omniauth:	no     GitLab Shell     Version:	2.0.1     Repositories:	/home/git/repositories/     Hooks:		/home/git/gitlab-shell/hooks/     Git:		/usr/bin/git     [root@gitlab gitlab]# sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production     #啟動gitlab服務     [root@gitlab gitlab]# service gitlab start     Starting unicorn:                                          [  OK  ]     Starting sidekiq:                                          [  OK  ]      

十五、安裝nginx服務,并下載下傳gitlab的站點配置檔案

    這裡的nginx使用yum進行安裝

[root@gitlab gitlab]# yum install -y nginx     [root@gitlab gitlab]# chkconfig nginx on     [root@gitlab gitlab]# wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl      

    将nginx使用者添加到git組

[root@gitlab gitlab]# usermod -a -G git nginx     [root@gitlab gitlab]# chmod g+rx /home/git/     [root@gitlab gitlab]# vim /etc/nginx/conf.d/gitlab.conf     #編輯檔案/etc/nginx/conf.d/gitlab.conf,修改其中的serve_rname     server_name gitlab.weyee.com      

    配置SSL證書    

[root@gitlab gitlab]# mkdir -p /etc/nginx/ssl     [root@gitlab gitlab]# cd /etc/nginx/ssl/     [root@gitlab gitlab]# openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key      

    啟動nginx服務

[root@gitlab gitlab]# service nginx start      

    十六、Gitlab配置SMTP郵件

cd /home/git/gitlab     [root@git gitlab]#sudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_setting.rb     #修改如下     [root@git gitlab]#sudo -u git -H vim config/initializers/smtp_settings.rb     if Rails.env.production?       Rails.application.config.action_mailer.delivery_method = :smtp       ActionMailer::Base.delivery_method = :smtp        #使用smtp方法       ActionMailer::Base.smtp_settings = {         address: "smtp.163.com",         port: 25,         user_name: "xxx",            #使用者名         password: "xxxx",            #密碼         domain: "163.com",         authentication: :login,         enable_starttls_auto: true,         #openssl_verify_mode: 'peer' # See ActionMailer documentation for other possible options       }     end     #編輯檔案     [root@git gitlab]#sudo -u git -H vim config/environments/production.rb     config.action_mailer.delivery_method = :smtp            #将方法修改成smtp方式      

    在第一次通路是報錯,500類型的錯誤,通過檢視日志檔案/home/git/gitlab/log/production.log知道是redis.sock的問題,解決如下

[root@gitlab gitlab]# cp /etc/redis.conf /etc/redis.conf.orig     [root@gitlab gitlab]# sed 's/^port .*/port 0/' /etc/redis.conf.orig |tee /etc/redis.conf     #添加redis.sock檔案資訊     [root@gitlab gitlab]# echo 'unixsocket /var/run/redis/redis.sock' |tee -a /etc/redis.conf     [root@gitlab gitlab]# echo -e 'unixsocketperm 0770' |tee -a /etc/redis.conf     #建立檔案并賦予權限     [root@gitlab gitlab]# mkdir  -p /var/run/redis     [root@gitlab gitlab]# chown redis:redis /var/run/redis     [root@gitlab gitlab]# chmod 755 /var/run/redis     [root@gitlab gitlab]# service redis restart     #将redis使用者添加到git組     [root@gitlab gitlab]# usermod -aG redis git      

    到此,重新開機redis後,還是報錯提示

Errno::EACCES (Permission denied - connect(2) for /var/run/redis/redis.sock):

    我這裡是直接使用如下指令解決的

[root@gitlab gitlab]# chmod -R 777 /var/run/redis      

驗證結果,通路位址如下:https://192.168.3.45

使用者名和密碼如下

login.........root

password......5iveL!fe

login以後的界面如下

CentOS6.4 安裝gitlab

    添加使用者www,按圖操作即可

CentOS6.4 安裝gitlab

在使用者郵箱[email protected]查收郵件,點選Click here to set your password進行密碼設定

CentOS6.4 安裝gitlab
CentOS6.4 安裝gitlab

安裝完成後gitlab運作異常使用如下指令檢測,并解決

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

密碼設定完成後使用https://www.gitlab.com/登入即可

gitlab的使用可參考http://dl528888.blog.51cto.com/2382721/1305656

http://dl528888.blog.51cto.com/2382721/1292316

繼續閱讀