Centos6.2 + gitlab安装小结

Centos6.2 + gitlab安装小结

1.Gitlab介绍及安装要求

介绍GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。GitLab 要求服务器端采用 Gitolite 搭建,5.0版本以后对于ssh服务,GitLab不再使用 Gitolite ,采用自己开发的 gitlab-shell 来实现。另外,如果需要对代码进行Review,推荐使用Gerrit,要复杂一些,但是功能非常强大。

安装GitLab的需求:Ubuntu/Debian(官方推荐这2个系统,也可以安装到CentOS系统中,并且在GitHub上有CentOS的GitLab一键安装脚本https://github.com/mattias-ohlsson/gitlab-installer/blob/master/gitlab-install-el6.sh

前提:一定要先关闭iptable与selinux

本文安装的系统为centos 6.2 X86_64位系统,安装在DELL R510机器,使用的nginx+php+mysql已经部署好了的环境。安装前强烈推荐阅读该帮助手册:

https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md

2. 安装:

2.1. install Packages /Dependencies

cd /u1/zdh

rpm -ivh\

http://fr2.rpmfind.net/linux/epel/6/x86_64/epel-release-6-8.noarch.rpm

yum -y install readline-devel  libyaml-devel gdbm-devel  ncurses-develredis openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-develcurl-devel expat-devel gettext-devel  tk-devel  libxml2-devellibffi-devel libxslt-devel libicu-devel httpd httpd-devel gitolite git-allpython-devel python-pip sqlite-devel sendmail vim mysql-devel mysql-serverpatch libyaml* pcre-devel

2.2 install ruby1.9+(此过程网络慢的情况下可能时间长点)

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

curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz

yum -y removeruby  #移除老版本

cd ruby-1.9.3-p392/

./configure

make && make install

gem install bundler --no-ri --no-rdoc

ln -s /usr/local/bin/ruby /usr/bin/ruby

ln -s /usr/local/bin/gem /usr/bin/gem

ln -s /usr/local/bin/bundle /usr/bin/bundle

2.3 create system user

adduser --comment 'GitLab'git

chmod -R 755 /home/git

2.4 install gitlab shell

su - git

cd /home/git

git clone https://github.com/gitlabhq/gitlab-shell.git

cd gitlab-shell

git checkout v1.7.0

cp config.yml.example config.yml

vim config.yml

user: git

gitlab_url: "http://gitlab.linuxblind.com/"

http_settings:

       self_signed_cert: false

repos_path: "/home/git/repositories"

auth_file: "/home/git/.ssh/authorized_keys"

redis:

       bin:/usr/bin/redis-cli

       host:127.0.0.1

       port:6379

       #socket: /tmp/redis.socket

       namespace:resque:gitlab

./bin/install

2.5 install database

mysql -u root -p

mysql> CREATE USER 'gitlab'@'localhost'IDENTIFIED BY 'gitlab';

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, ALTERON `gitlabhq_production`.* TO 'gitlab'@'localhost';

mysql>\q

2.6 install gitlab

#clone the source

su - git

cd /home/git

git clone https://github.com/gitlabhq/gitlabhq.git gitlab

cd /home/git/gitlab

git checkout 5-4-stable

#configure it

cd /home/git/gitlab

cp config/gitlab.yml.example config/gitlab.yml

vim config/gitlab.yml

gitlab:

       host:gitlab.linuxblind.com

       port:80

       https:false

           email_from:gitlab@localhost

support_email: support@localhost

default_projects_limit: 10

       satellites:

       path:/home/git/gitlab-satellites/

   backup:

           path:"tmp/backups

           #keep_time: 604800

       gitlab_shell:

repos_path: /home/git/repositories/

           hooks_path:/home/git/gitlab-shell/hooks/

       upload_pack:true

           receive_pack:true

       git:

           bin_path:/usr/local/bin/git

           max_size: 5242880

           timeout: 10

chown -R git log/

chown -R git tmp/

chmod -R u+rwX  log/

chmod -R u+rwX  tmp/

mkdir /home/git/gitlab-satellites

mkdir tmp/pids/

mkdir tmp/sockets/

chmod -R u+rwX  tmp/pids/

chmod -R u+rwX  tmp/sockets/

mkdir public/uploads

chmod -R u+rwX  public/uploads

cp config/puma.rb.example config/puma.rb

#locate unicorn.rb

#cp /home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/redis-3.0.4/examples/\

unicorn/unicorn.rb /home/git/gitlab/config/

   #vim config/unicorn.rb

git config --global user.name "GitLab"

git config --global user.email "gitlab@localhost"

git config --global core.autocrlf input

2.7 config mysql

su - git

cp config/database.yml.mysql config/database.yml

vim config/database.yml

production:

       adapter:mysql2

       encoding:utf8

       reconnect:false

       database:gitlabhq_production

       pool:5

       username:gitlab

       password:"gitlab"

       host:localhost

       socket:/tmp/mysql.sock

development:

       adapter:mysql2

       encoding:utf8

       reconnect:false

       database:gitlabhq_development

       pool:5

       username:gitlab

       password:"gitlab"

       socket:/tmp/mysql.sock

test: &test

       adapter:mysql2

       encoding:utf8

       reconnect:false

       database:gitlabhq_test

       pool:5

       username:gitlab

       password:"gitlab"

       socket:/tmp/mysql.sock

chmod o-rwx config/database.yml

2.8 install gem

cd /home/git/gitlab

gem install charlock_holmes --version '0.6.9.4'

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

2.9 Initialize database and activateadvanced features

/etc/init.d/redis start

/usr/local/mysql/bin/mysqld--defaults-file=/usr/local/mysql/my.cnf &

bundle exec rake gitlab:setup RAILS_ENV=production

2.10 install init script

cd /home/git/gitlab

cp lib/support/init.d/gitlab /etc/init.d/gitlab

chmod +x /etc/init.d/gitlab

#cat /etc/init.d/gitlab

APP_ROOT="/home/git/gitlab"

APP_USER="git"

DAEMON_OPTS="-C $APP_ROOT/config/puma.rb"

PID_PATH="$APP_ROOT/tmp/pids"

SOCKET_PATH="$APP_ROOT/tmp/sockets"

WEB_SERVER_PID="$PID_PATH/puma.pid"

SIDEKIQ_PID="$PID_PATH/sidekiq.pid"

STOP_SIDEKIQ="RAILS_ENV=production bundle exec rakesidekiq:stop"

START_SIDEKIQ="RAILS_ENV=production bundle exec rakesidekiq:start"

NAME="gitlab"

DESC="GitLabservice"

  2.11 check application status

  #Check if GitLab and its environment are configured correctly:

bundle exec rake gitlab:env:info RAILS_ENV=production

#To make sure you didn't miss anything run a more thorough check with:

bundle exec rake gitlab:check RAILS_ENV=production

#If all items are green, then congratulations on successfully

#if getwronglike“ Running? ... no”Try fixing it with:

bundle exec rake sidekiq:start RAILS_ENV=production

  2.12 start gitlab service

   sudo gitlab start (or: sudo /etc/init.d/gitlab start)

  2.13 install nginx and configure gitlab fornginx

   cd /home/git/gitlab

   cp lib/support/nginx/gitlab /usr/local/nginx/conf/sites-enabled/gitlab.conf

   chown -R nobody.nobody /usr/local/nginx

   #cat nginx.conf

      user  nobody nobody;

worker_processes 4;

error_log logs/error.log;

events {

           worker_connections  1024;

}

http {

       include       mime.types;

       default_type  application/octet-stream;

       sendfile        on;

       tcp_nopush     on;

       tcp_nodelay     off;

keepalive_timeout 65;

       gzip  on;

       gzip_comp_level 1;

       gzip_proxiedany;

gzip_types text/plain text/css application/x-javascripttext/xml application/xml application/xml+rss text/javascript;

include /usr/local/nginx/conf/sites-enabled/*;

}

#cat gitlab.conf

upstream gitlab {

       serverunix:/home/git/gitlab/tmp/sockets/gitlab.socket;

}


server {

       listen80;         # e.g., listen192.168.1.1:80;

       server_name gitlab.linuxblind.com;

       root/home/git/gitlab/public;

access_log /usr/local/nginx/logs/gitlab_access.log;

       error_log   /usr/local/nginx/logs/gitlab_error.log;

       location/ {

       try_files $uri $uri/index.html $uri.html@gitlab;

       }

       location@gitlab {

           proxy_read_timeout300;

           proxy_connect_timeout300;

           proxy_redirect     off;

           proxy_set_header   X-Forwarded-Proto $scheme;

           proxy_set_header   Host              $http_host;

           proxy_set_header   X-Real-IP         $remote_addr;

proxy_pass http://gitlab;

       }

}

/usr/local/nginx/sbin/nginx

3. 访问

   http://gitlab.linuxblind.com/用户名:[email protected] 密码:5iveL!fe

164327757.jpg

你可能感兴趣的:(git,gitlab)