标签:git
GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用。
安装步骤
n升级系统并及关闭selinux和iptables
n安装Ruby
n创建项目运行用户(创建git账号,方便权限管理)
nGitLab Shell
n数据库(可以支持mysql和PostgreSQL,这里使用mysql)
nGitLab(版本:6.3.1)
nWeb服务器(可支持nginx和apache,这里使用nginx)
# vi /etc/selinux/config # 设置SELINUX=disabled
# setup #将Firewall 选项取消
# 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 -qa gpg*
安装epel-release-6-8.noarch包
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
创建/etc/yum.repos.d/PUIAS_6_computational.repo,并添加如下内容:
[PUIAS_6_computational]
name=PUIAS computational Base $releasever - $basearch
mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias
下载并安装GPG key
# 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-pui
检测源
# yum repolist
# su -
# yum -y groupinstall ‘Development Tools‘
# yum -y install vim-enhanced readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git
# chkconfig redis on
# service redis start
# mkdir /tmp/ruby && cd /tmp/ruby
# curl --progress ftp://ftp.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/
# make && make install
安装bundle
# gem install bundler --no-ri --no-rdoc
# adduser --system --shell /bin/bash --comment ‘GitLab‘ --create-home --home-dir /home/git/ git
克隆gitlab shell
# su - git
$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell
$ git checkout v1.8.0 #切换版本
$ cp config.yml.example config.yml
$ vi config.yml
gitlab_url修改成gitlab的访问域名。形如:http://test.gitlab.com/
如果gitlab是使用https访问,则需将http替换成https,配置文件中的self_signed_cert要修改成true,否则会出错。
安装
$ ./bin/install
$ su -
$ yum install -y mysql-server mysql-devel
$ chkconfig mysqld on
$ service mysqld start
设置mysql root账号的密码
/usr/bin/mysql_secure_installation
创建新用户和数据库给gitlab使用
mysql> CREATE USER ‘gitlab‘@‘localhost‘ IDENTIFIED BY ‘gitlab账号的密码‘;
# 创建gitlaba使用的数据库
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# 给予gitlab用户权限
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO ‘gitlab‘@‘localhost‘;
$ su - git
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
$ cd /home/git/gitlab
$ git checkout 6-3-stable
# 复制配置文件
$ cp config/gitlab.yml.example config/gitlab.yml
# 修改配置文件中的访问域名
(your_domain_name为项目的访问域名)
$ sed -i ‘s|localhost|your_domain_name|g‘ config/gitlab.yml
# 设定log和tmp目录所有者和权限
$ chown -R git log/
$ chown -R git tmp/
$ chmod -R u+rwX log/
$ chmod -R u+rwX tmp/
# 创建gitlab-satellites目录
$ mkdir /home/git/gitlab-satellites
# 创建tmp/pids/和tmp/sockets/目录,确保gitlab有相应的权限
$ mkdir tmp/pids/
$ mkdir tmp/sockets/
$ chmod -R u+rwX tmp/pids/
$ chmod -R u+rwX tmp/sockets/
# 创建public/uploads目录
$ mkdir public/uploads
$ chmod -R u+rwX public/uploads
# 复制unicorn配置
$ cp config/unicorn.rb.example config/unicorn.rb
# 编辑unicorn配置
(笔者这里采用默认配置)
$ vim config/unicorn.rb
# 配置git的用户和邮件
$ git config --global user.name "GitLab"
$ git config --global user.email "gitlab@your_domain_name"
$ git config --global core.autocrlf input
$ cp config/database.yml.mysql config/database.yml
编辑config/database.yml,设置其中连接数据库的账号密码
#
# PRODUCTION
#
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 10
username: gitlab
password: "gitlab"
# host: localhost
# socket: /tmp/mysql.sock
修改其中username和password就可以了
确保该文件只有git账号有权限读取
$ chmod o-rwx config/database.yml
由于国外gem源访问非常慢,建议更换国内gem源。
# vi Gemfile
编辑Gemfile文件,将gem源更换为ruby.taobao.org
#source"https://rubygems.org"
sourcehttp://ruby.taobao.org
修改Gemfile文件,将gem "modernizr", "2.6.2"修改为gem"modernizr-rails", "2.7.1"。
修改Gemfile.lock文件,将modernizr (2.6.2)修改为modernizr-rails (2.7.1)。
否则无法正确安装。
# gem install charlock_holmes --version ‘0.6.9.4‘
$ cd /home/git/gitlab/
$ bundle install --deployment --without development test postgres puma aws
$ cd /home/git/gitlab
$ bundle exec rake gitlab:setup RAILS_ENV=production
$ bundle exec rake assets:precompile RAILS_ENV=production
这步完成后,会生一个默认的管理员账号:
admin@local.host
5iveL!fe
$ su -
$ wget -O /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn
$ chmod +x /etc/init.d/gitlab
$ chkconfig --add gitlab
开机时启动
$ chkconfig gitlab on
$ su - git
$ cd gitlab/
$ bundle exec rake gitlab:env:info RAILS_ENV=production
$ exit
可以查看到系统、Ruby、GitLab和GitLab Shell的版本和其他信息。
启动GitLab实例
$ service gitlab start
查看应用更加详细的信息
$ su - git
$ cd gitlab/
$ bundle exec rake gitlab:check RAILS_ENV=production
$ su -
$ yum -y install nginx
$ chkconfig nginx on
$ mkdir /etc/nginx/sites-available
$ mkdir /etc/nginx/sites-enabled
$ wget -O /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/nginx/gitlab-ssl
$ ln -sf /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
编辑/etc/nginx/nginx.conf,将 include /etc/nginx/conf.d/*.conf; 替换成include /etc/nginx/sites-enabled/*;,就是修改额外加载的配置文件目录。
编辑/etc/nginx/sites-available/gitlab,将配置中server_name替换成实际访问的域名。
将nginx加入git用户组
$ usermod -a -G git nginx
$ chmod g+rx /home/git/
添加ssl证书或者自己生成一个
$ cd /etc/nginx
$ openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
启动nginx
$ service nginx start
登录Gitlab 如下图所示:详情请查看官网:https://www.gitlab.com/downloads/
启动gitlab
# /opt/gitlab/bin/gitlab-ctl start
ok: run: nginx: (pid 2505) 0s
ok: run: postgresql: (pid 2509) 1s
ok: run: redis: (pid 2518) 0s
ok: run: sidekiq: (pid 2523) 1s
ok: run: unicorn: (pid 2528) 0s
参考文档
http://www.01happy.com/centos-6-5-install-gitlab/
http://www.it165.net/os/html/201405/8123.html
标签:git
原文地址:http://cqfish.blog.51cto.com/622299/1412050