GitLab完整搭建(版本6.3.1)

来源:互联网 发布:使用java实现串口通信 编辑:程序博客网 时间:2024/06/05 06:01

CentOS6.7安装gitlab

    GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。

    它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

前期规划:

1).操作系统Centos 6.7 Minimal

#Distribution      : CentOS 6.7 Minimal

#GitLab version    : 6.3.1

#GitLab-shell      : 1.8.0

#Ruby version      : ruby 2.0.0p353(2013-11-22 revision 43784) [x86_64-linux]

#Gem version       : 2.0.14

#Redis-server      : Redis server version2.4.10 (00000000:0)

#Web Server        : Nginx/1.0.15

#Database          : MariaDB 10.0.21

2).项目地址:https://github.com/gitlabhq/gitlabhq

参考文档:http://doc.gitlab.com/ce/install/installation.html#clone-the-source

          https://github.com/lubia/gitlab-recipes/tree/master/install/centos

3).主机名称及IP地址(测试主机IP地址)

Moxiaokai     192.168.3.251

4).同步主机系统时间

#/usr/sbin/ntpdate -us stdtime.gov.hk ntp.sjtu.edu.cn;hwclock -w;


第一,配置yum源及安装依赖包:

1).安装epel源

#yum -y install epel-release -y


2.安装puias源

#vi /etc/yum.repos.d/puias-computational.repo[PUIAS_6_computational]name=PUIAScomputational Base $releasever - $basearchmirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlistgpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias#cd /etc/pki/rpm-gpg/#wget -q http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias#rpm --import RPM-GPG-KEY-puias#yum repolist


wKioL1Z9Gb_zUsAVAAA36XEqgOM371.png

第二,安装依赖包:

1).基础依赖包

#yum -y install gdbm-devel glibc-devel tcl-devel openssl-devel curl-develexpat-devel db4-devel byacc libyaml libyaml-devel libffi libffi-devel libxml2libxml2-devel libxslt libxslt-devel libicu libicu-devel sudo wget patchlogwatch logrotate perl-Time-HiRes cmake libcom_err-devel.i686libcom_err-devel.x86_64 nodejs python-docutils


2).升级系统所有软件包到最新

#yum -y update


3).安装postfix邮件服务器

#yum install postfix


第三,安装git:

1).移除低版本git

#yum remove git -y


备注:默认centos的git版本是1.7.10,必须删除后,再下载源码进行安装

2).安装git的依赖包

#yum -y install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-developenssl-devel


3).编译安装git

#mkdir /tmp/git && cd /tmp/git #curl  --progress https://www.kernel.org/pub/software/scm/git/git-2.5.1.tar.gz | tar xz#cd  git-2.5.1/ && ./configure --prefix=/usr/local/git  && make && make install


4).配置换变量

#echo "export PATH=/usr/local/git/bin:\$PATH" >> /etc/profile#source /etc/profile


5).验证程序

#which git#git --version


wKioL1Z9GnCBr2mNAAAZ1BT6fIc072.png

第四,安装ruby

1).移除低版本ruby

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

#yum remove ruby



#如果是源码安装的

cd(your-ruby-source-path) && make uninstall


2).编译安装ruby

#mkdir /tmp/ruby && cd /tmp/ruby#curl --progress https://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz |tar xz#cd ruby-2.0.0-p353 && ./configure --prefix=/usr/local/ruby--disable-install-rdoc && make && make install


3).配置换变量

#echo "export PATH=/usr/local/ruby/bin:\$PATH" >> /etc/profile#source /etc/profile


4).验证程序

#which ruby#ruby --version


wKiom1Z9GqvQX1atAAAj2OVhVKk749.png

5).安装bundler

删除官方源使用淘宝的镜像

#gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/ #gem sources -l


wKiom1Z9GwDwbQQ-AAAYF-uFIaw471.png

#gem install bundler --no-rdoc


wKioL1Z9GyXTI5WEAAAnlbLDWBI672.png

# gem install charlock_holmes


     wKiom1Z9GzWSdxVfAAAzd3T3Faw204.png

第五,创建系统用户(git)

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



第六,配置MariaDB

创建数据库用户并授权

#mysql -u root -p mysql> create database gitlabhq_production character set utf8;mysql> grant all privileges on gitlabhq_production.*to git@localhost identified by '123456';mysql> flushprivileges;


7,配置redis

1).安装redis

#yum install redis


验证redis版本:

    wKiom1Z9HQDQ3AxAAAAa0AEaMr8371.png

2).修改redis.conf配置文件

    (1).备份配置文件

     

# cp /etc/redis.conf /etc/redis.conf.bak


  (2).修改/tmp/redis.sock为/var/run/redis/redis.sock

      wKiom1Z9HUuSIZV5AAAaTpNd0E4599.png

  (3).修改/var/var/run/redis/redis.sock的权限为755

  # chmod  -R 755 /var/run/redis/


3).配置redis自启动

#chkconfig --level 35 redis on


4).启动redis并验证

#/etc/init.d/redis restart#/etc/init.d/redis status


wKioL1Z9HYThqUjWAAAg_k_1KIo687.png

5).附加git到redis组

   

#usermod -aG redis git


第八,安装gitlab

1).取gitlab源代码:

# su - git$ git clonehttps://github.com/gitlabhq/gitlabhq.git gitlab


检查远程分支并切换到对应分支

$ cd gitlab$ git branch -a ##查看远程分支$ git checkout 6-3-stable


  wKiom1Z9HbLgT8nRAAAcGKKz_JE865.png

$ cat VERSION    6.3.1


2).修改配置gitlab.yml

 (1).修改18行(版本不同行数不同)的host为IP地址或者域名

$ cp config/gitlab.yml.example config/gitlab.yml$ vi config/gitlab.yml


wKioL1Z9HhzSW-hTAAAYXRjdkjI983.png

    (2).修正184行(版本不同行数不同)的bin_path为正确的git命令位置

      wKiom1Z9HlORbG_TAAA0a2fUH28008.png

    (3).检查创建目录及权限

$ mkdir -p /home/git/gitlab-satellites$ cd /home/git/gitlab$ mkdir -p tmp/pids$ mkdir -p tmp/sockets$ mkdir -p public/uploads


3).配置unicorn.rb文件

(1).修改配置

$ cp config/unicorn.rb.example config/unicorn.rb


#查看系统核心数

#nproc2


$viconfig/unicorn.rb

wKioL1Z9HqbSI9tKAABgjNdgc0c025.png

注意config/unicorn.rb的内容:

working_directory"/home/git/gitlab"

listen"/home/git/gitlab/tmp/sockets/gitlab.socket"

pid"/home/git/gitlab/tmp/pids/unicorn.pid"

4).配置resque.yml文件,(redis文件)

$ cp config/resque.yml.example config/resque.yml


#连接redis配置,默认配置,最终修改结果如下

$ cat config/resque.yml


wKiom1Z9HwjjvlA-AAAcJ864zVU748.png

5).配置database.yml文件(MariaDB),只配置production环境

$ cp config/database.yml.mysql config/database.yml$ vi config/database.yml


wKiom1Z9H0DQnXMaAAAmwEXbDYE623.png

第九,安装gem

1).修改gemfile源为淘宝源

# su - git$ cd /home/git/gitlab$ vi Gemfile


wKioL1Z9H3eDR7vGAAAq7fA8p_g974.png

修改文件Gemfile 的143行中gem"modernizr","2.6.2"为:gem"modernizr-rails","2.7.1"

wKioL1Z9H7rTt9h_AAA0IbC7DLE145.png

修改文件Gemfile.lock 的279行modernizr(2.6.2)为modernizr-rails (2.7.1)

wKioL1Z9H92zDaflAAAtuISGRf0781.png

修改文件Gemfile.lock 的605行modernizr(= 2.6.2)为modernizr-rails (= 2.7.1)

wKiom1Z9H9eQVQndAAAizIJcqd0362.png

2).执行gem安装

$ bundle install --deployment --without development test postgres aws


wKioL1Z9IAah5WIUAABexezhCJE796.png

第十,安装gitlab-shell

1).安装gitlab-shell

$ su - git$ git clone https://github.com/gitlabhq/gitlab-shell.git gitlab-shell$ cd gitlab-shell$ git checkout v1.8.0


wKiom1Z9IEbjoLajAAA81zZj4Ys273.png

2).配置config.yml

$ cp config.yml.example config.yml$ vi config.yml


在正式环境中将gitlan_url换成gitbal访问域名

wKiom1Z9IHGytC4tAABwbXRNkos186.png

3).执行安装命令,创建对应目录和文件

$ ./bin/install


第十一,初始化数据库并激活高级功能

$ cd /home/git/gitlab$ bundle exec rake gitlab:setup RAILS_ENV=production

这步完成后,会生一个默认的管理员账号:

root

5iveL!fe

wKioL1Z9IU-TUX4FAAAjz-b9Hg0478.png

wKiom1Z9IUXx3NeQAAAnGdY-xpo182.png

十二,下载gitlab启动服务脚本

# wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn


wKiom1Z9IXbjU9njAAA-jLM-gPE110.png

# chmod +x /etc/init.d/gitlab# chkconfig --add gitlab# chkconfig --level 35 gitlab on # 设置logrotate(可选操作)# cp /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab


十三,检测应用状态

1).检查基础环境

#su - git$ cd gitlab$ bundle exec rake gitlab:env:info RAILS_ENV=production


wKioL1Z9IcSgankJAABL0MJWMjc544.png

2).检查编译环境

$ bundle exec rake assets:precompile RAILS_ENV=production


3).查看应用详细信息

 $bundle exec rake gitlab:check RAILS_ENV=production


4).启动服务,并验证

#service gitlab start


wKiom1Z9Ig3Sb8_vAAAfW5zpDqM164.png

如果报错:bash: bin/web: No such file or directory和bash:bin/background_jobs: No such file or directory

解决办法为:

# vi /etc/init.d/gitlab

修改/etc/init.d/gitlab中的 bin/web 路径为 script/web

修改/etc/init.d/gitlab中的 bin/background_jobs 路径为 script/background_jobs

wKiom1Z9IjaiO6X8AABbXbgLimg425.png

十四,配置web服务

(1).编辑nginx.conf文件

    修改/usr/local/nginx/conf/nginx.conf (编译安装的nginx)

    1.在include        mine.types;这一行上添加:

    

    passenger_root /usr/local/ruby/lib/ruby/gems/2.0.0/gems/passenger-5.0.23;

    passenger_ruby /usr/local/ruby/bin/ruby;

    wKioL1Z-VEKRDDHCAAAyZTIFlHk825.png

    2.修改##访问方式为:http://ip/目录名为:

    

              server {

                    listen 80;

                    server_name localhost;


              location / {

                   root   /home/git/gitlab/public/;

                   index  index.html index.htm;

                   passenger_enabled on;

        }

                     }

    wKioL1Z-VFLQFsEZAAArVfgCc4o549.png


(2).访问http://192.168.3.251/登录

    用户名:root

    密码:5iveL!fe

wKiom1Z9I_XS64w0AACzyTvFfFg387.png

 


本文出自 “小陌成长之路” 博客,请务必保留此出处http://309173854.blog.51cto.com/7370240/1728390

0 0
原创粉丝点击